You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
I'm trying to add image and text in the pdf with large width and height
pdf width: 2383.91992
pdf height: 1690.56006
Why were you trying to do this?
It's a requirement
How did you attempt to do it?
Just the same code that works with the pdf normal size like a4 but if I use a scanned pdf with
pdf width: 2383.91992
pdf height: 1690.56006
The drawText and drawImage is not working. I can't found the text and the signature
What actually happened?
Just the same code that works with the pdf normal size like a4 but if I use a scanned pdf with
pdf width: 2383.91992
pdf height: 1690.56006
The drawText and drawImage is not working. I can't found the text and the signature
What did you expect to happen?
To see the text in the document
How can we reproduce the issue?
<meta charset="utf-8" />
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]"></script>
</head>
<p>Click the button to modify an existing PDF document with <code>pdf-lib</code></p>
<button onclick="modifyPdf()">Modify PDF</button>
<p class="small">(Your browser will download the resulting file)</p>
</body>
<script>
const { degrees, PDFDocument, rgb, StandardFonts } = PDFLib
async function modifyPdf() {
// Fetch an existing PDF document pdf width: 2383.91992 pdf height: 1690.56006
const url = 'https://store2.gofile.io/download/27ab4ce7-0ea4-4e52-9edd-ef37fa9d6fa6/Grundrisse%2018%20(4).pdf'
const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer())
// Load a PDFDocument from the existing PDF bytes
const pdfDoc = await PDFDocument.load(existingPdfBytes)
// Embed the Helvetica font
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
// Get the first page of the document
const pages = pdfDoc.getPages()
const firstPage = pages[0]
// Get the width and height of the first page
const { width, height } = firstPage.getSize()
// Draw a string of text diagonally across the first page
firstPage.drawText('This text was added with JavaScript!', {
x: 5,
y: height / 2 + 300,
size: 50,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(-45),
// Serialize the PDFDocument to bytes (a Uint8Array)
const pdfBytes = await pdfDoc.save()
// Trigger the browser to download the PDF document
download(pdfBytes, "pdf-lib_modification_example.pdf", "application/pdf");
</script>
</html>
@ezalorsara
I tried executing the HTML you provided as well as running the JSFiddle, but both examples fail with a 404 when trying to fetch the PDF document:
If you're still having trouble, please provide a working SSCCE and I'll take a look.