在wkhtmltopdf中混合页面方向 [英] Mixing page orientations in wkhtmltopdf

查看:980
本文介绍了在wkhtmltopdf中混合页面方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用wkhtmltopdf从单个HTML文件生成PDF,并使用 page-break-before:始终格式化为单独的页面。例如:

 < div class =cover> 
封面页
< / div>
< div class =page>
Page 1
< / div>
< div class =page>
Page 2
< / div>

使用CSS:

  .page {
page-break-before:always;

$ / code>

现在,我编写wkhtmltopdf命令以纵向打印PDF在信纸大小的页面上。我需要其中一个页面处于横向模式,其他页面处于纵向模式(以便在屏幕上查看PDF时,所有内容都将正确定向)。



有没有在单个PDF中混合方向的方法?

如果这不可行,是吗?一种使用wkhtmltopdf合并多个PDF的方法? (我已经看到了不同pdfmerge软件的其他建议)。如果需要,我可以将我的HTML源文件分割成多个文件。

如果有人在将来寻找这个答案,我会用我的解决方案来完成这个。基于缺乏答案,我想真的没有办法使用wkhtmltopdf创建一个包含多个页面方向的PDF文件。


  1. 我实现的第一个解决方案是使用一个HTML文件创建一个PDF,并使用以下CSS旋转横向页面的内容:

      width:1275px; 
    height:1650px;

    -webkit-transform:translateY(1650px)rotate(270deg); / * Chrome,Safari 3.1+ * /
    -moz-transform:translateY(1650px)rotate(270deg); / * Firefox 3.5+ * /
    -o-transform:translateY(1650px)rotate(270deg); / * Opera 10.5-12.0 * /
    -ms-transform:translateY(1650px)rotate(270deg); / * IE 9 * /
    transform:translateY(1650px)rotate(270deg); / * IE 10+,火狐16.0+,歌剧12.1+ * /
    滤波器:的progid:DXImageTransform.Microsoft.Matrix(M11 = 6.123031769111886e-17,M12 = 1,M21 = -1,M22 = 6.123031769111886e- 17,SizingMethod ='auto expand'); / * IE 6-7 * /
    -MS-滤波器:的progid:DXImageTransform.Microsoft.Matrix(M11 = 6.123031769111886e-17,M12 = 1,M21 = -1,M22 = 6.123031769111886e-17,SizingMethod ='auto expand'); / * IE 8 * /

    -webkit-transform-origin:0%0%;
    -moz-transform-origin:0%0%;
    -o-transform-origin:0%0%;
    -ms-transform-origin:0%0%;
    transform-origin:0%0%; (要编写类似的兼容CSS3转换,请查看这个伟大的站点来计算所有的IE矩阵值: http://www.useragentman.com/IETransformsTranslator/



    如果您的用户在制作后只能打印PDF,这将是一个体面的解决方案。由于我的用户需要在屏幕上查看PDF,因此他们不得不使用PDF查看软件旋转页面。因此,我的第二个解决方案是将每个页面创建为单独的HTML文件的单独PDF,然后使用 www.ghostscript.com/download/gsdnld.htmlrel =noreferrer> Ghostscript 将它们合并成一个文件。这工作完美,但只是增加了一些额外的处理时间来创建所有的文件并合并它们。就我而言,PDF不会经常下载,页面数量也很少,所以额外的时间不是一个重大的负担。



I'm using wkhtmltopdf to produce a PDF from a single HTML file, formatted into separate pages using page-break-before: always. For example:

<div class="cover">
    Cover Page
</div>
<div class="page">
    Page 1
</div>
<div class="page">
    Page 2
</div>

With CSS:

.page {
    page-break-before: always;
}

Right now, I have the wkhtmltopdf command written to print the PDF in portrait orientation on letter-size pages. I need one of the pages to be in landscape orientation and the rest to be in portrait orientation (so that when the PDF is viewed on screen, all of the content will be oriented correctly).

Is there a way to mix orientations in a single PDF?

If this is not possible, is there a way to merge multiple PDFs using wkhtmltopdf? (I have seen other suggestions of different pdfmerge software.) I could split my HTML source file into multiple files for each page if necessary.

解决方案

In case someone is looking for this answer in the future, I will complete this with my solutions. Based on the lack of answers, I guess there really is no way to create a PDF with multiple page orientations using wkhtmltopdf.

  1. The first solution I implemented was creating a single PDF using one HTML file and rotating the content of the landscape page using the following CSS:

    width: 1275px; 
    height: 1650px; 
    
    -webkit-transform: translateY(1650px) rotate(270deg); /* Chrome, Safari 3.1+ */ 
    -moz-transform: translateY(1650px) rotate(270deg); /* Firefox 3.5+ */ 
    -o-transform: translateY(1650px) rotate(270deg); /* Opera 10.5-12.0 */ 
    -ms-transform: translateY(1650px) rotate(270deg); /* IE 9 */ 
    transform: translateY(1650px) rotate(270deg); /* IE 10+, Firefox 16.0+, Opera 12.1+ */ 
    filter: progid:DXImageTransform.Microsoft.Matrix(M11=6.123031769111886e-17, M12=1, M21=-1, M22=6.123031769111886e-17, SizingMethod='auto expand'); /* IE 6-7 */ 
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=6.123031769111886e-17, M12=1, M21=-1, M22=6.123031769111886e-17, SizingMethod='auto expand')"; /* IE 8 */ 
    
    -webkit-transform-origin: 0% 0%; 
    -moz-transform-origin: 0% 0%; 
    -o-transform-origin: 0% 0%; 
    -ms-transform-origin: 0% 0%; 
    transform-origin: 0% 0%; 
    

    (To write similar compatible CSS3 transforms, check out this great site to calculate all of the IE matrix values: http://www.useragentman.com/IETransformsTranslator/)

    This would be a decent solution if your users would only be printing the PDF after it was produced. Since my users need to view the PDF on screen, it would not be practical for them to have to rotate the page using their PDF viewing software.

  2. So, my second solution was to create each page as a separate PDF from individual HTML files, and then I used Ghostscript to merge them into a single file. This worked perfectly, but just added some extra processing time to create all of the files and merge them. In my case, the PDF would not be downloaded too often and the number of pages was minimal so the extra time was not a significant burden.

这篇关于在wkhtmltopdf中混合页面方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆