Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active October 3, 2021 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-cloud/918593f25694b46f9eadef9be2b872e5 to your computer and use it in GitHub Desktop.
Save aspose-cloud/918593f25694b46f9eadef9be2b872e5 to your computer and use it in GitHub Desktop.
This gist contains code snippets related to HTML to XPS 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.xps";
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 XPS !");
}
}catch (Exception ex)
{
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
This gist contains code snippets related to HTML to XPS conversion using Aspose.HTML Cloud SDK for .NET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment