PDF Formları. Java ile yönetin

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

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

Etkileşimli PDF formları (AcroForms) eklemek için, PDF işlemeyi zahmetsiz hale getirmek için tasarlanmış güçlü, zengin özelliklere sahip ve geliştirici dostu bir kütüphane olan Java için Aspose.PDF ile çalışacağız. En son sürümü doğrudan Maven adresinden alabilir ve aşağıdaki yapılandırmayı pom.xml ’nize ekleyerek Maven projenize entegre edebilirsiniz.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Java kullanarak PDF Formları Nasıl Oluşturulur

Kodu ortamınızda denemek için Aspose.PDF for Java 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 - Java

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

String inputFile = DATA_DIR.resolve("sample.pdf").toString();
String outputFile = DATA_DIR.resolve("java-create-form.pdf").toString();
// Open document
try (Document pdfDocument = new Document(inputFile)) {
    Page page = pdfDocument.getPages().get_Item(1);
    // Create a field
    TextBoxField textBoxField = new TextBoxField(
            page,
            new Rectangle(100, 200, 300, 300));
    textBoxField.setPartialName("textbox1");
    textBoxField.setValue("Text Box");

    Border border = new Border(textBoxField);
    border.setWidth(5);
    border.setDash(new Dash(1, 1));
    textBoxField.setBorder(border);

    textBoxField.setColor(Color.getGreen());

    // Add field to the document
    pdfDocument.getForm().add(textBoxField, 1);

    // Save modified PDF
    pdfDocument.save(outputFile);
}