-
April 10th, 2014, 03:47 AM
#1
C#, Java and Ruby Code Samples for Creating PDF File from HTML in Cloud
This tutorial shows how developers can create PDF file from HTML in Cloud using Aspose.Pdf for Cloud API in their applications. You can use this REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
[C# Code Sample]
Code:
stringstrURI = "http://api.aspose.com/v1.1/pdf/outPdfFile.pdf?templateFile=input.html&templateType=html";
stringsignedURI = Sign(strURI);
StreamReader reader = new StreamReader(ProcessCommand(signedURI, "PUT"));
//further process JSON response
stringstrJSON = reader.ReadToEnd();
//Parse the json string to JObject
JObjectparsedJSON = JObject.Parse(strJSON);
BaseResponse stream = JsonConvert.DeserializeObject<BaseResponse>(parsedJSON.ToString());
if (stream.Code == "200" &&stream.Status == "OK")
Console.WriteLine("Empty PDF file has been created successfully");
//Here is the BaseResponse class
public class BaseResponse
{
publicBaseResponse() { }
public string Code { get; set; }
public string Status { get; set; }
}
[Java Code Sample]
Code:
//build uri to create empty pdf
String strURI = "http://api.aspose.com/v1.1/pdf/outPdfFile.pdf?templateFile=input.html&templateType=html";
String signedURI = Sign(strURI);
InputStreamresponseStream = ProcessCommand(signedURI, "PUT");
String strJSON = StreamToString(responseStream);
Gsongson = new Gson();
//Parse the json string to JObject and Deserializes the JSON to a object.
BaseResponsebaseResponse = gson.fromJson(strJSON,BaseResponse.class);
if (baseResponse.getCode().equals("200") &&baseResponse.getStatus().equals("OK"))
System.out.println("Empty PDF file has been created successfully");
//Here is the BaseResponse class
public class BaseResponse {
publicBaseResponse() { }
private String Code;
private String Status;
public String getCode(){return Code;}
public String getStatus(){return Status;}
public void setCode(String temCode){ Code=temCode;}
public void setStatus(String temStatus){ Status=temStatus;}
}
[Ruby Code Sample]
Code:
app_sid = '77******-1***-4***-a***-8***********'
app_key = '89******************************'
Aspose::Cloud::Common::AsposeApp.new(app_sid, app_key)
#build URI to create PDF from HTML
str_uri = 'http://api.aspose.com/v1.1/pdf/outPdfFile.pdf?templateFile=HtmlExample1.html&templateType=html'
#sign URI
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
RestClient.put(signed_uri, '', {:accept=>'application/json'})
#build URI to download output file
str_uri = 'http://api.aspose.com/v1.1/storage/file/outPdfFile.pdf'
#sign URI
signed_uri = Aspose::Cloud::Common::Utils.sign(str_uri)
response_stream = RestClient.get(signed_uri, :accept => 'application/json')
Aspose::Cloud::Common::Utils.save_file(response_stream, "outPdfFile.pdf")
p 'done'
-
June 26th, 2014, 02:11 AM
#2
Re: C#, Java and Ruby Code Samples for Creating PDF File from HTML in Cloud
hi folks,
I use the following code snippet to create PDF file from HTML ,check
Code:
static void Main(string[] args)
{
HtmlConverter.Convert("http://www.wikipedia.org/", "HTMLtoPDF.pdf",
//enable javascript
true,
//load timeout
100 * 1000,
//page size
new SizeF(612, 792),
//page margins
new PdfMargins(0, 0));
System.Diagnostics.Process.Start("HTMLtoPDF.pdf");
}
This scenario is based on C# PDF component , which support to convert the HTML page with rich elements, such as HTTPS, CSS3, HTML5, JavaScript to PDF file.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|