Skip to content

Commit

Permalink
feat(@generator, @type): Add default pdfkit info config (#19)
Browse files Browse the repository at this point in the history
* chore: add gitignore for test

* feat(generator): Add default pdfkit info config

* feat(type): add description about pdfkit info

* chore: changeset
  • Loading branch information
junghyeonsu authored Sep 7, 2023
1 parent 67f877b commit 8265bdf
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/blue-snails-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@icona/generator": patch
"@icona/types": patch
---

feat(generator, type): Add description about pdfkit info option and add default option
5 changes: 5 additions & 0 deletions .changeset/quiet-pens-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@icona/generator": patch
---

delete CreationDate in pdfkit
8 changes: 8 additions & 0 deletions packages/icona-generator/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
dist

# for test
svg
pdf
react
drawable
.icona
icona.js
Binary file added packages/icona-generator/pdf/icon_laptop_thin.pdf
Binary file not shown.
28 changes: 27 additions & 1 deletion packages/icona-generator/src/core/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,33 @@ export const generatePDF = ({
makeFolderIfNotExistFromRoot(path);

const svgPath = resolve(projectPath, path, `${name}.pdf`);
const pdfDoc = new PDFDocument(pdfkitConfig);

/**
* @see https://github.com/foliojs/pdfkit/blob/4ec77ddc8c090c8d0d57fbd72cff433e9ce0d733/docs/getting_started.md?plain=1#L194
* @description
* If you use `info` option, pdf output will be different every time.
* So it occur git diff. So we use default info option.
*
* If user want change info option, they can change it.
* But not recommend.
*/
const defaultPdfkitConfigInfo = {
Author: "Icona",
Creator: "Icona",
Producer: "Icona",
Title: name,
Subject: name,
Keywords: name,
CreationDate: new Date(0),
ModDate: new Date(0),
};

const pdfkitConfigInfo = pdfkitConfig.info || defaultPdfkitConfigInfo;
const pdfDoc = new PDFDocument({
...pdfkitConfig,
info: pdfkitConfigInfo,
});

SVGtoPDF(pdfDoc, svg, x, y, restSvgToPdfOptions);
pdfDoc.pipe(createWriteStream(svgPath));
pdfDoc.end();
Expand Down
33 changes: 32 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ import type { Config as SvgrConfig } from "@svgr/core";
import type { SVGtoPDFOptions } from "svg-to-pdfkit";
import type { Config as SvgoConfig } from "svgo";

type PDFKitConfig = PDFKit.PDFDocumentOptions & {
/**
* @readme
* If you use `info` option, pdf output will be different every time.
* So it occur git diff. So we use default info option.
* If user want change info option, they can change it.
* **But not recommend.**
*
* ```ts
* const defaultPdfkitConfigInfo = {
Author: "Icona",
Creator: "Icona",
Producer: "Icona",
Title: IconName,
Subject: IconName,
Keywords: IconName,
CreationDate: new Date(0),
ModDate: new Date(0),
};
* ```
*/
info?: PDFKit.PDFDocumentOptions["info"];
};

export type IconaIconData = {
name: string;
svg: string;
Expand All @@ -27,8 +51,15 @@ export interface GeneratePDFConfig {
/**
* PDFKit.PDFDocumentOptions
* @see https://pdfkit.org/docs/getting_started.html#document-structure
*
* @readme
* If you use `info` option, pdf output will be different every time.
* So it occur git diff. So we use default info option.
*
* If user want change info option, they can change it.
* But not recommend.
*/
pdfKitConfig?: PDFKit.PDFDocumentOptions;
pdfKitConfig?: PDFKitConfig;

svgToPdfOptions?: SvgToPdfOptions;
}
Expand Down

0 comments on commit 8265bdf

Please sign in to comment.