Post: C#, Java and Ruby Code Samples for Creating PDF File from HTML in Cloud
04-10-2014, 08:48 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); This tutorial shows how developers can You must login or register to view this content. 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]

    
stringstrURI = "https://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; }
}



    [/B]

[CODE]
//build uri to create empty pdf
String strURI = "https://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;}
}[/CODE]


[B][Ruby Code Sample][/B]

[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 = 'https://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 = 'https://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'Winky Winky
Aspose::Cloud::Common::Utils.save_file(response_stream, "outPdfFile.pdf")
p 'done'[/CODE]
(adsbygoogle = window.adsbygoogle || []).push({});

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo