简体   繁体   English

使用 PyMuPDF 将一个 pdf 嵌入到另一个 pdf

[英]Embed one pdf into another pdf using PyMuPDF

In need of help from learned people on this forum.需要这个论坛上有学识的人的帮助。 I just want to embed one pdf file to another pdf file.我只想将一个 pdf 文件嵌入到另一个 pdf 文件中。 So that when I go to the attachment section of the second file I can get to see and open the first file.这样当我转到第二个文件的附件部分时,我可以看到并打开第一个文件。 I would like to do this with help of PyMupdf .我想在PyMupdf帮助下做到这PyMupdf Got a command embeddedFileAdd to do so but I am not sure how to use it.有一个命令embeddedFileAdd这样做,但我不知道如何使用它。

Just Soved it with this code:刚刚用这个代码解决了它:

import fitz
pdf1=r'C:\Users\Amit PC\Desktop\pdf1.pdf'
pdf2=r'C:\Users\Amit PC\Desktop\pdf2.pdf'
outfile=r'C:\Users\Amit PC\Desktop\test2.pdf'
img= bytearray(open(pdf2,'rb').read())
doc1=fitz.open(pdf1)
doc1.embeddedFileAdd(img,'attach.pdf')
doc1.save(outfile, deflate = True)
doc1.close()

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

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