使用唯一后缀连接 PDF 表单
Contents
[
Hide
]
如果多个文件包含同名字段,合并 PDF 表单可能会导致冲突。使用 Aspose.PDF for Python,开发者可以在连接过程中为表单字段分配唯一后缀。类中的 unique_suffix 属性 PdfFileEditor 该类会自动重命名冲突的字段,保留交互性,并确保所有表单数据保持可用。此方法非常适合以编程方式合并调查、申请或任何交互式 PDF 文档。
- 创建一个 PdfFileEditor 对象并设置唯一后缀。
- 合并 PDF 表单。
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def concatenate_pdf_forms(files_to_merge, output_file):
# Create a PdfFileEditor object
pdf_editor = pdf_facades.PdfFileEditor()
pdf_editor.unique_suffix = (
"_xy_%NUM%" # Set a unique suffix to avoid form field name conflicts
)
pdf_editor.concatenate(files_to_merge, output_file)