How to use the pdfjs.Image 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
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()
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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();
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
// 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 })
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
let text = doc.text({ fontSize: 12 });
text.add("Lorem Ipsum ...");

let cell = doc.cell("Cell Text", { padding: 10 });
cell.text("More text ...");

const table1 = doc.table({
    widths: [256, 256],
    borderHorizontalWidth: 10
});

let row = table1.row();
row.cell("Cell 1");
row.cell("Cell 2");

const img1 = new pdf.Image(readFileSync("image.jpg"));
doc.image(img1, {
    height: 55,
    align: "center"
});

doc.op(1, 0, 0, "sc");
doc.op((x: any, y: any) => {
    const height = 40;
    return [x, y - height, x + 60, height, "re"];
});
doc.op("f");

doc.text("goto", { goTo: "here" });
doc.pageBreak();
doc.destination("here");
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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.',
        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,
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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.',
        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,
github rkusa / pdfjs / types / pdfjs-tests.ts View on Github external
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.',
        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,

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