Java Code Sample to Create PDF from HTML Using REST API


/ Published in: Java

This code sample shows how Java developers can create PDF file from HTML using Aspose.Pdf for Cloud API in their REST applications.


Copy this code and paste it in your HTML
  1. //build uri to create empty pdf
  2. String strURI = "http://api.aspose.com/v1.1/pdf/outPdfFile.pdf?templateFile=input.html&templateType=html";
  3. String signedURI = Sign(strURI);
  4. InputStreamresponseStream = ProcessCommand(signedURI, "PUT");
  5. String strJSON = StreamToString(responseStream);
  6. Gsongson = new Gson();
  7. //Parse the json string to JObject and Deserializes the JSON to a object.
  8. BaseResponsebaseResponse = gson.fromJson(strJSON,BaseResponse.class);
  9. if (baseResponse.getCode().equals("200") &&baseResponse.getStatus().equals("OK"))
  10. System.out.println("Empty PDF file has been created successfully");
  11.  
  12. //Here is the BaseResponse class
  13. public class BaseResponse {
  14. publicBaseResponse() { }
  15. private String Code;
  16. private String Status;
  17. public String getCode(){return Code;}
  18. public String getStatus(){return Status;}
  19. public void setCode(String temCode){ Code=temCode;}
  20. public void setStatus(String temStatus){ Status=temStatus;}
  21. }

URL: http://www.aspose.com/docs/display/pdfcloud/Create+PDF+from+HTML

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.