> ## Documentation Index
> Fetch the complete documentation index at: https://docs.markpdf.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Referencia

> MarkpdfService, providers and @markpdf/angular types.

# Referencia

## Provider configuration

<Tabs>
  <Tab title="provideMarkpdf (standalone)">
    ```ts theme={null}
    import { provideMarkpdf } from "@markpdf/angular";

    provideMarkpdf({
      baseUrl: string,              // ruta o URL de TU backend, no de la API directamente
      convertPath?: string,         // default "/convert"
      streamPath?: string,          // default "/convert/stream"
      indexPath?: string,           // default "/pdf/index"
      jobsPath?: string,            // default "/jobs"
      withCredentials?: boolean,    // default false
    });
    ```
  </Tab>

  <Tab title="MarkpdfModule.forRoot (NgModule)">
    ```ts theme={null}
    import { MarkpdfModule } from "@markpdf/angular";

    @NgModule({
      imports: [MarkpdfModule.forRoot({ baseUrl: "/api/markpdf" })],
    })
    export class AppModule {}
    ```
  </Tab>
</Tabs>

<Note>
  `@markpdf/angular` **does not** accept a `apiKey` option. It is designed to talk to your own backend, which is the one who knows the key. See [Framework Guide](/docs/sdks/angular/framework-guide).
</Note>

## `MarkpdfService`

Inyectable en cualquier componente, directiva o servicio:

```ts theme={null}
import { inject } from "@angular/core";
import { MarkpdfService } from "@markpdf/angular";

const markpdf = inject(MarkpdfService);
```

### `convertFile`

```ts theme={null}
convertFile(
  file: File | Blob,
  options?: ConvertOptions,
  http?: { reportProgress?: boolean }
): Observable<string | ConversionResult | UploadEvent>
```

Upload the file to your backend (`baseUrl + convertPath`). Returns:

* `Observable<string>` by default.
* `Observable<ConversionResult>` if `options.responseFormat === "json"`.
* `Observable<UploadEvent>` if `http.reportProgress === true` (emits progress events and a final event `{ type: "result", markdown }` or `{ type: "result", ...ConversionResult }`).

### `convertFromUrl`

```ts theme={null}
convertFromUrl(
  url: string,
  options?: ConvertOptions
): Observable<string | ConversionResult>
```

### `convertStream`

```ts theme={null}
convertStream(
  input: { file: File | Blob } | { url: string },
  options?: StreamOptions
): Observable<string>
```

Emits a value for each Markdown fragment received (uses `fetch` with `ReadableStream` internally, wrapped in a `Observable`). Subscribe and concatenate the values ​​in order.

### `pdfIndex`

```ts theme={null}
pdfIndex(url: string, filename?: string): Observable<PdfSpine>
```

### `getJob`

```ts theme={null}
getJob(jobId: string): Observable<JobStatus>
```

## `ConvertOptions`

Same fields as the rest of the SDKs, in camelCase — see [Parameters of API](/docs/api/parameters):

```ts theme={null}
interface ConvertOptions {
  inputFormat?: InputFormat;
  mode?: ConvertMode;
  engine?: Engine;
  clean?: boolean;
  imageOcr?: boolean;
  hybridOcr?: boolean;
  responseFormat?: "markdown" | "json";
  pages?: string;
  outputUrl?: string;
  outputEncoding?: "identity" | "gzip" | "zstd";
  outputHeadUrl?: string;
}
```

## Upload progress

```ts theme={null}
type UploadEvent =
  | { type: "progress"; loaded: number; total: number; percent: number }
  | { type: "result"; markdown: string }
  | { type: "result"; markdown: string; engine: string; timings: Timings; /* ...resto de ConversionResult */ };
```

```ts theme={null}
this.markpdf.convertFile(file, { mode: "fast" }, { reportProgress: true }).subscribe((event) => {
  switch (event.type) {
    case "progress":
      this.percent.set(event.percent);
      break;
    case "result":
      this.markdown.set(event.markdown);
      break;
  }
});
```

Internally it uses `HttpClient` with `reportProgress: true` and `observe: "events"`, filtering and remapping Angular events (`HttpEventType.UploadProgress`, `HttpEventType.Response`) to the simplified form `UploadEvent`.

## Tipos

```ts theme={null}
interface ConversionResult {
  markdown: string;
  filename: string;
  inputFormat: string;
  engine: string;
  sizeBytes: number;
  markdownBytes: number;
  tokenSavedEstimate: number;
  timings: Timings;
}

interface PdfSpine {
  pageCount: number;
  sections: Array<{ page: number; level: number; text: string }>;
  pages: Array<{ page: number; chars: number; firstLine: string }>;
  pagesTruncated: boolean;
  estimatedTokensFull: number;
  estimatedTokensSpineOnly: number;
}

interface JobStatus {
  jobId: string;
  status: "queued" | "processing" | "completed" | "failed";
  body?: string | Record<string, unknown>;
  error?: string;
}
```

All are exported from `@markpdf/angular`.
