Hairlines in PDF's from HTML
May 2017
When you want to create PDF's in Drupal 8, a good solution is Entity Print. Using a variety of PDF creation libraries you can convert an HTML view of an entity into a PDF. However, the smallest graphical resolution of HTML is 1 pixel. This is much more than the hairline width you might want to use in a PDF (for printing or high DPI screens). For many wkhtmltopdf is the library of choice. Using some tricks you can create hairlines in wkhtmltopdf.
The best solution seems to be the Paper Size and Zoom options. Together they allow you print hairlines: For an A4 size page, set the paper size to A0 and the zoom to 4. This allows you to print hairline widths on A4. Currently the Entity Print module does not support the paper size and zoom options. I submitted a patch to add this functionality.
This is especially interesting when using Entity Print in Drupal Commerce 2 projects, as you can print Orders, Shipping Statements and Invoices to PDF. These kinds of PDF tend to need layout that includes fine lines or boxes for items, totals, and such.
about the author
Finne Fortuin is a Drupal development expert.