Giving reference of css on local drive or online

Hi All,

I have created a console application(C#) in Visual Studio and I have test folder on my C drive.

I have also kept a html file on my C drive and my code reads the html file and generates a pdf file at the same location.

I issue is that I have also kept a test.css file and I am trying to use this in my pdf generation but it is not working.

Path : C:\Test

I already tried to add reference of the css file in my html file like this -

< link type="text/css" rel="stylesheet" href="../styles.css" > OR 
 < link type="text/css" rel="stylesheet" href="C:\Test\styles.css" > OR 
< link type="text/css" rel="stylesheet" href="https://mysite/styles.css" >

but none of this works, please help

@jinivthakkar

I would like to share with you that you can use any css file while converting an HTML file to a PDF file. I have attached a sample HTML, CSS file, generated output file and the sample code to work with it.

        HtmlLoadOptions options = new HtmlLoadOptions(@"D:\Sample\");
        // Load HTML file
        Document doc = new Document(@"D:\Sample\source.html", options);
        // Save HTML file
        doc.Save(@"D:\Sample\Aspose_17.11.pdf");

Sample.zip (65.2 KB)

For further information on HTML to PDF conversion, please visit this documentation article for your kind reference.

I hope this will be helpful. Please let us know if you need any further assistance.

Getting this error -
At most 4 text fragments can be added in evaluation mode.Does this mean that I can have only 4 style attributes ??

@jinivthakkar

Thanks for writing back.

You are getting this error due to limitation of using trial version of the API. In trial version, you can only process only 4 elements of any collection (e.g Pages, Annotations, Paragraphs, etc.). In order to have full access to all features of the API, please consider applying for a temporary license, by using which you can evaluate complete features of the API.

In event of any further query, please feel free to ask.

I had gave the license reference and it worked thanks !

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);

@jinivthakkar

Thanks for sharing your feedback.

It is good to know that your issue has been resolved by suggested approach. Please keep using our API and in event of any further query, feel free to ask.