Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'pdfjs' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
});
let row2 = table4.row();
row2.cell("Cell Left");
row2.cell("Cell Right");
const text2 = doc.text();
text2.add("add 1", { fontSize: 14 });
text2.br();
text2.add("add 2");
text.append("add3");
text.append("add4", { alignment: "justify" });
// from playground
const lorem = "lorem";
var docPlayground = new pdf.Document({ font: helveticaFont });
var header3 = docPlayground
.header()
.table({ widths: [null, null], paddingBottom: 1 * pdf.cm })
.row();
header3.cell().image(logo, { height: 2 * pdf.cm });
header3
.cell()
.text({ textAlign: "right" })
.add(
"A Portable Document Format (PDF) generation library targeting both the server- and client-side."
)
.add("https://github.com/rkusa/pdfjs", {
link: "https://github.com/rkusa/pdfjs",
underline: true,
color: 0x569cd6
// An outline with an unknown or empty destination is added to the outlines but is not reactive
doc.outline('4. Empty/Unknown destinations', '')
doc.outline('4.1. Can have children', 'Unknown', '4. Empty/Unknown destinations')
doc.outline('4.2. But are not reactive', 'Unknown', '4. Empty/Unknown destinations')
// If an outline is defined with a parent that has not already been declared, then the parent is added to the root with the same destination before the child outline is added
doc.outline('5.1. Can have children', 'Image', '5. Undeclared parents')
// An outline with an empty or undefined parent is attached to the root
doc.outline('6. An outline with an undefined parent is added to the root', 'Text')
doc.outline('7. So is an outline with an empty parent', 'Doc', '')
}
// from real usage
doc = new pdf.Document({ font: helveticaFont });
doc.cell({ paddingBottom: 0.5 * pdf.cm }).image(logo, { width: 150 });
doc
.cell({ paddingBottom: 0.5 * pdf.cm })
.text()
.add("Receipt", { font: helveticaBoldFont, fontSize: 14 })
.br()
.add("The Old Reader, Inc.")
.br()
.add("theoldreader.com", {
underline: true,
color: 0x569cd6,
link: "https://theoldreader.com"
})
.br()
.add(`Invoice ID: 456-4581-4545`);
import * as path from "path"
const helveticaFont: pdf.Font = require("pdfjs/font/Helvetica");
const helveticaBoldFont: pdf.Font = require("pdfjs/font/Helvetica-Bold");
const timesRomanFont: pdf.Font = require("pdfjs/font/TimesRoman");
const src: Buffer = readFileSync("tor-logo.jpg");
const logo: pdf.Image = new pdf.Image(src);
let doc: pdf.Document;
// from docs
// ReadMe
doc = new pdf.Document()
doc = new pdf.Document({
font: require("pdfjs/font/helvetica"),
padding: 10
});
doc.pipe(createWriteStream("output.pdf"));
// render something onto the document
async () => {
await doc.end();
};
new pdf.Font(readFileSync("./opensans/regular.ttf"));
const image1 = readFileSync("image.jpg");
let img = new pdf.Image(image1);
doc.image(img);
// utilities
function readFileSync(src: string): Buffer {
return new Buffer(src);
}
function createWriteStream(destination: string): any {
return destination;
}
function writeFileSync(_name: string, _data: Buffer, _opts: any) { }
/***** Fonts *****/
import * as Courier from "pdfjs/font/Courier";
doc = new pdf.Document({ font: Courier });
import * as CourierBold from "pdfjs/font/Courier-Bold";
doc = new pdf.Document({ font: CourierBold });
import * as CourierBoldOblique from "pdfjs/font/Courier-BoldOblique";
doc = new pdf.Document({ font: CourierBoldOblique });
import * as CourierOblique from "pdfjs/font/Courier-Oblique";
doc = new pdf.Document({ font: CourierOblique });
import * as Helvetica from "pdfjs/font/Helvetica";
doc = new pdf.Document({ font: Helvetica });
import * as HelveticaBold from "pdfjs/font/Helvetica-Bold";
doc = new pdf.Document({ font: HelveticaBold });
doc = new pdf.Document({
font: require("pdfjs/font/helvetica"),
padding: 10
});
doc.pipe(createWriteStream("output.pdf"));
// render something onto the document
async () => {
await doc.end();
};
new pdf.Font(readFileSync("./opensans/regular.ttf"));
const image1 = readFileSync("image.jpg");
let img = new pdf.Image(image1);
doc.image(img);
const externalDoc1 = readFileSync("other.pdf");
const ext = new pdf.ExternalDocument(externalDoc1);
doc.setTemplate(ext);
doc.addPagesOf(ext);
doc.addPageOf(1, ext);
let header = doc.header();
header.text("This is a header");
let footer = doc.footer();
footer.text("This is a footer");
doc
.asBuffer()
import * as pdf from "pdfjs";
import * as fs from "fs"
import * as path from "path"
const helveticaFont: pdf.Font = require("pdfjs/font/Helvetica");
const helveticaBoldFont: pdf.Font = require("pdfjs/font/Helvetica-Bold");
const timesRomanFont: pdf.Font = require("pdfjs/font/TimesRoman");
const src: Buffer = readFileSync("tor-logo.jpg");
const logo: pdf.Image = new pdf.Image(src);
let doc: pdf.Document;
// from docs
// ReadMe
doc = new pdf.Document()
doc = new pdf.Document({
font: require("pdfjs/font/helvetica"),
padding: 10
});
doc.pipe(createWriteStream("output.pdf"));
// render something onto the document
async () => {
await doc.end();
// relative
doc.op(1, 0, 0, 'sc')
doc.op((x: number, y: number) => {
const height = 40
return [x, y - height, x + 60, height, 're']
})
doc.op('f')
img = new pdf.Image(fs.readFileSync(path.join(__dirname, '/fixtures/illustrator.pdf')))
doc.image(img, {
wrap: false, x: 0, y: 841.89, width: 595.28
})
img = new pdf.Image(fs.readFileSync(path.join(__dirname, '/fixtures/indesign-interactive.pdf')))
doc.image(img, {
wrap: false, x: 0, y: 841.89, width: 595.28, height: 841.89
})
let table = doc.table({
widths: [256, 256],
padding: 0,
borderWidth: 10,
})
row = table.row()
row.cell(f.lorem.short, { textAlign: 'justify', fontSize: 20, padding: 10, backgroundColor: 0xdddddd })
doc.pipe(createWriteStream("output.pdf"));
// render something onto the document
async () => {
await doc.end();
};
new pdf.Font(readFileSync("./opensans/regular.ttf"));
const image1 = readFileSync("image.jpg");
let img = new pdf.Image(image1);
doc.image(img);
const externalDoc1 = readFileSync("other.pdf");
const ext = new pdf.ExternalDocument(externalDoc1);
doc.setTemplate(ext);
doc.addPagesOf(ext);
doc.addPageOf(1, ext);
let header = doc.header();
header.text("This is a header");
let footer = doc.footer();
footer.text("This is a footer");
doc
.asBuffer()
.then((data: Buffer) => writeFileSync("test.pdf", data, { encoding: "binary" }));
doc.asBuffer((err: Error, data: Buffer) => {
if (err) {
addRow(3, "Article D", lorem, 1220);
addRow(2, "Article E", lorem, 120);
addRow(5, "Article F", lorem, 50);
// from tests
const openSansRegular = fs.readFileSync(path.join(__dirname, 'font/opensans/regular.ttf'))
const openSansBold = fs.readFileSync(path.join(__dirname, 'font/opensans/bold.ttf'))
const jpegImage = fs.readFileSync(path.join(__dirname, 'image/pdfjs.jpg'))
const pdfImage = fs.readFileSync(path.join(__dirname, 'image/pdfjs.pdf'))
const complexPdfImage = fs.readFileSync(path.join(__dirname, 'image/complex.pdf'))
const f = {
font: {
opensans: {
regular: new pdf.Font(openSansRegular),
bold: new pdf.Font(openSansBold)
},
afm: {
regular: require('../../font/Helvetica'),
bold: require('../../font/Helvetica-Bold'),
monoRegular: require('../../font/Courier'),
monoBold: require('../../font/Courier-Bold'),
}
},
image: {
jpeg: new pdf.Image(jpegImage),
pdf: new pdf.Image(pdfImage),
complexPdf: new pdf.Image(complexPdfImage),
},
lorem: {
long: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\nDuis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.\n\nUt wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.',
addRow(2, "Article E", lorem, 120);
addRow(5, "Article F", lorem, 50);
// from tests
const openSansRegular = fs.readFileSync(path.join(__dirname, 'font/opensans/regular.ttf'))
const openSansBold = fs.readFileSync(path.join(__dirname, 'font/opensans/bold.ttf'))
const jpegImage = fs.readFileSync(path.join(__dirname, 'image/pdfjs.jpg'))
const pdfImage = fs.readFileSync(path.join(__dirname, 'image/pdfjs.pdf'))
const complexPdfImage = fs.readFileSync(path.join(__dirname, 'image/complex.pdf'))
const f = {
font: {
opensans: {
regular: new pdf.Font(openSansRegular),
bold: new pdf.Font(openSansBold)
},
afm: {
regular: require('../../font/Helvetica'),
bold: require('../../font/Helvetica-Bold'),
monoRegular: require('../../font/Courier'),
monoBold: require('../../font/Courier-Bold'),
}
},
image: {
jpeg: new pdf.Image(jpegImage),
pdf: new pdf.Image(pdfImage),
complexPdf: new pdf.Image(complexPdfImage),
},
lorem: {
long: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\nDuis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.\n\nUt wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.',
short: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',