-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Open
Description
Description
When using the html()
method to convert HTML content containing <strong>
tags to PDF, bold text renders with a vertical offset (positioned lower than normal text), causing it to overlap with subsequent lines. This issue only occurs in multi-page documents and the offset appears to accumulate progressively across pages.
Environment
- jsPDF version: 2.5.2
- jspdf-autotable version: 3.8.4
- Framework: Angular/TypeScript
- Custom fonts: Montserrat (Regular, Bold, Italic, BoldItalic)
- Document size: 8 pages
- Affected pages: Pages 1-6+ (worsens with page count)
Expected Behavior
Bold text from <strong>
tags should align on the same baseline as normal text without vertical offset or overlap.
Actual Behavior
- Bold text renders vertically lower than normal text
- Bold text overlaps with the line below it
- The offset increases progressively across multiple pages
- Adding more content increases the offset magnitude
- Issue does not occur on single-page documents
Reproduction Steps
import jsPDF from 'jspdf';
public static async generateBlobFromHTML(
htmlContent: HTMLElement,
): Promise<Blob> {
// Create a new jsPDF instance
let doc = new jsPDF();
// Add the Montserrat font to jsPDF
doc = PdfUtility.addMontserratFont(doc);
await document.fonts.ready;
// Convert HTML to PDF and then to a Blob
return new Promise((resolve) => {
doc.html(htmlContent.innerHTML, {
callback: (doc) => {
const totalPages = doc.getNumberOfPages();
for (let i = 1; i <= totalPages; i++) {
doc.setPage(i);
doc.setFontSize(10);
doc.text(
`${i}/${totalPages}`,
doc.internal.pageSize.getWidth() - 10,
doc.internal.pageSize.getHeight() - 10,
{ align: "right" },
);
}
const blob = doc.output("blob");
resolve(new Blob([blob], { type: "application/pdf" }));
},
autoPaging: "text",
margin: 15,
//180 as page is 200 in total. So 200 - 15 (margin) - 5(for adjusting single character in the end of paragraph), to make it break correctly.
width: 180,
//800, as it scales the size of the text correctly
windowWidth: 800,
});
});
}
private static addMontserratFont(doc: jsPDF): jsPDF {
doc.addFileToVFS("Montserrat-Regular-normal.ttf", MontserratReuglar);
doc.addFont("Montserrat-Regular-normal.ttf", "Montserrat", "normal");
doc.addFileToVFS("Montserrat-Bold.ttf", MontserratBold);
doc.addFont("Montserrat-Bold.ttf", "Montserrat", "bold");
doc.addFileToVFS("Montserrat-Italic.ttf", MontserratItallic);
doc.addFont("Montserrat-Italic.ttf", "Montserrat", "italic");
doc.addFileToVFS(
"Montserrat-BoldItalic-bolditalic.ttf",
MontserratBoldItallic,
);
doc.addFont(
"Montserrat-BoldItalic-bolditalic.ttf",
"Montserrat",
"bolditalic",
);
doc.setFont("Montserrat");
return doc;
}
HTML Content Sample:
<p><strong>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</strong> Nullam vel nisi. Etiam semper ipsum ut lectus...</p>
<p>More paragraphs with mixed bold and normal text...</p>
<!-- Content that spans 8+ pages -->
Visual Evidence
See attached screenshot showing bold text overlapping with normal text below it.
Additional Context
- Issue only manifests with multi-page documents (8 pages in my case)
- Offset accumulates across pages (worse on later pages)


Metadata
Metadata
Assignees
Labels
No labels