Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This gist contains code snippets related to HTML to PDF conversion using Aspose.HTML Cloud SDK for .NET
This gist contains code snippets related to HTML to PDF conversion using Aspose.HTML Cloud SDK for .NET
// Get ClientID from https://dashboard.aspose.cloud/
string clientSecret = "d757548a9f2558c39c2feebdf85b4c44";
string clientID = "4db2f826-bf9c-42e7-8b2a-8cbca2d15553";
// base URL string
const string SERVICE_API_HOST = "https://api.aspose.cloud";
// Create HtmlApi instance
HtmlApi htmlApi = new HtmlApi(clientID, clientSecret,SERVICE_API_HOST);
String name = "inputHTML.html";// inpit Document name.
int width = 800; // Resulting image width.
int height = 1000; // Resulting image height.
int leftMargin = 10; // Left resulting image margin.
int rightMargin = 10; // Right resulting image margin.
int topMargin = 10; // Top resulting image margin.
int bottomMargin = 10; // Bottom resulting image margin.
// name of resultant file
string resultantFile = "Resultant.pdf";
try
{
// load the file from local drive
using (var file = System.IO.File.OpenRead(@"C:\Users\shahbnay\Desktop\" + name))
{
// Create StorageApi instance
var uploadFileRequest = new StorageApi(clientID, clientSecret, SERVICE_API_HOST);
// upload HTML file to Cloud storage
uploadFileRequest.UploadFile(file, "inputHTML.html");
}
// Perform the conversion to PDF format
// save the output to Cloud storage
AsposeResponse response = htmlApi.PutConvertDocumentToPdf(
name, resultantFile, width, height,
leftMargin, rightMargin, topMargin, bottomMargin);
// print success message if conversion is successful
if (response != null && response.Equals("OK"))
{
Console.WriteLine("HTML successfully converted to PDF !");
}
}catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment