Home>
I want to display pdf from url using react-pdf
This sandboxIndex.jsx
I changed it a little, but
Failed to load PDF file.
And cannot be read
import React from "react";
import ReactDOM from "react-dom";
import {pdfjs, Document, Page} from "react-pdf";
import "./styles.css";
import samplePDF from "../sample.pdf";
pdfjs.GlobalWorkerOptions.workerSrc = `// cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;
function Test () {
return (
<Document
file = {
"https://helpx.adobe.com/jp/acrobat/kb/cq07071635/_jcr_content/main-pars/download-section/download-1/file.res/sample.pdf"
}
>
<Page pageNumber = {1} />
</Document>
);
}
ReactDOM.render (<Test />, document.getElementById ("app"));
What I tried
I changed the Document to the following, but it didn't work.
<Document
file = {{
url: "https://helpx.adobe.com/jp/acrobat/kb/cq07071635/_jcr_content/main-pars/download-section/download-1/file.res/sample.pdf"
}}
>
-
Answer # 1
Related articles
- javascript - i am using chart kick, but the display of "loading" remains and the graph is not displayed
- javascript - i want to display a drop-down menu using css and js in html
- javascript - display how many numbers are the same entered using if
- javascript - i want to switch the task display using the radio button
- javascript - i want to change the display by selecting the radio button
- python - how to display a list using curly braces
- python 3x - i want to display a japanese map using japanmap, but i can't no error
- javascript - i want to download a file in sjis format using js (jquery)
- javascript - about switching the display between desplay: none;and desplay: block;
- javascript - can you create a homepage using rails?
- css - i want to create a table using table and display multiple pieces of information in the same row
- javascript - i want to shift the display of the array
- i want to display characters in javascript p tag
- javascript - i want to display vertical navigation on both sides now
- html - i want to display the posted prototype using collection
- i want to make a 〇 × game (tic tac toe) with javascript i want to display 〇 × on the board
- javascript - i want to get the number corresponding to a character using an array
- javascript - i want to rewrite the inside of an element using the append method in jquery
- javascript - i want to display leaflet pins in a cluster
There is a possibility of a CORS error.
Roughly speaking, it is an error that resources can be shared by request only between the same domain, that is, the same service.
https://developer.mozilla.org/ja/docs/Web/HTTP/CORS/Errors
If you want to display the requested pdf on the server, you can set up the server yourself, place the pdf there, and allow the request from your application by setting Access-Control-Allow-Origin. I think.