pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

Some pdf file can't be preview

Open doornot opened this issue 1 year ago • 1 comments

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.

截屏2023-03-10 16 15 13

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

test.pdf

doornot avatar Mar 10 '23 08:03 doornot

Same issue

GusMartins499 avatar Jan 16 '24 19:01 GusMartins499