Options Operation: Change Display
Minimum technical requirements:
- Java version: 7
- webPDF version: 7
- wsclient version: 1
This code example shows how to use the Options operation in the webPDF ToolboxWebService and how to integrate it with the wsclient library.
Important note:
The following coding example is based on the webPDF wsclient library.
Start and Preparation
To call the webservice as shown below, you should first create a REST or SOAP session. By calling WebServiceFactory, you create either a ToolboxWebService object for a SOAP session:
ToolboxWebService toolboxWebService =
WebServiceFactory.createInstance(
session, WebServiceType.TOOLBOX
);
Or a ToolboxRestWebService object for a REST session:
ToolboxRestWebService toolboxWebService =
WebServiceFactory.createInstance(
session, WebServiceType.TOOLBOX
);
Finally, pass either a RestDocument or SoapDocument object to the webservice object via setDocument().
Use of Webservice Parameters
If you need write access to a protected PDF, pass the current open and/or permission password in the webservice call. You do this on the ToolboxWebService object. Skip this step if the document is not password-protected:
toolboxWebService.getPassword().setOpen("password");
toolboxWebService.getPassword().setPermission("password");
ToolboxWebService as Endpoint of Your webPDF Server
ToolboxWebService bundles several operations that let you modify PDF documents. One of these is Options, which allows you to control how the PDF is displayed.
Add an Options operation to your webservice object:
OptionsType options = new OptionsType();
toolboxWebService.getOperation().add(options);
You can configure the following parameters on Options:
initialPage (default value: 1)
Defines the start page number of the document (first page = 1).
options.setInitialPage(2);
initialView (default value: "none")
Defines which viewer panels are initially opened. Possible values:
- none = No subwindow is opened.
- outlines = The table of contents (outlines) of the document is displayed.
- thumbnails = Thumbnails of the document pages are displayed.
- fullscreen = The document is opened in fullscreen mode.
options.setInitialView(InitialViewType.FULLSCREEN);
magnification (default value: "fitWidth")
Sets the initial zoom mode for the document view. Possible values:
- none = No special zoom mode is selected.
- fitWidth = Zoom to full page width.
- fitPage = Zoom to the full page.
- fitHeight = Zoom to full page height.
- fitVisible = Zoom to the actual content area.
- fitActual = Open in original size.
- zoom = Open with a custom zoom percentage.
options.setMagnification(MagnificationType.ZOOM);
magnificationZoom (default value: 100)
If zoom is selected as magnification mode, this value defines the zoom percentage.
options.setMagnificationZoom(300);
pageLayout (default value: "singlePage")
Defines the page layout mode. Possible values:
- singlePage = Pages are displayed individually.
- singlePageContinous = Pages are displayed individually and continuously.
- twoPages = Two pages are displayed side by side.
- twoPagesContinous = Two pages are displayed continuously.
Below is a more detailed example of a SOAP webservice call:
try (
// Set up a SOAP session with the webPDF server
SoapSession session = SessionFactory.createInstance(
WebServiceProtocol.SOAP,
new URL("https://localhost:8080/webPDF/")
);
// Provide source and target document
SoapDocument soapDocument = new SoapDocument(
new File("Path of the source document").toURI(),
new File("Path of the target document")
)
) catch (ResultException | MalformedURLException ex) {
// Handle exception
}
Further Information
The parameters are also documented in the user manual: Options parameter structure
More webservice coding examples for the wsclient library are available here.