Login CONTACT java pdf Suchen





+49 661 25100-0support & infohotline
Our Customer
KfW Bankengruppe
+49 661 25100-0support & infohotline
More Products
Our Partners
Oracle Gold Partner

Java and PDF

Java plays an important role in the PDF creation with webPDF:

  • The webPDF.portal is web service implemented in Java and running on a J2EE Apache TomCat Server in order to use OpenOffice.org installed there.
  • The webPDF.jclient is a platform-independant application based on Java.

Additonally, the converter web service of webPDF can be accessed by Java and is therefore integrable into other applications. Following you will see a sample code. The code is based on the assumption, that the webPDF server and the Java client are running on the same machine. The code is intended for demo purposes only and has to be adapted to local requirements.

package webpdfsample;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.namespace.QName;
import net.webpdf.oooconverter.wsclient.stub.*;
public class Main {
    public static void main(String[] args) {
        String serviceURL = "http://localhost:8080/webPDF/OOoConverter";
        String converterOptions = "pdf.restrictPermissions=true&pdf.
        encryptDocument=true";
        OOoConverterService service = null;
        OOoConverter port = null;
        try {
            // get web service information
            URL url = new URL(serviceURL + "?wsdl");
            QName qname = new QName("http://oooconverter.webpdf.net/",
            "OOoConverterService");
            service = new OOoConverterService(url, qname);
            port = service.getOOoConverterPort();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // setup web service options
        OOoConverterOptions options = new OOoConverterOptions();
        options.setSourceExtension(".jpg");
        options.setTargetExtension(".pdf");
        options.setConverterOptions(converterOptions);
        // get a DataHandler to the source file
        javax.activation.DataHandler fileContent = new DataHandler(new
        FileDataSource(new File("webpdf.jpg")));
        javax.activation.DataHandler result = null;
        // start file conversion
        try {
            result = port.convert(options, fileContent);
        } catch (OOoConverterException_Exception ex) {
            ex.printStackTrace();
        }
        if (result != null) {
            // stream file to output
            try {
                result.writeTo(new FileOutputStream(new File("webpdf.pdf")));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}


Wenn Sie mehr über die Technik von webPDF erfahren möchten, klicken Sie hier. Sie können auf dieser Webseite kostenlos online PDF-Dateien erstellen und digital signieren, oder durch Download der Demo-Version die Funktionalität von webPDF auf Ihrem Rechner testen.