我有一些巨大的 pdf 技术电子书,我想以一种帮助我从每本书中准确找到和阅读我想要的部分的方式将它们分开。我说的是带有内容(部分和章节)的索引 pdf 文件。我根据 pdf 的内容提出了以下分割方案:
<强>1。阅读本书的内容。 2.为整本书创建一个根文件夹 3. 为本书的每一部分创建一个子文件夹 4. 将本书每章拆分为一个 pdf 文件,并将 pdf(章节)放入相应的子文件夹(部分)中。
如何使用 Java 或 Python pdf 库来完成此操作?
最佳答案
您可以使用PyPDF2阅读和分割您的 PDF 文件。
导出 PDF 页面的方法如下:
import PyPDF2
def export_pdf_pages(input_pdf_path, page_first, page_last, output_pdf_path):
with open(input_pdf_path, "rb") as input_stream:
input_pdf = PyPDF2.PdfFileReader(input_stream)
output = PyPDF2.PdfFileWriter()
for index in xrange(page_first - 1, page_last):
try:
page = input_pdf.getPage(index)
except IndexError:
fmt = 'Missing page {page_num} in "{input_pdf_path}"'
msg = fmt.format(page_num=index + 1, input_pdf_path=input_pdf_path)
raise IndexError(msg)
output.addPage(page)
with open(output_pdf_path, "wb") as output_stream:
output.write(output_stream)
关于java - 读取pdf电子书的内容并相应地分割pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40489799/