Trying to add style sheet to the pdf in aspose.pdf for .NET

I am trying to add style sheet to the PDF and I couldn’t load it to the PDF. Could you please help me??

//this is my convert method

   public List<byte[]> Convert(ContentsDto content, IDictionary<string, string> options, Func<DependentContent, Task<ContentsDto>> GetDependency = null)
    {

        var pdfBytearray = new List<byte[]>();
        License htmlLicense = new License();
        //htmlLicense.SetLicense("Aspose.HTML.NET.lic");
        //Manipulate html document 

        HtmlDocument htmlDocument = new HtmlDocument();
        using (var htmlStream = new MemoryStream(content.Data))
        {
            htmlDocument.Load(htmlStream);                
            AddCssLinks(options, htmlDocument);
        }

        HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions() { CustomLoaderOfExternalResources = Invoke, HtmlMediaType = HtmlMediaType.Print };
        
        using (var streamProvider = new MemoryStream(content.Data))
        {
            //convert html to pdf
            
            Document pdfDocument = new Document(streamProvider, htmlLoadOptions);

            //convert pdf to pptx 
            PptxSaveOptions pptx_save = new PptxSaveOptions();
            using (var pptxStream = new MemoryStream())
            {
                pdfDocument.Save(pptxStream, pptx_save);
                pptxStream.Seek(0, System.IO.SeekOrigin.Begin);
                pdfBytearray.Add(pptxStream.ToArray());
            }
        }


        return pdfBytearray;
    }

//this is my AddCssLinks method

private HtmlDocument AddCssLinks(IDictionary<string, string> options, HtmlDocument htmlDocument)
{
if (options.TryGetValue(ContentsConstants.CONVERT_OPT_CSS, out string cssReference))
{
var links = cssReference.Split(’,’, ‘|’);
foreach (var link in links)
{
var linknode = htmlDocument.CreateElement(“link”);
linknode.SetAttributeValue(“href”, link);
linknode.SetAttributeValue(“rel”, “stylesheet”);
var htmlHead = htmlDocument.DocumentNode.SelectSingleNode("//head");
htmlHead.AppendChild(linknode);
}
}
return htmlDocument;
}

@nethmi

Could you please attach the following resources here for testing:

  • Your input PDF.
  • Please attach the output PDF file that shows the undesired behavior.
  • Please attach the expected output PDF file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.