New Aspose.Pdf.Document XSLFO file to PDF

ASPOSE.PDF NET version 23.8.0
.NET 6.0

For some of our XSLFO to PDF transformations, we are seeing the following exception. I am guessing there is some issue with the data in the problematic XML entries, but cannot determine from the exception trace what those may be.

System.ArgumentOutOfRangeException: ‘Index was out of range. Must be non-negative and less than the size of the collection. (Parameter ‘index’)’.

Code snippet below:

        XsltArgumentList xsltArgumentList = new XsltArgumentList();
        xsltArgumentList.AddParam("path", "", @"C:\\Git\\hni_svn\\HNI.WebApp\\App_Themes\\2016\\images\\");
        xsltArgumentList.AddParam("dateOfService", "", "08/06/2023");
        xsltArgumentList.AddParam("imgPath", "", signatureFileName);


        XslCompiledTransform transform = new XslCompiledTransform(true);
        using (XmlReader reader = XmlReader.Create(new StreamReader(@"c:\\supportXslt.xml")))
        {
            transform.Load(reader);
        }

        string transformedFoXsl = string.Empty;


        using (StringWriter xmlWriterResults = new StringWriter())
        using (XmlWriter xmlWriter = XmlWriter.Create(xmlWriterResults, settings))
        using (XmlReader reader = XmlReader.Create(new StreamReader(@"c:\\support.xml")))
        {
            transform.Transform(reader, xsltArgumentList, xmlWriter);
            transformedFoXsl = xmlWriterResults.ToString();
            File.WriteAllText(xsltFileName, transformedFoXsl);
        }

        Aspose.Pdf.Document AsposePdfDocument2 = new Aspose.Pdf.Document(xsltFileName, new XslFoLoadOptions());

Here are the XML and XSLT filesSupportFiles.zip (28.6 KB)

@juleshnihc

While testing with 23.7 (as it is the latest one at the moment), we faced a different exception i.e. “System.Xml.XmlException: ‘There is no Unicode byte order mark. Cannot switch to Unicode.’”.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-55266

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

It looks like there is a bug in the Aspose.PDF library.

I posted a PHI cleaned version of our XML/XSL to their support forum. And they responded by creating a new issue.

I am seeing if there is some change we can make to our data that gets around the issue

~WRD0002.jpg (357 Bytes)

@juleshnihc

We really apologize for the inconvenience you have faced. Please note that we have logged this ticket in order to further investigate the reasons behind this issue and we will rectify it as soon our investigation is done. We will inform you via this forum thread once the issue is fixed. Please be patient and spare us some time.

We apologize for the inconvenience.

Thanks.

Is there something I can change about the XML or XSLT files, that would act as a workaround?

Jules

@juleshnihc

We are afraid that we cannot offer any workaround at the moment without completing the investigation of the ticket. As soon as analysis is done, we will be able to share some feedback with you. We will surely inform you once we have some updates in this regard. We apologize for the inconvenience.

@juleshnihc

  1. The ouput XSLT is in UTF-16 encoding instead of UTF-8 as its a default encoding for StringWriter. To avoid this, you can modify the code snippet:

Instead of:

using (StringWriter xmlWriterResults = new StringWriter());

Use:

using (StringWriter xmlWriterResults = new UTF8StringWriter()) 
public class UTF8StringWriter : StringWriter
{
   public override Encoding Encoding
   {
     get
        {
         return Encoding.UTF8;
        }
   }
}
  1. After the fix, the exception will be changed to: Unhandled Exception: “System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.”

The reason for this exception is the errors in supportXslt.xml:

  • In line 932, the attribute “number-columns-spanned” could not be more than 16 as there are only 17 columns in this table, and one cell already exists.
  • In line 999, the attribute “number-columns-spanned” could not be more than 2 as there are only 3 columns in this table, and one cell already exists. (In some situations, lines 1025, 1070, and 1040 also could raised the exceptions).
  • In line 1438, the attribute “number-columns-spanned” could not be more than 1 as there are only 2 columns in this table.

Hey Asad.

Thanks for you reply. I should be able to fix the source xslt for the exceptions in the supportXslt example.

For our other xslt documents, is there a way we can get the line numbers of problems in the XML on our end.

Currently, all we get from Aspose is the runtime ArgumentOutOfRangeException when a failure occurs.

Thanks

@juleshnihc

Thanks for the feedback. We have recorded your question along with the ticket and will write you back after checking related details.