移动字段
Contents
[
Hide
]
PDF 表单在创建后常常需要进行布局调整。使用 Aspose.PDF for Python,开发人员可以在不重新创建表单字段的情况下将其移动到新位置。
此示例展示了如何通过指定其在页面中的新坐标来重新定位 “Country” 字段。The FormEditor 类提供 move_field 方法以在 PDF 页面内重新定位字段。
- 打开现有的 PDF 表单。
- 创建一个 FormEditor 对象。
- 将 PDF 文档绑定到 FormEditor。
- 使用坐标将 ‘Country’ 字段移动到新位置。
- 保存修改后的文档。
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def move_field(infile, outfile):
# Create FormEditor object
form_editor = pdf_facades.FormEditor()
# Bind document to FormEditor
form_editor.bind_pdf(infile)
# Move field to new page
form_editor.move_field("Country", 200, 600, 280, 620)
# Save updated document
form_editor.save(outfile)