"jsdom": "^22.1.0",
"minimist": "^1.2.8",
"npx": "^10.2.2",
+ "pdf-lib": "^1.17.1",
"pdfkit": "^0.13.0",
"typescript-parsec": "^0.3.4"
},
"node": ">= 8"
}
},
+ "node_modules/@pdf-lib/standard-fonts": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz",
+ "integrity": "sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==",
+ "dependencies": {
+ "pako": "^1.0.6"
+ }
+ },
+ "node_modules/@pdf-lib/upng": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/@pdf-lib/upng/-/upng-1.0.1.tgz",
+ "integrity": "sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==",
+ "dependencies": {
+ "pako": "^1.0.10"
+ }
+ },
"node_modules/@swc/helpers": {
"version": "0.4.36",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.36.tgz",
"node": ">=8"
}
},
+ "node_modules/pako": {
+ "version": "1.0.11",
+ "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
+ "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
+ },
"node_modules/parent-module": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
"node": "*"
}
},
+ "node_modules/pdf-lib": {
+ "version": "1.17.1",
+ "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz",
+ "integrity": "sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==",
+ "dependencies": {
+ "@pdf-lib/standard-fonts": "^1.0.0",
+ "@pdf-lib/upng": "^1.0.1",
+ "pako": "^1.0.11",
+ "tslib": "^1.11.1"
+ }
+ },
"node_modules/pdfkit": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/pdfkit/-/pdfkit-0.13.0.tgz",
"node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
- "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
- "dev": true
+ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/tslint": {
"version": "6.1.3",
"fastq": "^1.6.0"
}
},
+ "@pdf-lib/standard-fonts": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz",
+ "integrity": "sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==",
+ "requires": {
+ "pako": "^1.0.6"
+ }
+ },
+ "@pdf-lib/upng": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/@pdf-lib/upng/-/upng-1.0.1.tgz",
+ "integrity": "sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==",
+ "requires": {
+ "pako": "^1.0.10"
+ }
+ },
"@swc/helpers": {
"version": "0.4.36",
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.36.tgz",
"release-zalgo": "^1.0.0"
}
},
+ "pako": {
+ "version": "1.0.11",
+ "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
+ "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
+ },
"parent-module": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
"integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==",
"dev": true
},
+ "pdf-lib": {
+ "version": "1.17.1",
+ "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz",
+ "integrity": "sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==",
+ "requires": {
+ "@pdf-lib/standard-fonts": "^1.0.0",
+ "@pdf-lib/upng": "^1.0.1",
+ "pako": "^1.0.11",
+ "tslib": "^1.11.1"
+ }
+ },
"pdfkit": {
"version": "0.13.0",
"resolved": "https://registry.npmjs.org/pdfkit/-/pdfkit-0.13.0.tgz",
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
- "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
- "dev": true
+ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"tslint": {
"version": "6.1.3",
"jsdom": "^22.1.0",
"minimist": "^1.2.8",
"npx": "^10.2.2",
+ "pdf-lib": "^1.17.1",
"pdfkit": "^0.13.0",
"typescript-parsec": "^0.3.4"
}
isBreakPoint(item) {
return item.newLined !== undefined;
}
- /**check if a boeitem is BreakPoint Type */
+ /**check if a boeitem is HGlue Type */
isHGlue(item) {
return item.stretchFactor !== undefined;
}
const canva_1 = require("../canva");
const fontkit = __importStar(require("fontkit"));
const breakLines = __importStar(require("./breakLines"));
+require("pdfkit");
+const pdf_lib_1 = require("pdf-lib");
+const fs = __importStar(require("fs"));
/**
* TYPES
*/
//console.log(breakLineAlgorithms.totalCost(a,70));
let segmentedNodes = breakLineAlgorithms.segmentedNodes(a, 70);
console.log(this.segmentedNodesToFrameBox(segmentedNodes, this.attrs["defaultFrameStyle"]));
+ // generate pdf
+ const pdfDoc = yield pdf_lib_1.PDFDocument.create();
+ var page = pdfDoc.addPage();
+ page.drawText('You can create PDFs!');
+ for (var j = 0; j < 1000; j += 5) {
+ if (j % 50 == 0) {
+ page.drawText(i.toString(), { x: 50, y: j });
+ }
+ page.drawLine({
+ start: { x: 0, y: j },
+ end: { x: 1000, y: j },
+ thickness: 0.5,
+ color: (0, pdf_lib_1.rgb)(0.75, 0.2, 0.2),
+ opacity: 0.20,
+ });
+ }
+ for (var i = 0; i < 1000; i += 5) {
+ if (i % 50 == 0) {
+ page.drawText(i.toString(), { x: i, y: 50 });
+ }
+ page.drawLine({
+ start: { x: i, y: 0 },
+ end: { x: i, y: 1000 },
+ thickness: 0.5,
+ color: (0, pdf_lib_1.rgb)(0.75, 0.2, 0.2),
+ opacity: 0.20,
+ });
+ }
+ pdfDoc.save();
+ const pdfBytes = yield pdfDoc.save();
+ fs.writeFileSync("blank.pdf", pdfBytes);
});
}
segmentedNodesToFrameBox(segmentedNodes, frame) {
import * as fontkit from "fontkit";
import * as util from "node:util";
import * as breakLines from "./breakLines";
+import "pdfkit";
+import PDFKitPage from "pdfkit/js/page";
+import { ColorTypes, PDFDocument, rgb } from "pdf-lib";
+import * as fs from "fs";
/**
* TYPES
//console.log(breakLineAlgorithms.totalCost(a,70));
let segmentedNodes = breakLineAlgorithms.segmentedNodes(a, 70);
- console.log(this.segmentedNodesToFrameBox(segmentedNodes, <FrameBox>this.attrs["defaultFrameStyle"]));
+ console.log(
+ this.segmentedNodesToFrameBox(segmentedNodes, <FrameBox>this.attrs["defaultFrameStyle"]));
+
+ // generate pdf
+ const pdfDoc = await PDFDocument.create();
+ var page = pdfDoc.addPage();
+ page.drawText('You can create PDFs!');
+
+ for (var j = 0; j<1000; j+=5){
+ if (j %50 == 0){
+ page.drawText(i.toString(), {x: 50, y: j});
+ }
+
+ page.drawLine({
+ start: { x: 0, y: j },
+ end: { x: 1000, y: j },
+ thickness: 0.5,
+ color: rgb(0.75, 0.2, 0.2),
+ opacity: 0.20,
+ });
+ }
+
+ for (var i = 0; i<1000; i+=5){
+ if (i % 50 == 0){
+ page.drawText(i.toString(), {x: i, y: 50});
+ }
+ page.drawLine({
+ start: { x: i, y: 0 },
+ end: { x: i, y: 1000 },
+ thickness: 0.5,
+ color: rgb(0.75, 0.2, 0.2),
+ opacity: 0.20,
+ });
+ }
+ pdfDoc.save();
+
+ const pdfBytes = await pdfDoc.save();
+ fs.writeFileSync("blank.pdf", pdfBytes);
}
segmentedNodesToFrameBox(segmentedNodes : BoxesItem[][], frame : FrameBox) : Box{