Toolbox Forms Operation of the webPDF wsclient Library

Minimum Technical Requirements

  • Java version: 7
  • webPDF version: 7
  • wsclient version: 1

How Can Form Data Be Exported, Imported, or Flattened with the wsclient Library?

Important Note

The following code example is based on the use of the webPDF wsclient library. To understand and apply the example correctly, you should first read the relevant introductory blog post.

Here we introduce the Forms operation of the webPDF ToolboxWebservice and show, with concrete code examples, how to use it with the webPDF wsclient library.

REST and SOAP Sessions

To follow the example completely and call the webservice, you should first have created a REST or SOAP session and thus be able to create a ToolboxWebService object for a SOAP session by calling WebserviceFactory:

ToolboxWebService toolboxWebService =
WebServiceFactory.createInstance(
session, WebServiceType.TOOLBOX
);

Or a ToolboxRestWebService object for a REST session:

ToolboxRestWebService toolboxWebService =
WebServiceFactory.createInstance(
session, WebServiceType.TOOLBOX
);

Finally, you should have passed either a RestDocument or a SoapDocument object to the WebService object by calling the setDocument() method.

The next steps describe how to obtain write access to a document.

Description of the Webservice Parameters

You should pass the current open and/or permission password of the document to the webservice call. This is done on the created ToolboxWebService object:

toolboxWebService.getPassword().setOpen("password");
toolboxWebService.getPassword().setPermission("password");

If the document is not protected by a password, you can skip this step.

The Toolbox Webservice: Forms Operation

With the Forms operation, it is possible to export or import form data. This means you can edit your PDF accordingly.

You add a Forms operation to your WebService object as follows:

FormsType forms = new FormsType();
toolboxWebService.getOperation().add(forms);

The following parameters can then be set on the Forms object.

The export Object

To export form data and configure the export, add a FormsExportType object to the Forms object.

FormsExportType export = new FormsExportType();
forms.setExport(export);

The following parameters can be set on the Export object.

format (default value: "xml")

Defines the file format in which form data should be exported. The following values can be set:

  • xml = XML
  • fdf = FDF
  • xfdf = XFDF
  • xdp = XDP, only for XFA data
export.setFormat(FormsFormatType.FDF);

The schema http://schema.webpdf.de/1.0/form/data.xsd is used for XML export.

fdfFileName (default value: "")

Defines the name of the PDF document that should be loaded automatically when the FDF file is opened. This applies only to the FDF export format.

export.setFdfFileName("fdf file name");

The import Object

To import form data and configure the import, add a FormsImportType object to the Forms object.

FormsImportType importData = new FormsImportType();
forms.setImport(importData);

The following parameters can be set on the Import object.

flatten (default value: false)

If this value is set to true, the form is flattened after the form data has been imported.

importData.setFlatten(true);

format (default value: "xml")

Specifies the format of the data to be imported. The following values can be set:

  • xml = XML
  • fdf = FDF
  • xfdf = XFDF
  • xdp = XDP, only for documents with XFA data
importData.setFormat(FormsFormatType.FDF);

The schema http://schema.webpdf.de/1.0/form/data.xsd is used for XML import.

The data itself is set via a FormsFileDataType object.

The data Object

You select the form data to be imported by adding a FormsFileDataType object to the ImportData object.

FormsFileDataType data = new FormsFileDataType();
importData.setData(data);

The following parameters can be set on the Data object.

source

Specifies the source from which the form data should be obtained. The following values can be set:

  • value = The data is passed directly as a byte array.
  • uri = A URI reference to the data is passed.
data.setSource(FileDataSourceType.VALUE);

value

Passes the form data as a byte array. The source value should be set to value.

data.setValue(FileUtils.readFileToByteArray(new File("...")));

uri

Passes a URI reference to the form data to be used. The source value should be set to uri.

data.setUri(new File("...").toURI().toString());

The flatten Object

To flatten forms and their contents, for example to lock them against further changes, you can add a FormsFlattenType object to the Forms object.

forms.setFlatten(new FormsFlattenType());

This operation supports only AcroForms. Static XFA Forms and Dynamic XFA Forms are not supported.

This operation has no additional parameters.

Example of a Webservice Call, SOAP

Here is a more detailed example of the full webservice call for addressing the SOAP interface:

try (
// Set up a session with the webPDF server, here using SOAP.
SoapSession session = SessionFactory.createInstance(
WebServiceProtocol.SOAP,
new URL("https://localhost:8080/webPDF/")
);
// Provide the document to be processed and the target file.
SoapDocument soapDocument = new SoapDocument(
new File("Path of the source document").toURI(),
new File("Path of the target document")
)
) catch (IOException ex)

More code examples for webservices that you can use with the wsclient library can be found here.