How to use the pdfjs.Document 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
});

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
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
// 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`);
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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);
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
// 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 });
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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.',
        shorter: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.',
    },
    document: {
        test: new pdf.ExternalDocument(fs.readFileSync(path.join(__dirname, 'document/test.pdf'))),
        pdfjsCreated: new pdf.ExternalDocument(fs.readFileSync(path.join(__dirname, 'document/pdfjs-created.pdf'))),
    }
};

doc = new pdf.Document({
    font: f.font.afm.regular,
    padding: 10,
    lineHeight: 1,
})

doc.info.id = '42'
doc.info.creationDate = new Date(2015, 1, 19, 22, 33, 26)
doc.info.producer = 'pdfjs tests (github.com/rkusa/pdfjs)'

doc.end().catch(err => {
    console.error(err)
})

doc.text('goto', { goTo: 'here' })

doc.pageBreak()
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
doc = new pdf.Document({ font: Symbol });

import * as TimesBold from "pdfjs/font/Times-Bold";
doc = new pdf.Document({ font: TimesBold });

import * as TimesBoldItalic from "pdfjs/font/Times-BoldItalic";
doc = new pdf.Document({ font: TimesBoldItalic });

import * as TimesItalic from "pdfjs/font/Times-Italic";
doc = new pdf.Document({ font: TimesItalic });

import * as TimesRoman from "pdfjs/font/Times-Roman";
doc = new pdf.Document({ font: TimesRoman });

import * as ZapfDingbats from "pdfjs/font/ZapfDingbats";
doc = new pdf.Document({ font: ZapfDingbats });
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
doc.text(f.lorem.short, { fontSize: 20 })

doc.cell(f.lorem.short, { width: 200, padding: 20, backgroundColor: 0xeeeeee })

doc.text(f.lorem.short)

cell = doc.cell({
    backgroundColor: 0xeeeeee, padding: 10, width: 256, borderWidth: 1,
    x: 256,
    y: 256,
})
cell.text(f.lorem.short)

doc.text(f.lorem.short)

doc = new pdf.Document({
    font: f.font.afm.regular,
    paddingLeft: 0,
    paddingRight: 0,
})
doc.text(f.lorem.short)

const external = f.document.test

doc.addPagesOf(external)

doc.text('Should be on third page ...')

doc.text('Should be on first page ...')

doc.addPagesOf(external)

pdfjs

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

MIT
Latest version published 12 months ago

Package Health Score

61 / 100
Full package analysis