繁体   English   中英

如何仅使用 pdfkit 生成 PDF 的第一页?

[英]How do I only generate the first page of a PDF using pdfkit?

我正在使用 pdfkit 生成我的pdfkit ,它运行良好。 我想要做的只是生成我的 PDF 的第一页而不是所有页面。 我怎么做?

import pdfkit 

options = {
    'page-size': 'Letter',
    'margin-top': '0in',
    'margin-right': '0in',
    'margin-bottom': '0in',
    'margin-left': '0in',
    'encoding': "UTF-8",
    'custom-header': [
        ('Accept-Encoding', 'gzip')
    ],
    'no-outline': None
}

pdfkit.from_file('resume2.html', 'resume2.pdf', options=options)

使用 pypdf2 代替:

from PyPDF2 import PdfFileWriter, PdfFileReader
infile = PdfFileReader('resume2.pdf', 'rb')
output = PdfFileWriter()

p = infile.getPage(0)
output.addPage(p)

with open('newfile.pdf', 'wb') as f:
    output.write(f)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM