question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught ReferenceError: PDFDocument is not defined

See original GitHub issue

So, thanks a lot for your lib.

I’m running into a weird issue.

No matter how I load pdfKit and blob-stream, I always end up with the same error.

If I do var doc = new PDFDocument();, I always have the same message :

Uncaught ReferenceError: PDFDocument is not defined

I tried to load the files directly in the browser, using sprokets ( may be the error ? )


With sprokets :

//= require pdfKit.js
//= require blob-stream.js

var doc = new PDFDocument();
var stream = doc.pipe(blobStream());

Result: error


By loading the files in the same order in script tags :

  <script src='pdfKit.js'></script>
  <script src='blob-stream.js'></script>
  <script src='all.js'></script>

And then in all.js :

var doc = new PDFDocument();
var stream = doc.pipe(blobStream());

Result: error

#help ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
julianklumperscommented, Jan 10, 2020

For people using webpack, you must bind PDFDocument and blobStream to the window object.

example:

import PDFDocument from 'pdfkit';
import blobStream from 'blob-stream';

...

window.PDFDocument = PDFDocument
window.blobStream = blobStream

Then in your html file

<script src="main.bundle.js"></script>
<script type="text/javascript" src="yourfile.js">
    const doc = new PDFDocument();
    ...
</script>
1reaction
gponnathcommented, Jan 6, 2017

Update: this is actually working for me after moving the scripts to the head rather than the footer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pdfkit Browser - "Uncaught ReferenceError: fs is not defined ...
So, first I downloaded a prebuilt version of pdfkit (which is assumed to work in browser) from here. Then I wrote this code...
Read more >
ReferenceError: document is not defined in JavaScript
The "ReferenceError: document is not defined" error is thrown when the code tries to access the document object, but the object is not ......
Read more >
I can't load PDF.js lib in Lightning Web Component
Failed to load script at /resource/1573759295000/pdfViewer/pdf.js: regeneratorRuntime is not defined [regeneratorRuntime is not defined].
Read more >
Uncaught ReferenceError: jsPDF is not defined - Code Grepper
uncaught referenceerror : jspdf is not defined · Oops, You will need to install Grepper and log-in to perform this action.
Read more >
How to generate a pdf file using javascript? - SAP Community
I tried jsPDF but getting some exceptions like Uncaught ReferenceError: pageWidth is not defined, fail to load pdf document Co.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found