struggling to adjust page margins in wkhtmltopdf

1,238 views
Skip to first unread message

Kate W.

unread,
Jul 16, 2018, 10:43:18 PM7/16/18
to wkhtmltopdf General
Page margins and footer-spacing seem to have no effect on production. Page margins work on our staging environment. Staging environment is very different. Dunno how to get the Linux version there -- but whatever it is, it's very old and very crusty (like PHP still v5.4 etc. old). Weird that it works on old crust and not shiny new? And we use Git so what is on staging is exactly what ends up on production.

Also worthy to note: I didn't install or configure wkhtmltopdf. A senior dev who actually knows server stuff did, they're gone now.

Questions:
  • What are some potential reasons that both page margins and footer-spacing would not work when using wkhtmltopdf in a certain environment?
  • Is there configuration in wkhtmltopdf that will prevent margins? How can I check said configuration? Again I did not configure this so maybe there is something really dumb that I can check real quick.
  • Other suggested workarounds? Anything you can give me would be appreciated! I've tried most I can think of and I'm at about ~5 hours on a dang page margin, aha.
Versions:
  • Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-112-generic x86_64)
  • wkhtmltopdf 0.12.2.4
How we run wkhtmltopdf:

The user clicks on a link, which is the same URL but with ?print=pdf and ?attorney=name appended. That brings up a different HTML template. I can provide the HTML template being used if needed but I skipped it because I'd have to strip a lot of stuff out. wkhtmltopdf is run via:

if (isset($_GET['target']))
{

    $atty
= $_GET['attorney'];
    $target
= $_GET['target'];
    $destFile
= tempnam(sys_get_temp_dir(), 'client-') . '.pdf';

    $cmd
= exec(
       
'xvfb-run --server-args="-screen 0 1280x1024x24" /usr/bin/wkhtmltopdf --orientation Portrait --page-size Letter ' .
            $target
. ' ' . $destFile,
        $out
,
        $result
   
);

    $file
= file_get_contents($destFile);
   
   
// set the pdf data as download content:
    header
('Content-type: application/pdf');
    header
('Content-Disposition: attachment; filename="' . 'client-' . $atty . '.pdf"');
    echo
($file);
}

Troubleshooting:

Thank you!

eric w

unread,
Jul 16, 2018, 11:04:13 PM7/16/18
to wkhtmltop...@googlegroups.com
Kate, 
different version of OS will cause WKHTMLTOPDF to behave differently. Look back in this thread for the note on creating a font configuration file. Regarding margins, it might not be the margin but how it's reacting to fonts. I'd start with the proper font configuration. Then I'd make you're actually loading the proper font, that is, that the font you think you're using is installed on both the dev and production machines. If it's on the production machine but not the dev machine it means that the dev machine is substituting some other font. You spend all kinds of time getting the PDF to look good, then you put it in production where the proper font actually exists and everything looks like scrambled eggs.  Or the opposite scenario. After that I'd upgrade the version to the latest, a lot of changes have been made. 
0.12.5 is the current release, I would upgrade to avoid fixing things that might already be fixed. 

--
===================================================
You received this message because you are subscribed to the "wkhtmltopdf General" group.
To post to this group, send email to wkhtmltopdf-general@googlegroups.com
To unsubscribe from this group, send email to wkhtmltopdf-general+unsub...@googlegroups.com
 
For more options, visit this group at
http://groups.google.com/group/wkhtmltopdf-general?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "wkhtmltopdf General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wkhtmltopdf-general+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Haase

unread,
Jul 17, 2018, 1:41:57 AM7/17/18
to wkhtmltop...@googlegroups.com
Did you consider --disable-smart-shrinking   (might be spelled out differently) ?
-Sebastian


To unsubscribe from this group, send email to wkhtmltopdf-general+unsubscribe...@googlegroups.com

 
For more options, visit this group at
http://groups.google.com/group/wkhtmltopdf-general?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "wkhtmltopdf General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wkhtmltopdf-general+unsubscribe...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

eric w

unread,
Jul 17, 2018, 2:13:13 AM7/17/18
to wkhtmltop...@googlegroups.com
Good point

To post to this group, send email to wkhtmltop...@googlegroups.com
To unsubscribe from this group, send email to wkhtmltopdf-gen...@googlegroups.com

 
For more options, visit this group at
http://groups.google.com/group/wkhtmltopdf-general?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "wkhtmltopdf General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wkhtmltopdf-gen...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
===================================================
You received this message because you are subscribed to the "wkhtmltopdf General" group.
To post to this group, send email to wkhtmltop...@googlegroups.com
To unsubscribe from this group, send email to wkhtmltopdf-gen...@googlegroups.com

 
For more options, visit this group at
http://groups.google.com/group/wkhtmltopdf-general?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "wkhtmltopdf General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wkhtmltopdf-gen...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
===================================================
You received this message because you are subscribed to the "wkhtmltopdf General" group.
To post to this group, send email to wkhtmltop...@googlegroups.com
To unsubscribe from this group, send email to wkhtmltopdf-gen...@googlegroups.com

 
For more options, visit this group at
http://groups.google.com/group/wkhtmltopdf-general?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "wkhtmltopdf General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wkhtmltopdf-gen...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages