React-pdf: TypeError: Cannot set property 'workerSrc' of undefined

Created on 2 Dec 2018  路  7Comments  路  Source: wojtekmaj/react-pdf

Before you start - checklist

  • [x] I have read documentation in README
  • [ ] 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.

Describe what are you trying to achieve Ex. I'd like to display multiple pages of my PDF.

Describe solutions you've tried

Describe solutions you've already tried, if any. Make sure to include code samples if you're stuck on implementation.

Additional information

If applicable, add screenshots (preferably with browser console open) and files you have an issue with to help explain your problem.

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]:
invalid question

Most helpful comment

It is ugly solution but I resolved like below.

import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
import { Document, Page, pdfjs } from 'react-pdf'
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`

All 7 comments

image

It is ugly solution but I resolved like below.

import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
import { Document, Page, pdfjs } from 'react-pdf'
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`

npm install --save-dev pdfjs-dist

and

pdfjs.GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker.js';

or
https://github.com/mozilla/pdf.js/issues/8305

Thank You So Much for solution. Its working now.

Can't help you since you completely ignored the form I created to help you describe the issue.

Also resolved in #291

I was having the same issues and following the suggestions in this issue im receiving a: InvalidPDFException聽{name: "InvalidPDFException", message: "Invalid PDF structure"} - error now.
If i use a url im getting a Cors issue.
Any suggestions? Im really struggeling to get this work in my React app (CRA, TypeScript)

@jp3492, this issue was exclusive to React-PDF 3.x. Try 4.x.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nnnikolay picture nnnikolay  路  4Comments

shivekkhurana picture shivekkhurana  路  4Comments

herneli picture herneli  路  3Comments

zambony picture zambony  路  3Comments

GManzato picture GManzato  路  4Comments