Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhantomJS generates large PDF

Tags:

pdf

phantomjs

I'm using PhantomJS to convert many (+500) web pages to PDF documents. Problem is, I keep getting quite large PDF files (approx 900 kb) for relatively small pages - 70 kb with images. Why they are so big? A simple "Save to PDF" in Firefox creates a 200 kb file, which is fine. I will soon have to process many other pages and file size will likely be an issue. Any suggestion?

EDIT: Here's two samples: output from PhantomJS and Firefox save to PDF

like image 370
gioppe Avatar asked Jan 07 '14 10:01

gioppe


1 Answers

Even i am facing the same problem. I was trying to reduce the size of the pdf when there is large amount of data. What i have observed is, If you dump your textual content (Example paragraphs, tabular data, description etc) inside any of these headers tags (h1, h2 ...h6), This part of the content will be rendered as text in the pdf and not as image. This will reduce good amount of pdf file size.

I am not sure why the contents inside div, p, span tags are not treated as text but as image in the pdf.

like image 123
ranjansaga Avatar answered Sep 23 '22 06:09

ranjansaga