PDF Formları. Python ile yönetin

Python via .NET Kütüphanesi için Aspose.PDF kullanarak PDF belgesindeki Acroformları yönetme

Python via .NET Kütüphanesi için Aspose.PDF Kullanarak PDF Formları Nasıl Yönetilir

PDF Formları (Acroforms) bir PDF dosyasına eklemek için Python uygulaması için zengin özelliklere sahip, güçlü ve kullanımı kolay bir belge işleme API’si olan Aspose.PDF for Python via .NET API’sini kullanacağız. En son sürümünü doğrudan PyPI paket yöneticisinden indirebilir, aspose-pdf arayabilir ve yükleyebilirsiniz. Konsoldan veya terminalden aşağıdaki komutu da kullanabilirsiniz.

Console

pip install aspose-pdf

Python kullanarak PDF Formları Nasıl Oluşturulur

Kodu ortamınızda denemek için Aspose.PDF for Python üzerinden .NET gerekir.

  1. Document sınıfının bir örneğine PDF yükleyin.
  2. Sayfaya dizini aracılığıyla erişin.
  3. Form koleksiyonunun Ekle yöntemini çağırın.
  4. Eklemek istediğiniz form alanını oluşturun.
  5. PDF dosyasını kaydedin.

PDF'de PDF Formları Oluşturma - Python

Bu örnek kod, Python kullanarak PDF'de PDF Formlarının nasıl oluşturulacağını gösterir

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)