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

Free Support Forum - aspose.com

Css not referencing in pdf


I have a html template with relative path referencing of CSS

I created a pdf with HTML template but the style were missing in PDF.

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf1.Sections.Add();
section.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width;
section.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;
Aspose.Pdf.Generator.MarginInfo marginInfo = new Aspose.Pdf.Generator.MarginInfo();
marginInfo.Top = 10;
marginInfo.Bottom = 10;
marginInfo.Left = 5;
marginInfo.Right = 5;
section.PageInfo.Margin = marginInfo;
StreamReader r = File.OpenText(@“c:\users\xxx\PDFGeneration\PDFGeneration\HTMLTemplate\ReceiptTemplate.html”);
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
text2.IsHtmlTagSupported = true;
pdf1.HtmlInfo.ExternalResourcesBasePath = @“path to css”;
//Save the pdf document

Am i missing some thing here. I am using a trial version dll. Is it something to do with that?


Hi Kannappan,

Thanks for your inquiry. Please check following documentation link of HTML to PDF conversion using new DOM approach, you may pass basepath to HtmlLoadOption() constructor for referring external resources e.g Fonts/Images/CSS. Hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,