We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Html to PDF CSS Example


I seem to be missing something. I have attempted several tests and I cannot seem to get the external css to link up with my html file using aspose pdf.

Pdf pdf = new Pdf();
//Set Page Size
pdf.PageSetup.PageHeight = PageSize.LetterHeight;
pdf.PageSetup.PageWidth = PageSize.LetterWidth;
var margins = new MarginInfo();
margins.Top = 36;
margins.Left = 36;
margins.Right = 36;
margins.Bottom = 36;
pdf.PageSetup.Margin = margins;
pdf.HtmlInfo.ExternalResourcesBasePath = “C:/Users/Administrator/Documents/Visual Studio 2012/PDFTest/Content/html/”;
// load the HTML file to Stream object
using (Stream htmlAsStream = File.OpenRead(“C:/Users/Administrator/Documents/Visual Studio 2012/Projects/PDFTest/Content/html/index.html”))
// bind the source HTML
pdf.BindHTML(htmlAsStream, “”);
// save the PDF file

my html file contains the following link ref =

I have also referenced several different examples on the Aspose website and they don’t help.


Hi Grant,

Thanks for your inquiry. Please check DOM approach for HTML to PDF conversion. You can pass a path argument as a string to HtmlLoadOption object for css/images database. Please check following code snippet for the purpose. Hopefully it will help you to accomplish the task.

// Specify the The base path/url for
the html file which serves as css/images database

String basePath = "E:/temp/";

HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);

// load HTML file

Document doc22 = new Document("E:/temp/Input.html", htmloptions);

// Save HTML file


Please feel free to contact us for any further assistance.

Best Regards,