Skip to content

Commit

Permalink
docs: enhance API & add missing license
Browse files Browse the repository at this point in the history
  • Loading branch information
fraxken committed Sep 2, 2022
1 parent 3f67cbd commit 6ff5869
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
67 changes: 50 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,36 @@ main().catch(console.error);

## API

### initBrowser(options: PuppeteerLaunchOptions): Promise<Browser>
<details>
<summary>initBrowser(options?: PuppeteerLaunchOptions): Promise< Browser ></summary>

```js
import { initBrowser } from "@myunisoft/html-to-pdf";

const browser = await initBrowser();
```

Options payload is described by the following TypeScript interface:
```ts
import {
LaunchOptions,
BrowserLaunchArgumentOptions,
BrowserConnectOptions,
Product
} from "puppeteer";

type PuppeteerLaunchOptions = LaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions & {
product?: Product;
extraPrefsFirefox?: Record<string, unknown>;
}

async function main() {
const browser = await initBrowser();
}
main().catch(console.error);
```
### generatePDF(browser: Browser, files: pdfFile[], options?: PuppeteerPDFOptions): Promise<genPDFPayload>
</details>
<details>
<summary>generatePDF(browser: Browser, files: pdfFile[], options?: PuppeteerPDFOptions): AsyncIterableIterator< Buffer ></summary>
`files` and `options` arguments are described with the following TypeScript interface/type:
```ts
interface pdfFile {
content?: string,
Expand All @@ -74,23 +88,39 @@ type PuppeteerPDFOptions = PDFOptions & { paginationOffset?: number };
```

```js
async function main() {
const browser = await initBrowser();
const readable = Readable.from(generatePDF(browser, [{ content: html.content }], pdfOptions));
}
main().catch(console.error);
import * as pdf from "@myunisoft/html-to-pdf";

const browser = await pdf.initBrowser();

const pdfOptions = {};
const content = "..HTML HERE..";

const readable = Readable.from(
pdf.generatePDF(browser, [{ content }], pdfOptions)
);
// Do the work with readable (pipe to an http response for example).
```

### terminateBrowser(browser: Browser): Promise<void>
</details>

<details>
<summary>terminateBrowser(browser: Browser): Promise< void ></summary>

```js
async function main() {
const browser = await pdf.initBrowser();
await terminateBrowser(browser);
import * as pdf from "@myunisoft/html-to-pdf";

const browser = await pdf.initBrowser();

try {
// DO THE WORK HERE
}
finally {
await pdf.terminateBrowser(browser);
}
main().catch(console.error);
```

</details>

## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
Expand All @@ -114,3 +144,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

## License
MIT
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function* generatePDF(
browser: Browser,
files: pdfFile[],
options?: PuppeteerPDFOptions
): AsyncIterableIterator<Buffer> {
): AsyncIterableIterator<Buffer> {
const { paginationOffset = 0, ...pdfOptions } = options ?? {};

if (!browser) {
Expand Down

0 comments on commit 6ff5869

Please sign in to comment.