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

fix(export): Adjust createPdf for the puppeteer^1.11.0 API. #294

Closed

Conversation

randytarampi
Copy link
Collaborator

The latest puppeteer seems to have broken PDF generation (with the page.goto workaround), at least locally for me both here in resume-cli and in @randy.tarampi/resume (which offers a similar PDFing functionality through @randy.tarampi/printables).

Per puppeteer/puppeteer#728 and https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetcontenthtml-options.

Also see the related change (including tests) at randytarampi/me@cb4dffb#diff-fbc2dab1d717f6eb0e4d2620c7fa7f03R21.

Per puppeteer/puppeteer#728 and https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetcontenthtml-options.

The latest `puppeteer` seems to have broken PDF generation (with the [`page.goto`](puppeteer/puppeteer#728 (comment)) workaround), at least locally for me both here in `resume-cli` and in [`jsonresume-theme-randytarampi`](https://www.npmjs.com/package/jsonresume-theme-randytarampi).
@randytarampi
Copy link
Collaborator Author

Perhaps @MarcLoupias could review this? Per @jphellemons' and @hannodrefke's issues in #291 (comment).

@jphellemons
Copy link

jphellemons commented Jan 3, 2019

It's no problem if I need to review it myself, however I could use some guidance.

found 17 vulnerabilities (7 low, 1 moderate, 8 high, 1 critical)

I just ran node ..\lib\export-resume\index.js -f pdf from the test dir which has a resume.json and I also tried node ..\lib\index.js export resume.pdf -f pdf but both "fail" because there is no pdf file generated and no error listed? What am I doing wrong?

Also ran mocha index.js in the test dir and got Error: ENOENT: no such file or directory, open '.env' Sorry but I am rather new to NodeJS development.

edit I have used npm link and tried to run resume export resume.pdf -f pdf -t flat again. I got a message that my resume.json was invalid (new schema?) and that callback is not a function? on line:
validate-schema.js:11:9

and if I force (-F) it:

resume-cli\node_modules\async\dist\async.js:966
if (fn === null) throw new Error("Callback was already called.");

@randytarampi
Copy link
Collaborator Author

Hm. Those steps look reasonable.

The following works for me though.

# Set things up
git clone git+ssh://github.com/randytarampi/resume-cli.git
cd resume-cli
git checkout puppeteer-v1.11.0
npm install

# Copy over your `resume.json` here...
# cp ../me/packages/jsonresume-theme/resume.json .

# Generate a `resume.pdf` using `jsonresume-theme-flat` 
./index.js export resume.pdf --force -f pdf --theme flat

# Generate a PDF using a custom theme, like `jsonresume-theme-elegant`
npm install jsonresume-theme-elegant
./index.js export resume.pdf --force -f pdf --theme elegant

@jphellemons
Copy link

I have added console.log('started'); on the top of index.js which does output to the console, but somehow there is no pdf generated. I also do not have node in my path so I ran: node ./index.js export resume.pdf --force -f pdf --theme elegant I am in the puppeteer-v1.11.0 branch.

@randytarampi
Copy link
Collaborator Author

Are you running the commands from the resume-cli root directory? That's what my instructions assume. Weird things happen when you try to use the wrong index.js as it seemed you were in your first comment.

What's your system environment like? It works fine for me on OSX, and on my Trusty Travis boxes.

What version of node are you running? This project requires node^8.

Can you try reinstalling your node_modules? Or otherwise verify that you actually do have [email protected] installed?

cd resume-cli
git checkout puppeteer-v1.11.0

# Also remember to blow away the `package-lock`
rm -rf node_modules package-lock.json

npm install

# Sanity check that we actually have the right `puppeteer`
cat node_modules/puppeteer/package.json # Check the `version` value.

node ./index.js export resume.pdf --force -f pdf --theme flat

I really don't know how else to troubleshoot this one. puppeteer might be silently failing.

I would add some logging here since it looks like we're just swallowing the err and not actually outputting it.

@jphellemons
Copy link

jphellemons commented Jan 4, 2019

I have 8 in my .nvmrc but have a newer version installed. I also updated some npm packages to try and reduce the vulnerabilities.
So I keep getting:

resume-cli\node_modules\async\dist\async.js:966
if (fn === null) throw new Error("Callback was already called.");
on lib\pre-flow\get-resume.js:29:9 when starting it with node ./index.js export resume.pdf --force -f pdf --theme flat
Here is a part of my package.json:

"dependencies": {
    "async": "^2.6.1",
    "chalk": "^2.4.1",
    "char-spinner": "^1.0.1",
    "cli-spinner": "^0.2.1",
    "colors": "^1.1.2",
    "commander": "^2.9.0",
    "dotenv": "^6.2.0",
    "eslint": "^5.11.1",
    "jsonlint": "^1.6.2",
    "jsonresume-theme-crisp": "^0.2.12",
    "jsonresume-theme-elegant": "^1.12.1",
    "jsonresume-theme-flat": "^0.3.7",
    "jsonresume-theme-modern": "0.0.18",
    "node-static": "~0.7.7",
    "opn": "5.4.0",
    "puppeteer": "^1.11.0",
    "read": "~1.0.7",
    "resume-schema": "latest",
    "resume-to-html": "latest",
    "resume-to-text": "latest",
    "should": "^13.2.3",
    "superagent": "^4.1.0",
    "terminal-menu": "^2.1.1"
  },

edit I "fixed" the callback message in the get-resume.js by replacing line 29 with console.log(error); But then got a Callback must be a function at lib\pre-flow\check-pkg-version.js:31:6)

@vanhoutenbos
Copy link

Installed this using npm link from the pull-requested version.
After this I ran resume export test.pdf and it created the pdf, unfortunatly with the 'default' template.

@randytarampi
Copy link
Collaborator Author

@jphellemons can you revert to using the original (and insecure) dependencies?

Looks like you've upgraded async, dotenv, should and superagent a major version, which is probably causing the breakages you're seeing. At least with async.

I wouldn't worry too much about those insecure dependencies really – if you really wanted to, I'd just upgrade mocha to knock off the risk of command injection, but it looks like most of these insecurities come from dependencies of dependencies.

@aslafy-z
Copy link

aslafy-z commented Apr 4, 2019

Any chance this gets merged anytime soon? We'd love to see a new release that includes this fix and would make the project usable! Thanks!

@codeocelot
Copy link
Contributor

Hi all,

I looked into the situation and noticed that the data url was unencoded. This generally poses a problem for html content. See #333 for a fix that does not require any bump in puppeteer.

marcpicaud
marcpicaud approved these changes Aug 1, 2019
@randytarampi
Copy link
Collaborator Author

Closed 'cause #333 is the actual solution here.

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

Successfully merging this pull request may close these issues.

6 participants