Search code examples
cssprintingwkhtmltopdf

Css border smaller than 4px @300dpi using wkhtmltopdf


I'm generating an auto-filled PDF, cloned from an inDesign layout that I was given. This layout uses tables, with 0.5pt borders on tables. Those borders aren't rendered properly when using wkhtmltopdf, since webkit doesn't want lines thinner than 0.8pt/1px.

I tried to use workarounds such as 0.8px (no display at 100% on screen, correct height at 400%), directly 0.5pt, or using 1px box shadows, none of this seem to give me the correct thickness, since sub-1px or sub-0.8pt lines aren't rendered into my PDF file, and 1px box-shadows give me the same issue.

Edit: The command I'm using to generate my PDF: wkhtmltopdf.exe -T 0 -B 0 -L 0 -R 0 --dpi 300 --disable-smart-shrinking <input> <output>

I'm not against an optical workaround. Here's a preview of my issue:

Thank you in advance!


Solution

  • Solved. Impossible to do with CSS in case it's processed by wkhtmltopdf.

    The first workaround I found was to render the page with zoom:1.41 in an A3 paper size, then render it at zoom:1/(1.41) in an A4. That was quite bloated.

    So, I replaced my borders with using a SVG sprite, with an height/width of 0.2mm. It allows me to skip the A4->A3->A4 conversion, and still use the --disable-smart-shrinking option, even if my markup is now ugly.