webPDF Toolbox Delete: Remove Pages

This is about an application description with code examples for the Delete Operation of the webPDF ToolboxWebService.

Important note:

The following coding example is based on the use of the webPDF wsclient library. In order to understand and apply the example, the following blog post should be considered first:

webPDF and Java: very easy with the “wsclient” library

First steps: Creating a REST or SOAP session

To be able to call the webservice the way we want to present it here, we assume that you have first created a REST or SOAP session, and so either a ToolboxWebService object (for a SOAP session) or a SOAP session object (for a SOAP session) can be called by calling the 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 passed to this WebService object by calling the method setDocument().

Webservice Parameter

Because you want to customize your documents, it is necessary that you give the current open and/or permission password of the document to the webservice call.

This happens at the created ToolboxWebService object:

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

(You only need to pay attention to this point if the document has an appropriate password protection.)

Toolbox Webservice: The Delete Operation

The ToolboxWebService can be understood as an endpoint of your webPDF server which summarizes some operations and through which it is possible to customize your PDF document accordingly. Here is a concrete example, namely the Delete Operation (Remove pages).

Add 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”)

Specifies the page area to be deleted. You can specify either 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 using “*”.

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

More detailed example

Finally, here is a somewhat more detailed example of our entire webservice call (for addressing the SOAP interface):

try (
    // Setup of a session with the webPDF server (here SOAP):
    SoapSession session = SessionFactory.createInstance(
        WebServiceProtocol.SOAP,
        new URL("https://localhost:8080/webPDF/")
    );
    // Make available the document that is to be processed
    // and the file in which the result is to be written:
    SoapDocument soapDocument = new SoapDocument(
        new File("Path of the source document").toURI(),
        new File("Path of the target document")
    )
) {
    // Selection of the webservice via a factory:
    ToolboxWebService toolboxWebService =
        WebServiceFactory.createInstance(
            session, WebServiceType.TOOLBOX
        );
    toolboxWebService.setDocument(soapDocument);
    toolboxWebService.getPassword().setOpen("password");
    toolboxWebService.getPassword().setPermission("password");

    // Object-oriented parameterization of the call:
    DeleteType delete = new DeleteType();
    toolboxWebService.getOperation().add(delete);
    delete.setPages("1-5");

    // execution.
    toolboxWebService.process();
} catch (ResultException | MalformedURLException ex) {
    // To evaluate possible errors that have occurred, the
    // wsclient library appropriate methods are available:
}

Note:

You will find further information about the parameters, error codes or SOAP and REST in the webPDF user manual.

More coding examples for webservices that you can use with the ws-client library can be found here.