As I cannot reopen closed issues, I create a new one, referring to #12887
I am using PhantomJS 2.1.1 on Windows 7.
The problem is the same which already has been discribed in #12887. But I want to add a small script to reproduce it. You just have to adjust the path to the image and the path for the PDF output.
var page = require('webpage').create();
var imageFilename = 'file:///C:/path/to/my.jpg';
page.paperSize = {
"format":"A4",
"header":{
"height":"35mm",
"contents":phantom.callback(function(pageNum, numPages) {
return '<img src="' + imageFilename + '">';
})
}
};
page.setContent('<html><body>Hello'
//+ '<img src="' + imageFilename + '">'
+ '</body></html>', 'http://example.com');
page.onLoadFinished = function(status) {
page.render('C:\\path\\to\\my.pdf', {format: 'pdf'});
phantom.exit();
};
Now, if you execute this script, it won't render the image in the header. But if you uncomment the commented line, it will render the image in the header and in the content.
I read somewhere in the documentation, that the rendering of header and footer does not allow asynchronous requests. That means, now links to content which needs to be loaded, nothing.
That is also the case for CSS style sheets if you refer them in your header. Header and footer are very special. I see also a problem with a white box in header and footer which is always produced by phantomJS.
You can either prepare your data (images) and embed them as base64 encoded strings, or you place the content in the webpage (hidden) and then use it in the header and footer. Both ways can be found in several stack overflow articles.
andre baresel
I'm having the same problem and tried with the base64 encoded string with no luck. My callback return this:
return "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAC2JJREFUeJzdm3l0lNUZh5/7zZZJJttkIxCWQMKSBNIYMMoqAlUQsFSpBBUQEbWiIEU9eCitPR57FIQC1hY8oCyC4lFURBSsWhCEsEMS9i2sSSB7JpPMcvtHJpCQSWbJTOD0+W++eb/3+9135n733ve+V+BnpJTRwEAgGegOdAXCgTDA4DCrAEqAYuA4cAzIAbYLIQr8qU/4w6mUsg+QCQyjtuECIK/ETPbVSq6W11BqtlBSZaXEbCVQoyJQo2DQqegYrqdrZCCJkXp0akVSG4gtwDohxF5fa/VZAKSUIcBUYDLQAyA3v5IN2YXsOF/KwUvlXDdZ3PanUgSpsQYGdQ7n/oRw7usShlal5AIfAkuFE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yayHESyMykqaPyEgy/nTwJCs272Ljr9lU1fj2dElogJrMtBim9Y0rSYwMXAAsrr+w8QZfHp01cPPobHJppZmvdh7hh33H+fnQSfKL3Tvp+tzIfiya9kiDa/nlNWw/W8KIHpE5gRplOfCBEML9QwPN4K/D02nU1uENA3oCyomLBRzNy+fEhQJOX75GqclMSUUVFVXVBGg16HUa2hpDGHlvCiPvSa5zZQcOU5u0XVuXxvIlfs9mSikjqa1ES6L2UHVXwIjz4/NFND4+79fanf8BQVDaNXeoN5sAAAAASUVORK5CYII='>"
Pasting this into an html file is working, so the syntax should be OK. But PhantomJS still doesn't show it.
Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!
Most helpful comment
I read somewhere in the documentation, that the rendering of header and footer does not allow asynchronous requests. That means, now links to content which needs to be loaded, nothing.
That is also the case for CSS style sheets if you refer them in your header. Header and footer are very special. I see also a problem with a white box in header and footer which is always produced by phantomJS.
You can either prepare your data (images) and embed them as base64 encoded strings, or you place the content in the webpage (hidden) and then use it in the header and footer. Both ways can be found in several stack overflow articles.
andre baresel