How to use the pdfjs.Font function in pdfjs

To help you get started, we’ve selected a few pdfjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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.',
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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.',
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
// 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);

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");

pdfjs

A Portable Document Format (PDF) generation library targeting both the server- and client-side.

MIT
Latest version published 1 year ago

Package Health Score

66 / 100
Full package analysis