How to use the pdfkit function in pdfkit

To help you get started, we’ve selected a few pdfkit 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 nrkno / core-icons / bin / build.js View on Github external
function svgtopdf (el, options, pdf) {
  if (typeof el === 'string') {
    const svg = svgson.parseSync(fs.readFileSync(el, 'utf-8'))
    const [, , width, height] = svg.attributes.viewBox.split(' ').map(Number)
    const scale = 24 / Math.min(width, height)
    const pdfdoc = new PDFDocument({ size: [width * scale, height * scale] })
    pdfdoc.scale(scale)
    pdfdoc.pipe(fs.createWriteStream(el.replace('svg', 'pdf')))
    svgtopdf(svg, { fill: '#000' }, pdfdoc)
    pdfdoc.end()
  } else {
    for (const node of el.children) {
      const fillr = (node.attributes['fill-rule'] || 'nonzero').replace(/-*(zero|odd)$/, '-$1')
      const color = (val) => String(val).replace(/currentColor/i, options.color).replace(/none/i, '')
      const float = (key) => Number(node.attributes[key]) || 0
      const style = {}

      // Style
      pdf.fillColor(style.fill = color(node.attributes['fill'] || options.fill || options.color))
      pdf.strokeColor(style.stroke = color(node.attributes['stroke'] || options.stroke || 'none'))
      pdf.lineWidth(style.lineWidth = Number(node.attributes['stroke-width']) || options.lineWidth || 1)
      pdf.lineJoin(style.lineJoin = node.attributes['stroke-linejoin'] || options.lineJoin || 'miter')
github diegomura / react-pdf / src / mount.js View on Github external
ReactUpdates.batchedUpdates(() => {
    let doc = new pdf();

    const transaction = ReactUpdates.ReactReconcileTransaction.getPooled();

    doc.pipe(fs.createWriteStream(filePath));

    transaction.perform(() => {
      // Starts mounting recursive process
      component.mountComponent(transaction, rootId, null, {doc});

      doc.end();

      if (callback) {
        callback(component.getPublicInstance());
      }
    });
    ReactUpdates.ReactReconcileTransaction.release(transaction);
github cennznet / runanode / app / main / ipc / generatePaperWalletChannel.js View on Github external
// Helpers
      const printMnemonic = (index) => `${index + 1}. ${mnemonics[index]}`;
      const readAssetSync = (p: string) => fs.readFileSync(p.startsWith('..') ? path.join(__dirname, p) : p);

      // Generate QR image for wallet address
      const qrCodeImage = qr.imageSync(address, {
        type: 'png',
        size: 10,
        ec_level: 'L',
        margin: 0
      });
      const textColor = '#040C40';
      const width = 595.28;
      const height = 841.98;
      const doc = new PDFDocument({
        size: [width, height],
        margins: {
          bottom: 0,
          left: 0,
          right: 0,
          top: 0,
        },
        info: {
          Title: messages.infoTitle,
          Author: messages.infoAuthor,
        }
      });
      try {
        // font family
        // const fontBuffer = readAssetSync(paperWalletFontPath);
        // doc.font(fontBuffer);
github cennznet / runanode / app / main / ipc / generatePaperWalletChannel.js View on Github external
// Helpers
      const printMnemonic = (index) => `${index + 1}. ${mnemonics[index]}`;
      const readAssetSync = (p: string) => fs.readFileSync(p.startsWith('..') ? path.join(__dirname, p) : p);

      // Generate QR image for wallet address
      const qrCodeImage = qr.imageSync(address, {
        type: 'png',
        size: 10,
        ec_level: 'L',
        margin: 0
      });
      const textColor = '#040C40';
      const width = 595.28;
      const height = 841.98;
      const doc = new PDFDocument({
        size: [width, height],
        margins: {
          bottom: 0,
          left: 0,
          right: 0,
          top: 0,
        },
        info: {
          Title: messages.infoTitle,
          Author: messages.infoAuthor,
        }
      });

      try {
        // font family
        // const fontBuffer = readAssetSync(paperWalletFontPath);
github foliojs / textkit / temp.js View on Github external
Path,
  Rect,
  LayoutEngine,
  AttributedString,
  Container,
  Attachment
} from '@textkit/textkit';

const path = new Path();

path.rect(30, 30, 300, 400);

// const exclusion = new Path();
// exclusion.circle(140, 160, 50);

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('out.pdf'));

path.toFunction()(doc);
// exclusion.toFunction()(doc);

doc.stroke('green');
doc.stroke();

const string = AttributedString.fromFragments([
  {
    string: 'Lorem ipsum dolor sit amet, ',
    attributes: {
      font: 'Arial',
      fontSize: 14,
      bold: true,
      align: 'justify',
github bpampuch / pdfmake / src / pdfKitEngine.js View on Github external
function createPdfDocument(options = {}) {
	return new PdfKit(options);
}
github tharyckgusmao / integrada.minhabiblioteca.com.br / app / utils / convert.js View on Github external
let files = fs.readdirSync(temp)
    .map((v)=> {
        return {
            name:v
        };
    })
    .sort((a, b)=> {
        return a.name.split('___')[1].split('.')[0] - b.name.split('___')[1].split('.')[0]
    })
    .map((v)=> {
        return temp+'/'+ v.name

    });

    let doc = new pdfkit({
      size: [596, 842]
    });
    doc.pipe(fs.createWriteStream(folderPath+'/'+name+'.pdf'));

    files.forEach((el)=>{
        doc.addPage()
        .image(el,{
          fit: [596, 842],
          align: 'center',
          valign: 'center'
      });

    })

    doc.end();
github huy-nguyen / webpack-and-pdfkit / src / index.js View on Github external
import PDFDocument from 'pdfkit'
import blobStream from 'blob-stream';

const doc = new PDFDocument();
const stream = doc.pipe(blobStream());
stream.on('finish', () => {
  const blob = stream.toBlob('application/pdf');

  const anchor = document.createElement('a');
  document.body.appendChild(anchor);
  anchor.style = 'display: none';
  const url = window.URL.createObjectURL(blob);
  anchor.href = url;
  anchor.download = 'pdfkit-and-webpack.pdf';
  anchor.click();
  window.URL.revokeObjectURL(url);
})

doc.fontSize(25).text('Some text with an embedded font!', 100, 100);
github Automattic / woocommerce-services / client / lib / pdf-label-generator / index.js View on Github external
const renderPDF = ( paperSize, labels ) => {
	const dimensions = PAPER_SIZES[ paperSize ].dimensions;
	const doc = new PDF( {
		size: dimensions,
		margin: 0,
	} );
	doc.fontSize( FONT_SIZE );
	const stream = doc.pipe( blobStream() );

	const renderLabel = ( caption, imageBuffer, pageDimensions, offset ) => {
		const labelSize = caption ? LABEL_SIZE_WITH_CAPTION : LABEL_SIZE;
		const labelX = ( pageDimensions[ 0 ] - labelSize.width ) / 2 - offset[ 0 ];
		let labelY = ( pageDimensions[ 1 ] - labelSize.height ) / 2 - offset[ 1 ];
		if ( caption ) {
			doc.text( caption, labelX, labelY, { width: LABEL_SIZE.width, align: 'center' } );
			labelY += FONT_SIZE + PARAGRAPH_MARGIN;
		}
		doc.image( imageBuffer, labelX, labelY, { fit: PAPER_SIZES.label.dimensions } );
	};

pdfkit

A PDF generation library for Node.js

MIT
Latest version published 5 days ago

Package Health Score

90 / 100
Full package analysis