admin管理员组文章数量:1125782
I'm working with NextJS 15 with App router on a monorepo powered by Turbo.
I'm generating a PDF with PDF-Lib but when I'm using drawText()
my PDF generation crash
Look my component:
export const CollaborationPdf = () => {
const [pdfBlobUrl, setPdfBlobUrl] = useState<string | null>(null);
const generatePdf = async () => {
try {
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage(PageSizes.A4);
page.drawCircle();
const { width, height } = page.getSize();
pdfDoc.addPage().drawText("Hello, World!", {
x: width / 2,
y: height / 2,
size: 30,
color: rgb(0, 0, 0),
});
const pdfBytes = await pdfDoc.save();
const blob = new Blob([pdfBytes], { type: "application/pdf" });
const blobUrl = URL.createObjectURL(blob);
setPdfBlobUrl(blobUrl);
} catch (error) {
console.error("Error generating PDF:", error);
}
};
return (
<div>
{!pdfBlobUrl && (
<Button variant="outline" size="sm" onClick={generatePdf}>
Generate PDF
</Button>
)}
{pdfBlobUrl && (
<Link href={pdfBlobUrl} target="_blank" rel="noopener noreferrer">
<Button variant="outline" size="sm">
View PDF
</Button>
</Link>
)}
</div>
);
};
If I use drawCircle()
for example, my PDF will be generated as normal
But when I use drawText()
it crashes
Someone have an idea ?
I'm trying to generate a PDF from scratch with PDF-Lib
版权声明:本文标题:typescript - Error generating PDF: invalid distance too far back when using drawText from pdf-lib - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736675121a1947141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论