簡體   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