Failed to load PDF file
See original GitHub issuei am having trouble showing pdf file tried every way from importing as file and directory giving path it is giving an error Failed to load PDF file. And When I am using webpack or parcel it just showing loading PDF.
Code
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import { Document, Page } from 'react-pdf'
import lesson2 from './lesson2.pdf'
class App extends Component {
state = { numPages: null, pageNumber: 1 };
onDocumentLoadSuccess = ({ numPages }) => {
this.setState({ numPages });
};
goToPrevPage = () =>
this.setState(state => ({ pageNumber: state.pageNumber - 1 }));
goToNextPage = () =>
this.setState(state => ({ pageNumber: state.pageNumber + 1 }));
render() {
const { pageNumber, numPages } = this.state;
return (
<div>
<nav>
<button onClick={this.goToPrevPage}>Prev</button>
<button onClick={this.goToNextPage}>Next</button>
</nav>
<div style={{ width: 600 }}>
<Document
file={lesson2}
onLoadSuccess={this.onDocumentLoadSuccess}
>
<Page pageNumber={pageNumber} width={600} />
</Document>
</div>
<p>
Page {pageNumber} of {numPages}
</p>
</div>
);
}
}
export default App;
Folder Structure
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:35 (10 by maintainers)
Top Results From Across the Web
8 Ways to Fix Failed to Load PDF Document Error
How do I fix a PDF failed to load? · 1. Download the latest Adobe Reader version · 2. Change PDF settings in...
Read more >How to Fix Error Failed to Load PDF Document in Chrome
How to Fix Error Failed to Load PDF Document Chrome · Fix 1: Update Google Chrome to the Latest Version · Fix 2:...
Read more >Fix: Error Failed to Load PDF Document in Chrome - Appuals
Visit this link (here) and click on Add to Chrome to install the PDF Viewer Extension. Then click Add Extension to confirm the...
Read more >Failed to load PDF document in Chrome - Stack Overflow
Opening Google Chrome (obviously) · In the top right, click More Untitled. · At the bottom, click Show Advanced Settings. · Under Privacy,...
Read more >How to Fix Failed to load PDF Document in Chrome Browser
Fix PDF File Opening or Crashing in Chrome Browser# PDFFile #ChromeBrowserFacebook Page : https://www.facebook.com/MeMJTubeFollow on twitter: ...
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
@saadpasta @MichaelBlanchet I reckon you are using create-react-app as a boilerplate ?
Add/change these to your code
as instructed on the main page of this project. Also make sure pdf file is to be found for your project (public directory)
I have a very similar (simple) App.js - as per your description - and not able to load a PDF document. Getting the following errors: