Szpadel / chrome-headless-render-pdf

223 stars 67 forks source link

What format do I use for parameters to pass to generateMultiplePdf? #12

Closed gate5th closed 7 years ago

gate5th commented 7 years ago

Hi, I expect this is me just not getting some ES6 thing, but I'm trying to generate multiple pdfs from several local files and getting an error: Error: Invalid parameters (url: string value expected)

I'm confused because in the instructions it shows a format that I don't recognize. It looks like an array of objects, but inside the curly brackets doesn't appear to be a valid object ({url, output} instead of {url: output}). I've tried several different ways to pass parameters but having no luck. Can you clarify what the function is looking for?

Thanks!

From the readme:

RenderPDF.generateMultiplePdf([
    {'http://google.com', 'outputPdf.pdf'},
    {'http://example.com', 'outputPdf2.pdf'}
]);

My Error logs:

multiplePdfObject after loop [ { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_acord126.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_acord126.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_acord140.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_acord140.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_acord130.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_acord130.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_acord131.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_acord131.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_acord125.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_acord125.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_MSSuppLiquor.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_MSSuppLiquor.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_MSEandO.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_MSEandO.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_MSSuppDandO.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_MSSuppDandO.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_MSAuto.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_MSAuto.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_MSCyber.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_MSCyber.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_MSEandOIndustrySuppTech.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_MSEandOIndustrySuppTech.pdf' },
  { 'file:\C:\modernsubmissions-redux\tmp\1504789339753_MSLossRunRequestLetter.html': 'file:\\C:\\modernsubmissions-redux\\tmp\\1504789339753_MSLossRunRequestLetter.pdf' } ]
(node:5108) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Invalid parameters (url: string value expected)
gate5th commented 7 years ago

Actually it looks like it was a Typescript thing. After console.logging my way through the node_module I determined that you can pass an array of object formatted as below to generateMultiplePdf:

[
{url:'first.html', pdf:'pdf1.pdf'},
{url:'second.html', pdf:'pdf2.pdf'}
]

Hope that's helpful to somebody else out there in internet-land.