Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Error: PDF creation timeout. PDF generation script did not end.] #5

Closed
mpkorstanje opened this issue Nov 24, 2014 · 31 comments
Closed

Comments

@mpkorstanje
Copy link

On Windows 7 when trying to convert a .html to .pdf I get this message: [Error: PDF creation timeout. PDF generation script did not end.]. and no .pdf.

Script

var fs = require('fs');
var pdf = require('html-pdf');
var html = fs.readFileSync('LICENSE.md.html', 'utf8')
pdf.create(html, { width: '50mm', height: '90mm'}, function(err, buffer) {
  if (err) return console.log(err);
  fs.writeFile('LICENSE.md.html.pdf', buffer);
});

LICENSE.md.html

<p>Copyright (c) 2014 GitHub Inc.</p>

Note: Originally discovered the issue in the markdown-pdf module for Atom.

@marcbachmann
Copy link
Owner

Sorry, for the bug. The default timeout is currently 10 seconds, which is a bit low for some computers.
On what hardware are you working? Anyways, I'll change the default to 30s.

Also I should document the options a bit better (or make a better api of the module).
The markdown-pdf module just uses the defaults, which writes a file in phantom to a tmp directory and reads that file back to a buffer in node.
It's faster to pass { width: "210mm", height: "297mm", border: "10mm", filename: /path} as option which will save the file directly at the desired destination.

So can you try to use.

pdf.create(inputHtml, {file: outputPath, width: '210mm', height: '297mm', border: '10mm', timeout: 30000}, function(err, buffer) {
  if (err) return console.log(err);
  console.log("Converted successfully. Output in " + outputPath);
});

@mpkorstanje
Copy link
Author

I'm still getting the timeout. Both at 30 and 90 seconds.

I'm working on a:
HP Z420 Workstation
Intel(R) Xeon(R) CPU E5-1620 v2 @3.70Ghz 64-Bit
20 GB Ram

Can't imagine the machine is the problem. ;)

@mpkorstanje
Copy link
Author

Still timing out at 10 minutes. I can't imagine the converting a single line of html is gonna take that much time.

@marcbachmann
Copy link
Owner

Hehe, absolutely not.
I use phantoms' system.stdin method to pass the html from the node process.
Apparently that's the problem on windows.
Because phantomjs itself is synchronous there's no other event and the script fails with a timeout.

As an alternative I can write the html to file and read that file in phantomjs.
Or pass the html differently to phantomjs. But I'll have to elaborate that.
So there's no windows support for now :(
I'm sorry

@mpkorstanje
Copy link
Author

Alright. Thanks for looking into it!

@marcbachmann
Copy link
Owner

Hmm. It should work: https://groups.google.com/d/msg/phantomjs/GbndcSYaBWc/AznZfhT03zYJ
I have to investigate into this. But sadly I don't have a windows system.

@mpkorstanje
Copy link
Author

How can I execute the pdf_as_a4_portrait.coffee?

Doing it with Phantomjs.exe gets me a SyntaxError: Parse error.

@mpkorstanje
Copy link
Author

Okay that was case of PBKAC. Using Phantomjs.exe I can produce a pdf with pdf_as_a4_portrait.coffee.

So the problem is somewhere between node and phantom.js.

@marcbachmann
Copy link
Owner

Sorry for the late reply.
To create a pdf the command on unix is:

echo '<html></html>' | phantomjs pdf_as_a4_portrait.coffee HTMLBUFFERSIZE '{"width":"210mm", "height": "297mm"}' 

@marcbachmann
Copy link
Owner

@mpkorstanje I've updated some parts of the script. I'm passing the html differently to the process. So it's possible that it works now on windows.
Can you check out the windows-support branch?

edit:
I guess you still have to pass the destination file name directly as option. Otherwise a wrong tmp path is generated which is not working on windows.

@mpkorstanje
Copy link
Author

I'll try and have a look at that tonight.

@mpkorstanje
Copy link
Author

Okay. Running pdf_as_a4_portrait.coffee creates an empty pdf. But that might be because I can't figure out pipes on windows.

How do I package this and install it in node?

@marcbachmann
Copy link
Owner

Try to execute the tests. Are those working in the windows-support branch?
Just run npm test

@mpkorstanje
Copy link
Author

They time out sadly.

> html-pdf@0.2.1 test C:\Users\mpkorstanje\workspace\node-html-pdf
> grunt test

Running "mochaTest:test" (mochaTest) task


  html-pdf
    #create()
      V throws error when passing null (1ms)
      V throws error when passing undefined
      V throws error when passing empty string (1ms)
      1) does not throw an error when succeeding
      2) returns a buffer
      3) returns a pdf buffer
      4) works with a custom page size and footer
      5) works with custom html and css


  3 passing (6s)
  5 failing

  1) html-pdf #create() does not throw an error when succeeding:
     Error: timeout of 2000ms exceeded
    at [object Object].<anonymous> (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runnable.js:158:19)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)


  2) html-pdf #create() returns a buffer:

      Should be a buffer
      + expected - actual

      +true
      -false

    at Context.<anonymous> (C:\Users\mpkorstanje\workspace\node-html-pdf\test\create.coffee:48:28)
    at callFn (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runnable.js:250:21)
    at Test.Runnable.run (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runnable.js:243:7)
    at Runner.runTest (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:373:10)
    at C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:451:12
    at next (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:298:14)
    at C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:308:7
    at next (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:246:23)
    at Object._onImmediate (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:275:5)
    at processImmediate [as _immediateCallback] (timers.js:345:15)


  3) html-pdf #create() returns a pdf buffer:
     TypeError: Cannot call method 'toString' of undefined
    at Context.<anonymous> (C:\Users\mpkorstanje\workspace\node-html-pdf\test\create.coffee:52:32)
    at callFn (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runnable.js:250:21)
    at Test.Runnable.run (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runnable.js:243:7)
    at Runner.runTest (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:373:10)
    at C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:451:12
    at next (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:298:14)
    at C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:308:7
    at next (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:246:23)
    at Object._onImmediate (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runner.js:275:5)
    at processImmediate [as _immediateCallback] (timers.js:345:15)


  4) html-pdf #create() works with a custom page size and footer:
     Error: timeout of 2000ms exceeded
    at [object Object].<anonymous> (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runnable.js:158:19)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)


  5) html-pdf #create() works with custom html and css:
     Error: timeout of 2000ms exceeded
    at [object Object].<anonymous> (C:\Users\mpkorstanje\workspace\node-html-pdf\node_modules\mocha\lib\runnable.js:158:19)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)




Warning: Task "mochaTest:test" failed. Use --force to continue.

Aborted due to warnings.
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

@marcbachmann
Copy link
Owner

I believe you're doing the tests on the master branch.
I've increased the test timeout to 10 seconds on windows-support
So please execute that:

git checkout windows-support
npm install
npm test

Anyways. Thanks for your patience.

@mpkorstanje
Copy link
Author

You were correct. Checked out the wrong branch.

Test passed. I've got pdfs for the test files. It works now. Cheers!

 html-pdf
   #create()
     V throws error when passing null (1ms)
     V throws error when passing undefined
     V throws error when passing empty string
     V does not throw an error when succeeding (679ms)
     V buffer must be returned when no filename specified (641ms)
     V returns a pdf buffer (613ms)
     V saves the pdf to a destination (648ms)
     V works with a custom page size and footer (720ms)
     V works with custom html and css (749ms)

@marcbachmann
Copy link
Owner

Nice. So I'll merge this & it will land in the markdown-pdf module after they incorporate it.

@mpkorstanje
Copy link
Author

Awesome! Will you poke the issue at markdown-pdf when you merge your fixes?

@travs
Copy link

travs commented Dec 9, 2014

cc: @harshbhatt @marcbachmann
This issue is rearing its head again. Do you have any idea what could be going on?

markdown-pdf is requiring 0.3.0; I believe this is the correct version.

Let me know if there's anything I can help with!

@marcbachmann
Copy link
Owner

Is this still an issue? Please try to run those phantomjs tests: https://github.com/Medium/phantomjs
I currently can't test the script on windows. If the problem still exists, please create a new issue.

@harshbhatt
Copy link

The scripts here? Can you help me out in doing so - still new to using npm and nodejs - would apprecaite it.

@marcbachmann
Copy link
Owner

@harshbhatt here you go

git clone git@github.com:Medium/phantomjs.git
cd phantomjs
NODE_ENV=development npm install
npm test

@harshbhatt
Copy link

Thanks @marcbachmann, appreciate it.

After cloning the repo, I ran set NODE_ENV=development and ran npm test after that. Here is what I got:

screenshot 2014-12-17 23 23 54

@marcbachmann
Copy link
Owner

Apparently npm doesn't set the PATH variable on windows. So it can't execute nodeunit.
Is there a ./node_modules/.bin/nodeunit file?
Try to run that using .\node_modules\.bin\nodeunit test\tests.js

@marcbachmann
Copy link
Owner

Does anybody know a CI platform that supports Windows? 😄
edit: oh, there is one: http://www.appveyor.com/pricing

@marcbachmann
Copy link
Owner

@harshbhatt did you execute npm install?

@harshbhatt
Copy link

@marcbachmann I did, but nothing happened.

I did set nodejs as a PATH variable so after some digging, ran npm install nodeunit -g and tried npm test again, then had to run npm install which after which I finally got:

screenshot 2014-12-17 23 58 11

Sorry about the noob-ness here - not familiar with nodejs as you can probably tell 😄

@marcbachmann
Copy link
Owner

You still need to execute npm install. During npm install, it downloads phantomjs which is needed for the tests. That's why it fails.

@marcbachmann
Copy link
Owner

I just tested the module on Windows 8.1. There are no dependencies like on linux.

@harshbhatt
Copy link

I'm not sure I follow. As far as I understood, I had npm installed and I installed phantomjs using npm install phantomjs found here.

@MisterNice
Copy link

I'm sporadically receiving this error, which appears related to this thread:
[Error: html-pdf: PDF generation timeout. Phantom.js script did not exit.]
It worked just fine yesterday, not working today with no change in that part of my code. I'm on version 1.5.0

var html = ejs.renderFile(appRoot + '/path/to/file', {
var: var
}, function (err, result) {
if (result) {
html = result
console.log(html)
var options = {format: 'Letter'}
var filename = bcrypt.hashSync(jobInfo[0].customer)
pdf.create(html, options).toFile(appRoot + '/public/uploads/invoices/WO-' + opID + "-" + filename + '.pdf', function(err, res){
do some other stuff
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants