React-pdf: Failed to load PDF file from URL

Created on 5 Feb 2019  路  8Comments  路  Source: wojtekmaj/react-pdf

Before you start - checklist

  • [X] I have read documentation in README
  • [X] I have checked sample and test suites to see real life basic implementation
  • [X] I have checked if this question is not already asked

What are you trying to achieve? Please describe.
Unable to render pdf (url)

Describe what are you trying to achieve Ex. I'd like to display multiple pages of my PDF.
I'm trying to render pdf from url , but I get the following error in the browser

failed to load pdf file
pages of

Describe solutions you've tried
SamplePdf.jsx

 import React, {Component} from "react";
   import {Document, Page} from 'react-pdf';

class Sample extends Component {
    constructor(props) {
        super(props);
        this.state = {
            numPages: null,
            pageNumber: 1
        };
    }
 onDocumentLoad({numPages}) {
        this.setState({numPages});
    }
render() {
const {pageNumber, numPages} = this.setState;
        return (
            <div>
                <Document
                    file={{url: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'}}
                    onLoadSuccess={this.onDocumentLoad}>
                    <Page pageNumber={pageNumber}/>
                </Document>
                <p>Page {pageNumber} of {numPages}</p>
            </div>
        );
    }
}

export default Sample; 

index.jsx

import React from 'react';
import { storiesOf } from '@storybook/react';
import Sample from '../Sample';

const storyPath = 'TrialComponents/reactpdf';

storiesOf(storyPath, module)
  .add('Static', () => <Sample />);

Additional information

Environment

  • Browser (if applicable) [e.g. Chrome 57, Firefox 59]:
  • React-PDF version [e.g. 3.0.4]:
  • React version [e.g. 16.3.0]:
  • Webpack version (if applicable) [e.g. 4.16.2]:
duplicate question

Most helpful comment

OK, so duplicate. Where is the answered or original?

All 8 comments

Sorry this is a duplicate issue. Closing it. Thanks

OK, so duplicate. Where is the answered or original?

I am also facing same problem... where is the original post?

This issue is not described well enough for me to point out a specific issue to seek help. I suggest either creating a new ticket describing exactly what happens, or seek for the issue on your own.

when I try to load file from a URL (external pdf url like for eg. : http://www.pdf995.com/samples/pdf.pdf )
error "Failed to load PDF file". PDF is not rendered as expected.

syntax
file={{
url: 'http://example.com/sample.pdf',
httpHeaders: { 'X-CustomHeader': '40359820958024350238508234' },
withCredentials: true
}
}
// onLoadSuccess={this.onDocumentLoadSuccess}
/>

Anyone found a solution?

Anyone found solution ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webguru103 picture webguru103  路  3Comments

herneli picture herneli  路  3Comments

wojtekmaj picture wojtekmaj  路  4Comments

nnnikolay picture nnnikolay  路  4Comments

shivekkhurana picture shivekkhurana  路  4Comments