Skip to content

Prevent Text Overflow #1525

@Sinterus

Description

@Sinterus

Is it possible to prevent text overflow?

Description

I want to create a document, which has a big title-esque text field on the bottom. If I increase the y position just a bit further, it will be rendered on a new page despite having about 100pt left for the text to render. Is it possible to suppress overflow or violate the page margins?

My code:

const PDFDocument = require("pdfkit");
const fs = require("fs");

// Create a document
const doc = new PDFDocument({
  size: "A4",
  layout: "landscape",
});
doc.pipe(fs.createWriteStream("foo.pdf"));

//  Actual Content
//  Shapes
doc.rect(220.945, 50, 400, 400).stroke();
doc.rect(841.89 - 30 - 160, 50, 160, 50).stroke();
doc.rect(30, 50, 160, 50).stroke();
doc.rect(841.89 - 30 - 160, 595.28 - 250, 160, 50).stroke();

//  Text
doc.fontSize(20).text("Field 1", 30, 97.64 + 35);
doc.fontSize(20).text("Field 2", 841.89 - (160 + 30), 97.64 + 35);
doc.fontSize(20).text("Field 3", 841.89 - (160 + 30), 400 + 97.64 - 75);
doc.fontSize(25).text("Placeholder for description",40,490,{
  align: "center",
  lineBreak: "false",
});
doc.end();

My environment

  • pdfkit version: 0.15
  • Node version: 22.2
  • Browser version (if applicable): run as script
  • Operating System: Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions