webPDF Toolbox Delete: Remove Pages

Minimum Technical Requirements

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

This article provides an application-oriented description with code examples for the Delete operation of the webPDF ToolboxWebService.

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.

First Steps: Creating a REST or SOAP Session

To call the webservice in the way we want to present here, we assume that you have first created a REST or SOAP session and can then create either 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
);

Either a RestDocument or a SoapDocument object is then passed to this WebService object by calling the setDocument() method.

About the Webservice Parameter

Because you want to modify your documents, you need to 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");

You only need to consider this point if the document is protected by a corresponding password.

Toolbox Webservice: The Delete Operation

The ToolboxWebService can be understood as an endpoint of your webPDF server that combines several operations and makes it possible to modify your PDF document accordingly. Here we focus on one specific example, namely the Delete operation for deleting or removing pages.

Adding the Delete Operation to the WebService Object

DeleteType delete = new DeleteType();
toolboxWebService.getOperation().add(delete);

The following parameters can be set on the Delete object.

pages (default value: "1")

Defines the page range to be deleted. You can specify a single page ("1"), a list of pages ("1,3,5"), a page range ("1-5"), or a combination of these elements ("1,3-5,6"). All pages of the document can be selected with "*".

delete.setPages("1,3-5,6");

More Detailed Example

Finally, 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 (ResultException | MalformedURLException ex)

Note

You can find additional information about the parameters, error codes, and also SOAP and REST in the webPDF user manual.

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