Issues using HtmlInfo.ExternalResourcesBasePath for CSS

As the subject says, I’m having issues using HtmlInfo.ExternalResourcesBasePath for CSS links. The value I’m applying to that property is working when I apply it to HtmlInfo.ImgUrl.

So, imagine the following:

var basePath = “[http://domain](http://domain/)”;

var pdf = new Pdf {

HtmlInfo = {

ImgUrl = basePath,

ExternalResourcesBasePath = basePath,

}

};

var section = pdf.Sections.Add();

var text = new Text(section, htmlString) {

IsHtmlTagSupported = true,

IsHtml5Supported = true // tried with and without this

};

section.Paragraphs.Add(text);

The HTML I’m using to create the PDF has the following element in the tag:

…and the following element in the tag:

When I create a PDF, the image is properly found and loaded, but the CSS is NOT applied. If I view the page itself in a browser (without converting it to a PDF), the CSS IS applied.

I should also note that I’ve tried stripping “bootstrap.css” down to a couple simple styles to make sure something unsupported wasn’t breaking the use of the stylesheet, and it still didn’t work.

Am I missing something? Any direction or help would be greatly appreciated!

EDIT: I wrote this based on suggestions found on this page

Hi Nicholas,


Thanks for your inquiry. Please use new DOM approach for HTML to PDF conversion, pass basepath for image/css files to HtmlLoadOptions constructor as suggested in following documentation link. It will help you to accomplish the task.


Please feel free to contact us for any further assistance.

Best Regards,

Following the code example on that link: when I new up an HtmlLoadOptions() object, and attempt to set "UseNewConversionEngine" to "true", intellisense tells me that property is obsolete.

Is that code sample out of date, or is that still valid?

Hi Nicholas,


We are sorry for the inconvenience caused. Please ignore engine setting property. By default Aspose.Pdf.Document namespace uses new engine, It is depreciated now. We will update documentation very soon.

Best Regards,
This method worked! Thanks!

Hi Nicholas,


Thanks for your feedback. It is good to know that you have accomplished your requirement.

Please keep using our API and feel free to ask any question or concern. We will be more than happy to extend our support.

Best Regards,

Now that I’m using Document() instead of Pdf() to convert HTML, I’m struggling to force the output PDF to 8.5" x 11" page size. Any suggestions?


EDIT: Nevermind, figured out I needed to pass PdfSaveOptions when doing doc.Save() to get it to set the page size properly.

Hi Nicholas,


Thanks for sharing the feedback.

You may either consider following the steps give over following link to Update Page Dimensions. So you can use this approach before calling Document.Save(…) method.