Options Operation: Change Display

This code example shows how to work with the Options operation using the webPDF ToolboxWebService and how to best use the wsclient library.

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

Start and Preparation

To be able to call the webservice in this way, you should have already created a REST or SOAP session. When you call the WebserviceFactory, either a ToolboxWebService object (for a SOAP session)

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

..or a ToolboxRestWebService object (for a REST session). Example:

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

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

Use of the Webservice parameter

You need a changing access to your PDF document and for this you have to pass the current open and/or permission password of the document to the webservice call. This happens at the created ToolboxWebService object (if the document does not have such a password protection, you can skip this point):

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

ToolboxWebService as endpoint of your webPDF server

The ToolboxWebService summarizes a series of operations with which you can make the PDF document changeable. One of these operations is the Options operation, which is used here as an example. With the Options operation you can manipulate various options for the presentation of your PDF document.

How to add an Options operation to your WebService object:

OptionsType options = new OptionsType();
toolboxWebService.getOperation().add(options);

The following parameters can be set for the Options object:

initialPage (default value: 1)

Specifies the home page number of the document. (The first page corresponds to the value 1)

options.setInitialPage(2);

initialView (default value: “none”)

Determines which subwindows of the viewer are initially opened. The following values can be set here:

  • none = No subwindow is opened.
  • outlines = The table of contents (outlines) of the document is displayed.
  • thumbnails = Thumbnails of the pages of the document are displayed.
  • fullscreen = The document is opened in full screen mode.
options.setInitialView(InitialViewType.FULLSCREEN);

magnification (default value: “fitWidth”)

Sets the initial magnification of the document view to a preset mode. The following values can be set here:

  • none = No special zoom mode is selected.
  • fitWidth = A suitable zoom level is selected to display the entire page width.
  • fitPage = A suitable zoom level is selected to display the entire page.
  • fitHeight = An appropriate zoom level is selected to display the entire page height.
  • fitVisible = An appropriate zoom level is selected to display the actual content area of the page.
  • fitActual = The document is opened in its original size.
  • zoom = The document is opened with a certain magnification.
options.setMagnification(MagnificationType.ZOOM);

magnificationZoom (default value: 100)

If Zoom mode is selected for the magnification, this percentage value determines the magnification.

options.setMagnificationZoom(300);

pageLayout (default value: “singlePage”)

Defines the layout in which the pages are displayed. The following values can be set here:

  • singlePage = The pages are displayed individually and isolated.
  • singlePageContinous = The pages are displayed individually and consecutively.
  • twoPages = Two pages of the document are displayed separately.
  • twoPagesContinous = Two pages of the document are displayed consecutively.

We will now give you a more detailed example for the 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:
    OptionsType options = new OptionsType();
    toolboxWebService.getOperation().add(options);

    options.setInitialPage(2);
    options.setInitialView(InitialViewType.FULLSCREEN);
    options.setMagnification(MagnificationType.ZOOM);
    options.setMagnificationZoom(300);

    // Ausführung.
    toolboxWebService.process();
} catch (ResultException | MalformedURLException ex) {

    // To evaluate possible errors that have occurred, the
    // wsclient library appropriate methods are available:
}

Further information here:

The parameters are also described in the user manual: Options Parameter structure

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