How-to: How to use webPDF webservices
Minimum technical requirements
- Java version: 7
- webPDF version: 6
- wsclient version: 1

This tutorial uses a simple example to show how to use webPDF webservices. The "Converter" webservice is used to convert a selected file into a PDF document. Java is used to access the webservice. To run this example locally, you need webPDF, JDK 1.7 or later, and IntelliJ IDEA (Community Edition is sufficient).
Set up the project in IntelliJ
After installing the required software, create a new Java project in IntelliJ. In the start view, click Create New Project. If a project is already open, use File -> New -> Project....
Select Java as the project type and choose your installed JDK. If needed, add it via New... by selecting the JDK home directory.

Click Next. In the following dialog, choose the Command Line App template and click Next.
Enter the values as shown in the screenshot and click Finish.
IntelliJ will open the new project after creating the directory. Open the project view via View -> Tool Windows -> Project.

The IntelliJ project is now ready.
Generate required proxy classes with wsimport
The target webservice uses the SOAP protocol. To call it, you need generated proxy classes (client stubs).
In IntelliJ, right-click the src folder and select Run cmd shell. Run the following command:
wsimport -Xnocompile -s . http://localhost:8080/webPDF/Converter?WSDL
Note: if webPDF is not running on port 8080, adjust this and all related URLs.
After running the command, the generated proxy classes are available in package net.webpdf.converter.

Implement the webservice request
Insert the example code into the main method of your main class.
Note: while typing, unknown classes may be marked red. Use Ctrl+Space (multiple import suggestions) or Alt+Enter (single suggestion) to add required imports.
URL url = null;
try {
// initialize URL
} catch (MalformedURLException ex) {
// handle invalid URL
}
Initialize a URL object inside a try/catch block because the constructor can throw MalformedURLException.
QName qname = new QName("http://converter.webpdf.net/", "ConverterService");
ConverterService service = new ConverterService(url, qname);
Converter endpoint = service.getConverterPort();
Create a QName to resolve XML namespaces in WSDL, initialize ConverterService, then fetch the endpoint as Converter.
DataHandler fileContent = new DataHandler(
new FileDataSource(new File("./src/net/webpdf/converter/Converter.java"))
);
DataHandler result = null;
try {
// result = endpoint.convertDocument(...)
} catch (ConverterException_Exception ex) {
// handle converter error
}
fileContent references the source file to convert. The conversion result is returned as another DataHandler.
try {
// write DataHandler content using FileOutputStream
} catch (IOException ex) {
// handle file write error
}
Finally, write the converted result into your project directory. After execution, the generated PDF should be available there.

You have now converted a Java file into a PDF using a webPDF webservice.
Attachment:
Required imports for the class:
import net.webpdf.converter.Converter;
import net.webpdf.converter.ConverterException_Exception;
import net.webpdf.converter.ConverterOptions;
import net.webpdf.converter.ConverterService;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
You can find our technical webservices series for webPDF 7.0 here.