我正在创建一个 python 脚本来编辑 PDF 中的文本。
我有这个 Python 代码,它允许我将文本添加到 PDF 文件的特定位置。
import PyPDF2
import io
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
import sys
packet = io.BytesIO()
# create a new PDF with Reportlab
can = canvas.Canvas(packet, pagesize=letter)
# Insert code into specific position
can.drawString(300, 115, "Hello world")
can.save()
#move to the beginning of the StringIO buffer
packet.seek(0)
new_pdf = PyPDF2.PdfFileReader(packet)
# read your existing PDF
existing_pdf = PyPDF2.PdfFileReader(open("original.pdf", "rb"))
num_pages = existing_pdf.numPages
output = PyPDF2.PdfFileWriter()
# add the "watermark" …Run Code Online (Sandbox Code Playgroud) 我需要将一些PDF转换回文本。我尝试了许多软性和在线工具,结果总是中等。
从技术上讲为什么如此困难?