pofider / phantom-html-to-pdf

Highly scalable html to pdf conversion using phantom workers
MIT License
159 stars 33 forks source link

Feature request: conversion.waitFor #12

Closed PaddyMann closed 9 years ago

PaddyMann commented 9 years ago

Thanks for both the tool and answering earlier issues today!

I have a webpage that downloads a set of files and then runs a script to translate the content to the right language. This works great, unless the PDF is generated before the content has been translated.

conversion.printDelay is useful, but isn't reliable enough.

Instead, I want to run a custom JS test to check whether or not the page has actually been loaded. If it hasn't, then I'd wait 100ms and try again. This polling technique is common with Selenium-based testing frameworks (e.g. Protractor).

I'm going to be looking into this tomorrow, so any guidance on how to implement this with (or as an extension/pull-request for) phantom-html-to-pdf would be very welcome :)

pofider commented 9 years ago

Yes, this feature is missing. We are having plans to implement it in the short time frame, however we didn't discuss the implementation details yet.

Feel free to fork and try to add some evaluations you need before printing. https://github.com/pofider/phantom-html-to-pdf/blob/master/lib/scripts/conversionScriptPart.js#L79

PaddyMann commented 9 years ago

I have working support for this when just running a single phantom server: https://github.com/pofider/phantom-html-to-pdf/pull/14

I've not updated conversionScriptPart.js (when is this used?) or standaloneScript.js (currently unclear on best way to return an error). It feels like the 3 files should be refactored and DRYed up...

Any tips for how to return an error in standaloneScript.js ?

bjrmatos commented 9 years ago

conversionScriptPart.js (and serverScriptPart.js, standaloneScriptPart.js) are used in prepareScripts.js which is executed in npm postinstall hook.

don't need to return an error in standaloneScriptPart.js (well, if you really need that just throw new Error()) because this file will be running inside a child process, if it has an error it will reported in the callback of childProcess.execFile

bjrmatos commented 9 years ago

@PaddyMann the feature is complete :smile:

PaddyMann commented 9 years ago

Had a quick play and it works great - thank you kindly sir :)