Invalid PDF Structure for latest version of PDF.js in Chrome
See original GitHub issueI’m using the test PDF, shown here, which I have saved locally.
I’m using pdfjs-dist, and the pdf.js version 1.8.172 (or higher).
Configuration:
- Browser: Chrome 56, I’ve also tried on FireFox 52 and the same error happens.
- OS version: OSX 10.12.1
- PDF.js version: 1.8.172
Steps to reproduce the problem:
const url = "http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf";
// other code involved with React
componentDidMount() {
window.PDFJS
.getDocument('../pdf/compressed.tracemonkey-pldi-09.pdf')
.then((pdf) => {
this.renderPdf(pdf);
})
.catch((e) => {
console.log(e);
});
}
renderPdf(pdf) {
const container = document.getElementById("pageContainer");
for (let i = 1; i <= pdf.numPages; i++) {
// Get desired page
pdf.getPage(i).then(function(page) {
const scale = 1.5;
const viewport = page.getViewport(scale);
const div = document.createElement("div");
// Set id attribute with page-#{pdf_page_number} format
div.setAttribute("id", "page-" + (page.pageIndex + 1));
// This will keep positions of child elements as per our needs
div.setAttribute("style", "position: relative");
// Append div within div#container
container.appendChild(div);
// Create a new Canvas element
const canvas = document.createElement("canvas");
// Append Canvas within div#page-#{pdf_page_number}
div.appendChild(canvas);
const context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
const renderContext = {
canvasContext: context,
viewport: viewport
};
// Render PDF page
page.render(renderContext);
});
}
What is the expected behavior? The PDF loads
What went wrong? I get a InvalidPDFStructure error.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
PDF.js v1.8.557 (build: 4a74cc41) Messaggio - Google Support
PDF.js v1.8.557 (build: 4a74cc41) Messaggio: Invalid PDF structure. I can't open PDF files.
Read more >Invalid PDF Structure - PDF Plugins For WordPress
If you see 'Invalid PDF Structure' where you expected the PDF to display, this may be due to server configuration problems. Either the...
Read more >How to fix Google Chrome pdf file opening error 'PDF JS Click ...
How to fix Google Chrome pdf file not opening. error message ' PDF JS Click on "Allow access o file URLs" at Chrome...
Read more >Error = Invalid PDF structure, while viewing and downloading ...
I'd like to test and see if you can at least download the PDF files to view them. Open the main menu, navigate...
Read more >PDF.js v1.1.366 (build: 9e9df56) Bericht: Invalid PDF structure
js v1.1.366 (build: 9e9df56) Bericht: Invalid PDF structure This is the error code. Opening with any other PDF viewer is still possible and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same problem here - could use an inch?
hum, just tried again and it works… It was because I was loading the wrong file as worker with webpack
CopyWebpackPlugin
. Fixed now. This wrong worker was throwing the same issue as @prakashsanker