【问题标题】:Using different margins on first page using pdfkit python使用 pdfkit python 在第一页上使用不同的边距
【发布时间】:2016-05-04 08:14:27
【问题描述】:

我正在使用 pdfkit 和 wkhtmltopdf 从 html 生成 pdf。我使用以下代码来执行此操作:

pdfkit.from_string(htmlString, filename, options = options, cover = cover)

cover 是 html 文件,options 是设置 wkhtmltopdf 选项的 dict,filename 是生成的 pdf 文件的名称,htmlString 是包含 pdf 内容的字符串。

选项是:

options = {
    'user-style-sheet':css,
    'encoding': 'UTF-8',        
    'margin-left': '25mm',
    'margin-right': '25mm',
    'margin-bottom': '25mm',
    'margin-top': '25mm'
}

我想要做的和我似乎没有开始工作的是封面页上的不同边距。在封面上,我有一个应该从页面顶部开始的背景图片(没有边距)。

我尝试为此使用 css,但没有成功。我还发现了以下建议,但我似乎做错了什么:

   <head>
        <meta name="pdfkit-margin-left" content="0mm" />
        <meta name="pdfkit-margin-right" content="0mm" />
        <meta name="pdfkit-margin-bottom" content="0mm" />
        <meta name="pdfkit-margin-top" content="0mm" />
    </head>

有什么建议吗?谢谢!

【问题讨论】:

  • 我也想弄清楚如何设置首页边距。您对此有什么了解吗?

标签: python html css wkhtmltopdf pdfkit


【解决方案1】:

这是我的解决方案,创建 PDFDocument 时使用autoFirstPage: false,然后可以使用addPage 设置第一页的边距:

const doc = new PDFDocument({autoFirstPage: false});
doc.addPage({margin: 36});

https://pdfkit.org/docs/guide.pdf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    相关资源
    最近更新 更多