Open aldopj opened 2 years ago
same issue here
Just installed the package and ran it, same issue. Trying to find a workaround now.
EDIT: Looks like the page size is not respected at all. I've tried setting size manually (210mm x 297mm) or A4 but the actual PDF comes back to 8.26i x 11.69in
Looks like this is a know issue with phantomjs: https://github.com/ariya/phantomjs/issues/12685 You need to experiment to make the page size work. In my case, passing format as "A3" resulted in almost the correct aspect ratio.
this "solved" it in case too, but be aware that when you try to print it, the size is incorrect again - it can be solved by tinkering with ratio and page size in printer setting, so it's not a huge deal, but it my affect some business scenarios, so it's best to keep that in mind
I had the same issue but not on my local machine. This led me to discover that I had phantomjs
installed on my device. So the issue seems to be with the phantomjs-prebuilt
package somehow since when you have phantomjs
installed already it doesn't install it's own. To test this:
rm -rf node_modules
sudo apt install phantomjs
npm i
this worked for me
I created a pdf from a simple html. i used 'mm' for units for page size as well as a div inside it. i put a 120mm div inside the 240mm page. The div should have been half the width of the page but its more like 80%. I tried zoomFactor, but no change in output. Below is the code:
html = "
const options = { height: "140mm", // allowed units: mm, cm, in, px width: "240mm", type: "pdf", };
pdf.create(html, options).toStream(function (err, stream) { if (err) { res.status(500); } else { stream.pipe(fs.createWriteStream("./foo.pdf")); res.status(200).json({ text: "Done" }); } });