douhensheng1131 2013-09-06 12:08
浏览 90
已采纳

wkhtmltopdf扩大了服务器上的内容

I'm generating invoices based on an online office environment. On my local server (win7) everything is working as it should. PDF's are generated perfectly with correct measurements etc. but when generating a pdf via the online server (linux) all the content gets enlarged. The pdf's hold a header, invoice rules and a footer. All of those hold text and a background-image. This causes the content to go beyond the page dimensions.

Here's an image to illustrate what I mean, left the locally generated pdf and to the right the one generated online. (blanked out some fields) enter image description here

Thing's I've tried, but with no succes:

  • adding the zoom parameter
  • adding the dpi parameter
  • updating wkhtmltopdf on the server
  • setting max sizes in css (i.e. a4 size in mm)

Does anyone know how to make the PDF look the same on the online server? Is there an argument/parameter I'm missing?

Extra info:

  • I'm running v0.11.0 rc2 locally and the server is on v0.11.0 rc1. Coulnd't find the rc2 version for linux or mac.
  • I'm using the footer, header and zoom arguments when generating, nothing else.
  • 写回答

2条回答 默认 最新

  • douchen2011 2013-09-09 06:43
    关注

    My colleague fixed the problem this weekend. He updated wkhtmltopdf but that didnt help. Then he proceeded to set the max width in pixels and that did the trick. I already had set the max-width and height in mm but had no effect. This did make the header get positioned wrong, half way accros the page. The fix for this was adding height:0; to it. The fixes don't make that much sense to me but hey it works :P.

    I'm using the following params now:

    ["disable-smart-shrinking"],
    ["margin-left" => 0],
    ["margin-right" => 0],
    ["page-width" => "210mm"],
    ["page-height" => "297mm"],
    ["margin-bottom" => 0],
    ["header-html" => CUSTOM FUNCTION],
    ["margin-top" => "90mm"],
    ["header-spacing" => "90"],
    ["margin-bottom" => "18mm"],
    ["footer-html" => CUSTOM FUNCTION],
    ["javascript-delay" => 1000]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?