pdf-lib
pdf-lib copied to clipboard
Some pdf file can't be preview
What were you trying to do?
Preview a pdf file and add watermark
How did you attempt to do it?
<html>
<head>
<meta charset="utf-8" />
<script src="https://unpkg.com/pdf-lib"></script>
</head>
<body>
<iframe id="pdf" style="width: 100%; height: 100%;" type="application/pdf"></iframe>
</body>
<script>
createPdf();
async function createPdf() {
const existingPdfBytes = await fetch('./test.pdf').then((res) => res.arrayBuffer());
const pdfDoc = await PDFLib.PDFDocument.load(existingPdfBytes);
const pdfDataUri = await pdfDoc.saveAsBase64({ dataUri: true });
document.getElementById('pdf').src = pdfDataUri;
}
</script>
</html>
What actually happened?
Nothing render, and no error in devtools console.
What did you expect to happen?
Render the pdf file
How can we reproduce the issue?
run the index.html
in http-server.
Version
1.17.1
What environment are you running pdf-lib in?
Browser
Checklist
- [X] My report includes a Short, Self Contained, Correct (Compilable) Example.
- [X] I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
test.pdf
Same issue