pofider / phantom-html-to-pdf

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

Upgrade from 0.3.5 -> 0.4.1 breaks image rendering #29

Closed jperkelens closed 8 years ago

jperkelens commented 8 years ago

When we upgraded from 0.3.5 to 0.4.1, we are noticing that tags are failing to render properly.

We are using express 4 and an interesting quirk we noticed is that the pdf will render properly if we first pass the html fed to the phantom server in our express app. So, for example, in the code below, the image renders appropriately if we make a request to '/page' and then '/file' but not if we just call '/file'

var converter = require("phantom-html-to-pdf")()
app.get('/page', function(req, res, next) {
   var htmlForPdf = _.template(loadTemplate('pdf_report.html.erb'))()
   res.render('pdf', {pdf: htmlForPdf})
})

app.get('/file', function(req,res,next) {
   var htmlForPdf = _.template(loadTemplate('pdf_report.html.erb'))()
   converter({html: htmlForPdf}, function(err, file) {
     file.stream.pipe(res)
   })
}
pofider commented 8 years ago

Hi,

could you try to print phantomjs output somewhere

var conversion = require("phantom-html-to-pdf")();
conversion({ html: "<h1>Hello World</h1>" }, function(err, pdf) {
  //print phantomjs output
  console.log(pdf.logs);
  console.log(pdf.numberOfPages);
  pdf.stream.pipe(res);
});
romanmt commented 8 years ago

I added the above logging....

res.log was empty.

converter({html: html, paperSize: { orientation: 'landscape' }}, (err, pdf) => {
  log.debug({logs: pdf.logs}, "pdf logs");
  log.debug({pages: pdf.numberOfPages}, "pdf number of pages");
  pdf.stream.pipe(res);
})
[2016-05-05T15:02:41.038Z] DEBUG: okdj-app/70305 on stravinsky.local: pdf logs (logtype=services)
[2016-05-05T15:02:41.039Z] DEBUG: okdj-app/70305 on stravinsky.local: pdf number of pages (logtype=services, pages=1)
pofider commented 8 years ago

That is strange. The pdf.logs should be an array with at least 1 item. I double checked it and it is like that. I was using console.log..

Can you share your html?

demsey2 commented 8 years ago

We experienced a similar issue. Could you provide any update on that?

pofider commented 8 years ago

@demsey2 Can you share the html on which it is breaking? We are using this component very heavily in jsreport without experiencing it.

Did you try using the latest release 0.4.2?

demsey2 commented 8 years ago

@pofider we use Flatdoc to generate html on fly from makrdown files, from time to time our doc file doesn't contain any images, I am going to try 0.4.2 and let you know

pofider commented 8 years ago

@demsey2 Maybe you can also try to increase resourceTimeout https://github.com/pofider/phantom-html-to-pdf/issues/7#issuecomment-154761297

pofider commented 8 years ago

Closing due to inactivity. There was a very low resource loading timeout (1000ms) in one of the release which could cause missing images. This should be increased now. If you have further problem with images, please reopen.