6

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

2
  • 2
    If possible, use a professional tool such as Acrobat Pro to audit your PDF -- it will tell you where all the bytes went. If not, post a link to an on-line sample. Chances are the problem is PhantomJS itself -- i.e., unable to compress as tight as possible, not subsetting fonts, that sort of things.
    – Jongware
    Commented Jan 7, 2014 at 15:10
  • i agree with Jongware, use some pdf tool to figure out the issue. My bet is that phantomjs doesn't do any compression.
    – JasonS
    Commented Jan 8, 2014 at 1:37

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.