public class CloudConvert { private String pass = "password"; private String email = "your_email@example.com"; private String inLoc = "C:\\exampleinput\\"; private String outLoc = "C:\\exampleoutput\\"; private String fileName = "file.pdf"; public void execute() { FileInputStream fis = null; try { /* User details - Create an account at http://www.idrsolutions.com/Cloud-Services-New-Registrations/ */ /** * Follow the links for more style parameters: HTML * http://www.idrsolutions.com/configuring-the-pdf-to-html5-converter/ * SVG * http://www.idrsolutions.com/configuring-the-pdf-to-svg-converter/ */ String[] params = {"org.jpedal.pdf2html.viewMode", "multifile", "org.jpedal.pdf2html.navMode", "css"}; /* Sets up the byte array the file will be written to */ File pdfFile = new File(inLoc + fileName); byte[] dataByteArray = new byte[(int) pdfFile.length()]; /* Get the file as a byte array */ fis = new FileInputStream(pdfFile); fis.read(dataByteArray); fis.close(); System.out.println("Converting"); // Pass the user details, document and other parameters to the online converter and assign the resulting byte array byte[] zipFileData = convert(email, pass, fileName, dataByteArray, "html5", Arrays.asList(params), null, false); /* Write the resulting byte array to disk as a .zip file */ File outputFile = new File(outLoc + fileName + ".zip"); FileOutputStream fos = new FileOutputStream(outputFile); fos.write(zipFileData); fos.flush(); fos.close(); unZipIt(outLoc + fileName + ".zip", outLoc); } catch (Exception ex) { // Error handling ex.printStackTrace(); } } /* In this method, the conversion class is created, calls the conversion method and returns the resulting byte array */ private byte[] convert(java.lang.String email, java.lang.String password, java.lang.String fileName, byte[] dataByteArray, java.lang.String conversionType, java.util.List conversionParams, byte[] xmlParamsByteArray, boolean isDebugMode) throws ConversionException { IDRConversionService_Service service = new IDRConversionService_Service(); IDRConversionService port = service.getIDRConversionServicePort(); return port.convert(email, password, fileName, dataByteArray, conversionType, conversionParams, xmlParamsByteArray, isDebugMode); } public void setPassword(String password) { pass = password; } public void setUser(String username) { email = username; } public void setInLoc(String inLocation) { inLoc = inLocation; } public void setOutLoc(String outLocation) { outLoc = outLocation; } public void setFileName(String fileToConvert) { fileName = fileToConvert; } public String getFileName() { return fileName; } public String getOutLoc() { return outLoc; } /** * Unzip it - Curtosy of http://www.mkyong.com/ * * @param zipFile input zip file * @param output zip file output folder */ public void unZipIt(String zipFile, String outputFolder) { byte[] buffer = new byte[1024]; try { //create output directory is not exists File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } //get the zip file content ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); System.out.println("file unzip : " + newFile.getAbsoluteFile()); //create all non exists folders //else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); System.out.println("Done"); } catch (IOException ex) { ex.printStackTrace(); } } }