สร้างแบบฟอร์ม PDF ผ่าน Python

สร้าง acroform ใน PDF โดยใช้โปรแกรมโดยใช้ Aspose.PDF สำหรับไลบรารี Python for .NET

วิธีสร้างแบบฟอร์ม PDF โดยใช้ Python

ในการสร้าง PDF Forms (Acroforms) ในไฟล์ PDF เราจะใช้ Aspose.PDF for Python ผ่าน.NET API ซึ่งเป็น API จัดการเอกสารที่อุดมไปด้วยคุณสมบัติ ทรงพลัง และใช้งานง่าย สำหรับแอป Pythonคุณสามารถดาวน์โหลดเวอร์ชันล่าสุดได้โดยตรงจาก PyPi ตัวจัดการแพ็คเกจ ค้นหาaspose-pdf และติดตั้งคุณอาจใช้คำสั่งต่อไปนี้จากคอนโซลหรือเทอร์มินัล

วิธีสร้าง AcroForm ใน PDF โดยใช้ Python


คุณต้อง Aspose.PDF for Python ผ่าน.NET เพื่อลองใช้รหัสในสภาพแวดล้อมของคุณ

1.โหลด PDF ในอินสแตนซ์ของคลาสเอกสาร 1.สร้างฟิลด์ 1.สร้างการตกแต่ง (เช่น Border) 1.เพิ่มฟิลด์ลงในเอกสารและบันทึก PDF ที่แก้ไข

สร้างแบบฟอร์ม PDF ในรูปแบบ PDF - Python

รหัสตัวอย่างนี้แสดงวิธีการสร้างแบบฟอร์ม PDF ใน PDF โดยใช้ Python

import aspose.pdf as apdf

from os import path
path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)
document = apdf.Document(path_infile)

# Create a new text box field
rectange = apdf.Rectangle(100, 100, 200, 120, True)
textBoxField = apdf.forms.TextBoxField(document.pages[1], rectange)
textBoxField.partial_name = "textbox1"
textBoxField.value = "Text Box"

# Customize the border of the text box field
border = apdf.annotations.Border(textBoxField)
border.width = 3
border.dash = apdf.annotations.Dash(1, 1)
textBoxField.border = border

# Set the color of the text box field
textBoxField.color = apdf.Color.dark_green

# Add the text box field to the form
document.form.add(textBoxField, 1)

# Save the modified PDF document
document.save(path_outfile)