This page describes how to use the Pdfcrowd online API to convert PDF to HTML
in Java.
The API is user-friendly and can be integrated into your application with just a few lines of code.
Here are Java examples for quickly getting started with the API.
See more examples.
importcom.pdfcrowd.*;importjava.io.*;publicclassApiTest{publicstaticvoidmain(String[]args)throwsIOException,Pdfcrowd.Error{try{// create the API client instancePdfcrowd.PdfToHtmlClientclient=newPdfcrowd.PdfToHtmlClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// run the conversion and write the result to a fileclient.convertFileToFile("/path/to/logo.pdf","logo.html");}catch(Pdfcrowd.Errorwhy){System.err.println("Pdfcrowd Error: "+why);throwwhy;}catch(IOExceptionwhy){System.err.println("IO Error: "+why);throwwhy;}}}
importcom.pdfcrowd.*;importjava.io.*;publicclassApiTest{publicstaticvoidmain(String[]args)throwsIOException,Pdfcrowd.Error{try{// create the API client instancePdfcrowd.PdfToHtmlClientclient=newPdfcrowd.PdfToHtmlClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// run the conversion and write the result to a fileclient.convertUrlToFile("https://pdfcrowd.com/static/pdf/apisamples/invoice.pdf","invoice.html");}catch(Pdfcrowd.Errorwhy){System.err.println("Pdfcrowd Error: "+why);throwwhy;}catch(IOExceptionwhy){System.err.println("IO Error: "+why);throwwhy;}}}
importcom.pdfcrowd.*;importjava.io.*;importjava.nio.file.Files;importjava.nio.file.Paths;publicclassApiTest{publicstaticvoidmain(String[]args)throwsIOException,Pdfcrowd.Error{try{// create the API client instancePdfcrowd.PdfToHtmlClientclient=newPdfcrowd.PdfToHtmlClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// run the conversion and write the result to a fileclient.convertRawDataToFile(Files.readAllBytes(Paths.get("/path/to/hello_world.pdf")),"logo.html");}catch(Pdfcrowd.Errorwhy){System.err.println("Pdfcrowd Error: "+why);throwwhy;}catch(IOExceptionwhy){System.err.println("IO Error: "+why);throwwhy;}}}
Authentication
The credentials to access the API are your Pdfcrowd username and the API key.
You can try out the API without registering using the following demo
credentials:
It is recommended that you implement error handling to catch errors
that the API may return, see the example code below. A list of status
codes and their description can be found
here.
try{// call the API }catch(Pdfcrowd.Errorwhy){// print the errorSystem.err.println("Pdfcrowd Error: "+why);// print the error codeSystem.err.println("Pdfcrowd Error Code: "+why.getCode());// print the error messageSystem.err.println("Pdfcrowd Error Message: "+why.getMessage());}