How to use the pdf-lib.drawLinesOfText function in pdf-lib

To help you get started, we’ve selected a few pdf-lib 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 Hopding / pdf-lib / examples / document_creation / node / index.js View on Github external
height: MARIO_PNG_HEIGHT,
  }),
  // Next we'll draw a Solarized White rectangle with a Solarized Gray border
  // beneath the image of Mario. It will be centered horizontally in the page.
  drawRectangle({
    x: PAGE_2_WIDTH * 0.5 - TEXT_BOX_WIDTH * 0.5,
    y: PAGE_2_HEIGHT * 0.5 - 100,
    width: TEXT_BOX_WIDTH,
    height: 90,
    colorRgb: SOLARIZED_WHITE,
    borderWidth: 4,
    borderColorRgb: SOLARIZED_GRAY,
  }),
  // Now we'll draw three lines of text within the rectangle we just drew. The
  // text will be drawn in the Ubuntu font colored Solarized Gray.
  drawLinesOfText(
    [
      'Here is a picture of Mario',
      'running. It was placed in',
      'this PDF using JavaScript!',
    ],
    {
      x: PAGE_2_WIDTH * 0.5 - TEXT_BOX_WIDTH * 0.5 + 10,
      y: PAGE_2_HEIGHT * 0.5 - 38,
      font: UBUNTU_FONT,
      size: 24,
      colorRgb: SOLARIZED_GRAY,
    },
  ),
);

// Here we (1) register the content stream to the PDF document, and (2) add the
github Hopding / pdf-lib / examples / document_modification / node / index.js View on Github external
// `drawImage` is a "composite" PDF operator that lets us easily draw an image
  // on a page's content stream. "composite" just means that it is composed of
  // several lower-level PDF operators. Usually, you'll want to work with
  // composite operators - they make things a lot easier! The naming convention
  // for composite operators is "draw".
  //
  // Here we draw the image of Mario on the page's content stream. We'll draw
  // him centered horizontally in the top half of the page.
  drawImage(MARIO_PNG, {
    x: 200,
    y: 350,
    width: MARIO_PNG_WIDTH,
    height: MARIO_PNG_HEIGHT,
  }),
  // Now let's draw 2 lines of red Courier text near the bottom of the page.
  drawLinesOfText(['This text was added', 'with JavaScript!'], {
    x: 30,
    y: 150,
    font: COURIER_FONT,
    size: 48,
    colorRgb: [1, 0, 0],
  }),
);

// Here we (1) register the content stream to the PDF document, and (2) add the
// reference to the registered stream to the page's content streams.
existingPage.addContentStreams(pdfDoc.register(newContentStream));

/* ================= 4. Setup and Create New First Page ===================== */
// This step is platform independent. The same code can be used in any
// JavaScript runtime (e.g. Node, the browser, or React Native).
const page1 = pdfDoc