I've been using phantomjs to convert HTML pages to PDF.  On my Mac, everything was OK.  But, on a Linux environment, the fonts were not rendering properly (particularly web fonts).  There isn't too much out there on this problem, until I finally stumbled upon this github issue: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/45.  (Apparently, the workaround found for wkhtmltopdf also applies to phantomjs).  Anyways, the fix finally ended up to be creating a new file (/etc/fonts/conf.d/100-smoothfonts.conf) with the following contents:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <match target="font">
  <edit mode="assign" name="rgba">
   <const>rgb</const>
  </edit>
 </match>
 <match target="font">
  <edit mode="assign" name="hinting">
   <bool>true</bool>
  </edit>
 </match>
 <match target="font">
  <edit mode="assign" name="hintstyle">
   <const>hintslight</const>
  </edit>
 </match>
 <match target="font">
  <edit mode="assign" name="antialias">
   <bool>true</bool>
  </edit>
 </match>
 <match target="font">
  <edit mode="assign" name="lcdfilter">
   <const>lcddefault</const>
  </edit>
 </match>
</fontconfig>

Open in new window


Just throwing this out there in case someone else has the same issue and stumbles upon this post!
6
LVL 7

Expert Comment

by:Brian Matis
Huh... I'm very interested in learning more about this HTML conversion to PDF, but would be particularly interested in a way to convert to JPG. Does the method you're using support that? Any pointers on getting started?
0
LVL 17

Author Comment

by:Phil Phillips
Yeah, I'm using the screen capture ability of phantomjs.  Supported output formats are png, jpeg, gif, pdf.  The phantomjs download page has binaries for the major OSes. Their git repo has a script called "rasterize.js" that I've been using to do the capturing.  Sample usage:

phantomjs rasterize.js https://www.experts-exchange.com ee.jpg

Open in new window

1
LVL 7

Expert Comment

by:Brian Matis
Sweet, thanks Phil! I'll have to give that a try.
0

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month