【问题标题】:Start first PDF page a certain distance from top then start at the top on every page after that?从距顶部一定距离的第一个 PDF 页面开始,然后从每页的顶部开始?
【发布时间】:2015-06-11 00:35:43
【问题描述】:

在 Python 中使用 XHTMLPDF2;很棒的工具!

我正在生成 PDF 以集成到另一个 PDF,因此我需要第一页从顶部的某个高度开始(有时说 432pt,有时是 200pt;它在一个变量中)。

然而,之后的每一页都应该从顶部开始。

我已经尝试过这个 CSS,它的工作原理和我想要的一样......除了第二页和以后的内容是从第一页开始写,然后你会得到原始第一页和第二页的网格从第一个开始。其他页面都很好。

这是我的风格:

<style>
    @page {
    size: letter landscape;
    @frame content1_frame {left: 50pt; width: 512pt; top: 494pt; height: 118pt;}
    @frame content2_frame {left: 50pt; width: 512pt; top: 20pt; height: 612pt;}
    }
</style>

我也尝试过只使用一个框架(仅限 content1_frame),但每个页面从顶部开始 494pt。提前致谢

【问题讨论】:

    标签: python css pdf pypdf


    【解决方案1】:

    就在你的内容之前,使用

    <pdf:spacer height="400px">
    

    所以你的源 HTML 可能看起来像

    <html><head><style>
        @page {
        size: letter landscape;
        @frame content2_frame {left: 50pt; width: 512pt; top: 20pt; height: 612pt;}
        }
    </style>
    </head><body>
    <pdf:spacer height="400px">
        My exciting content goes here! <span style="font-family: Verdana, Arial; font-size: 13.3999996185303px; line-height: 19.1428565979004px; text-align: center; background-color: #ccccdd;">T</span>
    </body></html>
    

    还有你的 Python 代码

    from xhtml2pdf import pisa             # import python module
    resultFile = open('out.pdf', "w+b")
    pisaStatus = pisa.CreatePDF(sourceHTML, dest=resultFile)
    resultFile.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      相关资源
      最近更新 更多