-
I am trying to create a custom PDF viewer with react-pdf v6.2.0 to load in PDFs that I get from an API that are stored as base64 strings. The following is the code I currently have: import React, { useState } from "react";
import { Document, Page } from "react-pdf/dist/esm/entry.webpack";
export function PDFViewer({ pdfFile }) {
const [numPages, setNumPages] = useState(null);
const [pageNumber, setPageNumber] = useState(1);
return (
<>
<Document
file={`data:application/pdf;base64,${pdfFile}`}
onLoadSuccess={({ numPages }) => {
console.log(`PDF File drawingId: ${pdfFile.DrawingId}`);
setNumPages(numPages);
setPageNumber(1);
alert("PDF document loaded successfully!");
}}
onLoadProgress={({ loaded, total }) =>
alert("Loading a document: " + (loaded / total) * 100 + "%")
}
onLoadError={(error) =>
alert("Error while loading document! " + error.message)
}
onSourceSuccess={() => alert("Document source retrieved!")}
onSourceError={(error) =>
alert("Error while retrieving document source! " + error.message)
}
>
<Page pageNumber={pageNumber || 1} />
</Document>
</>
);
} When I run the code, I get "Document source retrieved!" twice, followed by "Error while loading document! Worker was destroyed", followed by "Loading a document: 100%", and finally "PDF document loaded successfully" even though nothing is shown or the a PDF page is shown. Thee issue is that for some PDFs nothing is displayed and for all PDFs, regardless of if there is a page displayed, I get the "Worker was destroyed" error and the "Document source retrieved" message twice. Do you have any ideas what the issue is and what can be done to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Getting same error |
Beta Was this translation helpful? Give feedback.
In 597bec1, I got to the root of it and finally fixed the issue. Will be available in the incoming release (probably 7.0.2).