PyPDF2文件的完整克隆 [英] PyPDF2 complete clone of file

查看:178
本文介绍了PyPDF2文件的完整克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PyPDF2完整复制PDF,以下代码复制了内容,但没有复制PDF的轮廓.

I am trying to copy a PDF in its entirety using PyPDF2, the following code copies the content but not the outline of the pdf.

这是一个示例pdf ,并使用如下的代码python test.py <input pdf> <output dest>

here is a sample pdf and use the code as follows python test.py <input pdf> <output dest>

这是我到目前为止的代码.

Here is the code that I have so far.

from PyPDF2 import PdfFileWriter, PdfFileReader
import sys
import os.path

def main(argv):
    if not os.path.isfile(argv[0]) and \
    not os.path.isfile(argv[1]):
        print("Invalid path")
        sys.exit()
    input_pdf = PdfFileReader(open(argv[0], "rb"))
    output_pdf = PdfFileWriter()
    input_pdf_pages = input_pdf.getNumPages()
    for i in range(0, input_pdf_pages):
        output_pdf.addPage(input_pdf.getPage(i))
    output_pdf.write(open(argv[1], "wb"))

if __name__ == "__main__":
    main(sys.argv[1:])

推荐答案

PdfFileWriter确实有许多复制整个文件的方法:appendPagesFromReadercloneReaderDocumentRootcloneDocumentFromReader.

PdfFileWriter does have a number of methods for copying an entire file: appendPagesFromReader, cloneReaderDocumentRoot, and cloneDocumentFromReader.

但是,我也无法使它们正常工作. ;-)您可能会遇到好运.

However, I can't get them to work properly either. ;-) You might have better luck.

这篇关于PyPDF2文件的完整克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆