# HtmlExport

## Content

# Namespace: HtmlExport

## Table of contents

### Type aliases

- [CheckCancelCallback](HtmlExport#checkcancelcallback)
- [HtmlExportResult](HtmlExport#htmlexportresult)
- [HtmlSettings](HtmlExport#htmlsettings)
- [OnProgressCallback](HtmlExport#onprogresscallback)

### Functions

- [exportDocument](HtmlExport#exportdocument)

## Type aliases

### <a id="checkcancelcallback" name="checkcancelcallback"></a> CheckCancelCallback

Ƭ **CheckCancelCallback**: () => `boolean`

#### Type declaration

▸ (): `boolean`

Defines a callback that determines whether export should be canceled.

**`example`**
```ts
const shouldCancel: CheckCancelCallback = () => false;
```

##### Returns

`boolean`

`true` to cancel the export; otherwise, `false`.

___

### <a id="htmlexportresult" name="htmlexportresult"></a> HtmlExportResult

Ƭ **HtmlExportResult**: `Object`

Represents the result of an HTML export.

**`example`**
```ts
const result: HtmlExportResult = {
	data: '<html></html>',
	download: (name) => console.log(name),
};
```

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `data` | `Blob` \| `string` | Gets or sets the exported content.  **`remarks`** Returns a `string` for single HTML output and a `Blob` for ZIP output. |
| `download` | (`filename?`: `string`) => `void` | Gets or sets the function that triggers a browser download of the export result.  **`example`** ```ts const result = {} as HtmlExportResult; result.download('report.html'); ``` |

___

### <a id="htmlsettings" name="htmlsettings"></a> HtmlSettings

Ƭ **HtmlSettings**: `Object`

Represents HTML export settings.

**`example`**
```ts
const settings: HtmlSettings = {
	outputType: 'html',
	title: 'Invoice',
};
```

#### Type declaration

| Name | Type | Description |
| :------ | :------ | :------ |
| `autoPrint?` | `boolean` | Gets or sets whether an auto-print script is added on page load. |
| `embedFonts?` | `boolean` | Gets or sets whether fonts are embedded in the exported HTML.  **`remarks`** Requires `outputType` to be `'zip'`. |
| `embedImages?` | ``"none"`` \| ``"embed"`` \| ``"external"`` | Gets or sets how images are embedded in the exported HTML.  **`remarks`** Accepted values: - `'none'`: Do not embed images. - `'embed'`: Embed images as data URIs. - `'external'`: Store images as external files in the archive.  Using `'external'` requires `outputType` to be `'zip'`. |
| `multiPage?` | `boolean` | Gets or sets whether each page is exported as a separate HTML file.  **`remarks`** Requires `outputType` to be `'zip'`. |
| `outputType?` | ``"html"`` \| ``"zip"`` \| ``"auto"`` | Gets or sets the output format.  **`remarks`** Accepted values: - `'html'`: Export a single HTML file. - `'zip'`: Export a ZIP archive. - `'auto'`: Choose automatically based on other settings. |
| `title?` | `string` | Gets or sets the title of the HTML page.  **`remarks`** This value maps to the `<title>` element in the HTML output. |

___

### <a id="onprogresscallback" name="onprogresscallback"></a> OnProgressCallback

Ƭ **OnProgressCallback**: (`pageNumber`: `number`) => `void`

#### Type declaration

▸ (`pageNumber`): `void`

Defines a callback invoked after each page is rendered.

**`example`**
```ts
const onProgress: OnProgressCallback = (pageNumber) => console.log(pageNumber);
```

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `pageNumber` | `number` | The one-based page number that has finished rendering. |

##### Returns

`void`

## Functions

### <a id="exportdocument" name="exportdocument"></a> exportDocument

▸ **exportDocument**(`source`, `settings?`, `onProgress?`, `checkCancel?`): `Promise`<[`HtmlExportResult`](HtmlExport#htmlexportresult)\>

Exports a PageDocument or VDomRenderer to HTML.

**`example`**
```ts
const result = await exportDocument(report, { outputType: 'html', title: 'Report' });
result.download('report.html');
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `source` | [`PageDocument`](../classes/Core.PageDocument) \| `VDomRenderer` | The source document or renderer to export. |
| `settings?` | [`HtmlSettings`](HtmlExport#htmlsettings) | The HTML export settings. |
| `onProgress?` | [`OnProgressCallback`](HtmlExport#onprogresscallback) | The callback invoked after each page is rendered. |
| `checkCancel?` | [`CheckCancelCallback`](HtmlExport#checkcancelcallback) | The callback invoked before rendering each page. Return `true` to cancel. |

#### Returns

`Promise`<[`HtmlExportResult`](HtmlExport#htmlexportresult)\>

A promise that resolves to the export result.
