douchen4915 2016-03-16 16:35
浏览 810
已采纳

wkhtmltopdf:如何设置拉伸的A4 PDF文档?

I have a page I want to convert to PDF, and I want it to look like the ones "Prince" do, but using wkhtmltopdf.

If you look at this example: http://www.princexml.com/samples/invoice/invoicesample.pdf

and look at the original HTML: http://www.princexml.com/samples/invoice/invoicesample.html

You could see that the HTML has 100% width but it shrinks its' width because of the page size (A4).

I had been trying so many options for 'wkhtmltopdf' but didn't get any good results!

This is the list of properties: http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf_0.10.0_rc2-doc.html#Global%20Options

Can you please help me get the right display?

These are the options I tried in so many ways:

$options = array( 
    // 'page-width' => '216mm', 
    // 'page-height' => '279mm', 
    'page-size' => 'A4', 
    //'dpi' => 96, 
    //'image-quality' => 100, 
    //'disable-smart-shrinking', 
    //'no-outline', 
    'no-outline',           // option without argument
    'encoding' => 'UTF-8',  // option with argument
    'user-style-sheet' => $cssPath,
    'margin-top'    => 0,
    'margin-right'  => 0,
    'margin-bottom' => 0,
    'margin-left'   => 0,


    // 'orientation' => 'portrait', 
    // 'images' => true,
    // 'cookie' => array(),
    // 'dpi' => 300,
    // 'image-dpi' => 300
    // Default page options
    //'disable-smart-shrinking'
    );

There are margins at the top-left-right and the display has a wide screen and the 100% elements don't get smaller.

enter image description here

  • 写回答

1条回答 默认 最新

  • doupai1876 2016-06-03 11:24
    关注

    enable/disable-smart-shrinking option will help you. By default, wkhtmltopdf scale content to configured page size. You should disable this behavior.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配