Skip to content

Commit

Permalink
Add options
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Jan 12, 2022
1 parent 3f8e79c commit a3b50a3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ const text = "# hello world";

## Options

| Key | Default | Type | Description |
| ------ | -------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| output | "buffer" | `"buffer"` `"blob"` `"raw"` | Set output type of `VFile.result`. `buffer` is `Promise<ArrayBuffer>`. `blob` is `Promise<Blob>`. `raw` is internal data for testing. |
| Key | Default | Type | Description |
| --------------- | --------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| output | "buffer" | `"buffer"` `"blob"` `"raw"` | Set output type of `VFile.result`. `buffer` is `Promise<ArrayBuffer>`. `blob` is `Promise<Blob>`. `raw` is internal data for testing. |
| info | undefined | TDocumentInformation? | |
| pageMargins | undefined | Margins? | |
| pageOrientation | undefined | PageOrientation? | |
| pageSize | undefined | PageSize? | |
| userPassword | undefined | string? | |
| ownerPassword | undefined | string? | |
| permissions | undefined | DocumentPermissions? | |
| version | undefined | PDFVersion? | |
| watermark | undefined | Watermark? | |
37 changes: 35 additions & 2 deletions src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type {
ContentUnorderedList,
Style,
TableCell,
TDocumentDefinitions,
TDocumentInformation,
} from "pdfmake/interfaces";

(<any>pdfMake).vfs = pdfFonts.pdfMake.vfs;
Expand Down Expand Up @@ -49,19 +51,50 @@ type Context = {
export type Opts = {
output?: "buffer" | "blob" | "raw";
imageResolver?: ImageResolver;
};
info?: TDocumentInformation;
} & Pick<
TDocumentDefinitions,
| "pageMargins"
| "pageOrientation"
| "pageSize"
| "userPassword"
| "ownerPassword"
| "permissions"
| "version"
| "watermark"
>;

const error = (message: string) => {
throw new Error(message);
};

export function mdastToPdf(
node: mdast.Root,
{ output }: Opts,
{
output,
info,
pageMargins,
pageOrientation,
pageSize,
userPassword,
ownerPassword,
permissions,
version,
watermark,
}: Opts,
images: ImageDataMap
): Promise<any> | pdfMake.TCreatedPdf {
const content = convertNodes(node.children, { deco: {}, images });
const doc = pdfMake.createPdf({
info,
pageMargins,
pageOrientation,
pageSize,
userPassword,
ownerPassword,
permissions,
version,
watermark,
content,
images,
styles: {
Expand Down

0 comments on commit a3b50a3

Please sign in to comment.