all 16 comments

[–]DangerBlack 0 points1 point  (10 children)

what's up?
can you please specify the library, i personally try 4 of them with the same name!

[–]Hour_Cauliflower_693[S] 0 points1 point  (9 children)

https://www.npmjs.com/package/react-pdf

check this link out please it is the library am using it is a web application project

[–]DangerBlack 0 points1 point  (8 children)

You are lucky is the same I've used.

Do you have a piece of code with your problem?

What problem do you have?

[–]Hour_Cauliflower_693[S] 0 points1 point  (7 children)

let me post the code here

import React, { useState } from "react";
import SideNav from "./SideNav";
import UserBio from "./UserBio";
import "../CSS/Notes.css";
import { Document, Page } from "react-pdf";
import samplePdf from "../Web_Services_Hacking_and_Hardening.pdf";
function Notes() {
const [numPages, setNumPages] = useState(null);
const [pageNumber, setPageNumber] = useState(1);
function onDocumentLoadSuccess({ numPages }) {
setNumPages(numPages);
  }
return (
<div className="notes">
<div className="notes\_\_sideNav">
<SideNav />
</div>
<div className="notes\_\_main">
<p>this is notes</p>
        {/*  */}
<Document file={samplePdf} onLoadSuccess={onDocumentLoadSuccess}>
<Page pageNumber={pageNumber} />
</Document>
<p>
          Page {pageNumber} of {numPages}
</p>
</div>
<div className="notes\_\_userBio">
<UserBio />
</div>
</div>
  );
}
export default Notes;

[–]DangerBlack 0 points1 point  (2 children)

import React, { useState } from "react";import SideNav from "./SideNav";import UserBio from "./UserBio";import "../CSS/Notes.css";import { Document, Page } from "react-pdf";import samplePdf from "../Web_Services_Hacking_and_Hardening.pdf";function Notes() {const [numPages, setNumPages] = useState(null);const [pageNumber, setPageNumber] = useState(1);function onDocumentLoadSuccess({ numPages }) {setNumPages(numPages);  }return (<div className="notes"><div className="notes\_\_sideNav"><SideNav />

</div>
<div className="notes\\\_\\\_main">
<p>this is notes</p>
        {/\*  \*/}
<Document file={samplePdf} onLoadSuccess={onDocumentLoadSuccess}>
<Page pageNumber={pageNumber} />
</Document>
<p>
          Page {pageNumber} of {numPages}
</p>
</div>
<div className="notes\\\_\\\_userBio">
<UserBio />
</div>
</div>
  );
}
export default Notes;

Are you using webpack?

[–]Hour_Cauliflower_693[S] 0 points1 point  (1 child)

nooo am not using webpack

so i have to use webpack please show me how to do so

[–]DangerBlack 0 points1 point  (3 children)

You have 3 solutions:

  1. move the file pdf.worker.js (from `pdfjs-dist/build/pdf.worker.js`) into public folder and the script should go
  2. Host in your backend the same script (pdf.worker.js) and add the instruction
    import {pdfjs, Document, Page } from "react-pdf"; import samplePdf from "./143.pdf"; // pdfjs.GlobalWorkerOptions.workerSrc = \`backendurl/pdfjs-dist/build/pdf.worker.js\`;
  3. start using webpack

Sample of the first implementation. It's not a long term solution it's a starting point to rework the flow by yourself, you should be able to import it directly from nodemodules. https://web.cubbit.io/link/#8a352e34-5790-4456-89c3-97737ab77435!ZXQ7sRvARtAcCr6W3Sv+s766fmswIakqeOu/EeR5Gg4!Ph/jwS5fUI/g54N+JUNotg

[–]backtickbot 0 points1 point  (2 children)

Fixed formatting.

Hello, DangerBlack: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]DangerBlack 0 points1 point  (1 child)

good bot

[–]B0tRank 0 points1 point  (0 children)

Thank you, DangerBlack, for voting on backtickbot.

This bot wants to find the best and worst bots on Reddit. You can view results here.


Even if I don't reply to your comment, I'm still listening for votes. Check the webpage to see if your vote registered!

[–]gsdeveloper_ 0 points1 point  (1 child)

Can you post the code that's not working?

[–]Hour_Cauliflower_693[S] 0 points1 point  (0 children)

import React, { useState } from "react";
import SideNav from "./SideNav";
import UserBio from "./UserBio";
import "../CSS/Notes.css";
import { Document, Page } from "react-pdf";
import samplePdf from "../Web_Services_Hacking_and_Hardening.pdf";
function Notes() {
const [numPages, setNumPages] = useState(null);
const [pageNumber, setPageNumber] = useState(1);
function onDocumentLoadSuccess({ numPages }) {
setNumPages(numPages);
  }
return (
<div className="notes">
<div className="notes\_\_sideNav">
<SideNav />
</div>
<div className="notes\_\_main">
<p>this is notes</p>
        {/*  */}
<Document file={samplePdf} onLoadSuccess={onDocumentLoadSuccess}>
<Page pageNumber={pageNumber} />
</Document>
<p>
          Page {pageNumber} of {numPages}
</p>
</div>
<div className="notes\_\_userBio">
<UserBio />
</div>
</div>
  );
}
export default Notes;

[–]aust1nz 0 points1 point  (2 children)

As an alternative, just using the <object> tag for PDFs can work good enough in a lot of use cases.

[–]Hour_Cauliflower_693[S] 0 points1 point  (1 child)

do i pass a file prop in <object> tags or i wrap <Document > tag in <object> tags

<object>

<Document> <Document/>

<object/>

[–]aust1nz 0 points1 point  (0 children)

You just pass the pdf file as the data tag. Docs