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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程