URL Converter with the wsclient Library
Minimum Requirements
- Java version: 7
- webPDF version: 7
- wsclient version: 1

This article shows how to convert websites into PDF documents with the URL Converter webservice.
Important note: The following coding example is based on the webPDF wsclient library.
Calling the Webservice
At the start, you should already have created a REST or SOAP session. Using the WebServiceFactory, you can create either an UrlConverterWebService object for SOAP or an UrlConverterRestWebService object for REST.
SOAP:
UrlConverterWebService urlConverterWebService =
WebServiceFactory.createInstance(
session, WebServiceType.URLCONVERTER
);
REST:
UrlConverterRestWebService urlConverterWebService =
WebServiceFactory.createInstance(
session, WebServiceType.URLCONVERTER
);
After that, pass a RestDocument or SoapDocument via setDocument().
Webservice Parameters
For write access, the current open and/or permission password may be required:
urlConverterWebService.getPassword().setOpen("password");
urlConverterWebService.getPassword().setPermission("password");
This step is only relevant if the document is password protected.
URL Converter Webservice
The URL Converter is a webPDF server endpoint that converts websites into PDF documents.
You can retrieve the UrlConverterType object like this:
UrlConverterType urlConverter = urlConverterWebService.getOperation();
Parameters on the urlConverter Object
url (default: "")
Defines the URL of the website to convert:
urlConverter.setUrl("https://www.webpdf.de");
The page Object
To define page size and margins, add a PageType object:
PageType page = new PageType();
urlConverter.setPage(page);
Important parameters:
width(default:210):page.setWidth(800);height(default:297):page.setHeight(1600);bottom(default:20):page.setBottom(10);top(default:20):page.setTop(10);left(default:20):page.setLeft(10);right(default:20):page.setRight(10);metrics(default:"mm"):page.setMetrics(MetricsType.MM);
Available units:
mm= millimeterpx= pixel
The basicAuth Object
If the target URL requires HTTP authentication, add an HttpBasicAuthType object:
HttpBasicAuthType basicAuth = new HttpBasicAuthType();
urlConverter.setBasicAuth(basicAuth);
Parameters:
username(default:""):basicAuth.setUserName("username");password(default:""):basicAuth.setPassword("password");
The proxy Object
If access is only possible through a proxy, use an HttpProxyType object:
HttpProxyType proxy = new HttpProxyType();
urlConverter.setProxy(proxy);
Parameters:
username(default:""):proxy.setUserName("username");password(default:""):proxy.setPassword("password");address(default:""):proxy.setAddress("Proxy Address");port(default:0):proxy.setPort(8080);
Example Webservice Call
Below is a more detailed example of the full webservice call for the SOAP interface:
try (
// Set up a session with the webPDF server (SOAP in this example):
SoapSession session = SessionFactory.createInstance(
WebServiceProtocol.SOAP,
new URL("https://localhost:8080/webPDF/")
);
// Provide the source and target documents:
SoapDocument soapDocument = new SoapDocument(
new File("Path to the source document").toURI(),
new File("Path to the target document")
)
) {
// Webservice call and processing
} catch (ResultException | MalformedURLException ex) {
// Error handling
}
- More information about the URL Converter parameter structure and error codes is available in the documentation.
- Please note that all parameters have default values and only need to be set when you want to override them.
More coding examples for webservices that can be used with the wsclient library are available here.