[英]PYPDF2, how to compress output PDF
i am highlighting text using this code: https://gist.github.com/agentcooper/4c55133f5d95866acdee5017cd318558我正在使用此代码突出显示文本: https://gist.github.com/agentcooper/4c55133f5d95866acdee5017cd318558
from PyPDF2 import PdfFileWriter, PdfFileReader
from PyPDF2Highlight import createHighlight, addHighlightToPage
pdfInput = PdfFileReader(open("input.pdf", "rb"))
pdfOutput = PdfFileWriter()
page1 = pdfInput.getPage(0)
page1.compressContentStreams() # ADDED BY MYSELF
highlight = createHighlight(100, 400, 400, 500, {
"author": "",
"contents": "Bla-bla-bla"
})
addHighlightToPage(highlight, page1, pdfOutput)
pdfOutput.addPage(page1)
outputStream = open("output.pdf", "wb")
pdfOutput.write(outputStream)
problem is connected with too large output PDF that i am receiving, I have added compressContentStreams()
but still doesn't work, input file: 10MB, output 3 GB !问题与我收到的 output PDF 太大有关,我添加了
compressContentStreams()
但仍然无法正常工作,输入文件:10MB,Z78E6221F6393D1356681DB398F1CECE681DB398F14
Not all PDF software is capable of compressing PDFs, when I search their documentation I find no other matches for what could optimize files besides compressContentStreams ().并非所有 PDF 软件都能够压缩 PDF,当我搜索他们的文档时,我发现除了compressContentStreams () 之外没有其他匹配项可以优化文件。
You'll probably need to consider alternative PDF software if you need either better results initially or the ability to compress PDF files.如果您最初需要更好的结果或能够压缩 PDF 文件,您可能需要考虑替代 PDF 软件。 My company offers PDF Optimizer to help in situations like this.
我公司提供PDF 优化器来帮助解决这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.