从第一个PDF页面开始,与顶部保持一定距离,然后从每个页面的顶部开始?

2024-09-29 23:16:09 发布

您现在位置:Python中文网/ 问答频道 /正文

在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>

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


Tags: 工具框架网格高度pdfstyle风格top
1条回答
网友
1楼 · 发布于 2024-09-29 23:16:09

在内容之前,使用

<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()

相关问题 更多 >

    热门问题