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

Free Support Forum - aspose.com

ArgumentOutOfRangeException when converting html into a pdf document

Hi,
I’m using the Aspose.pdf for .Net version 19.2 when I go to generate a pdf from an Html using the Aspose.Pdf.Document constructor I am getting the following exception.

System.ArgumentOutOfRangeException
Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index

I have worked out that this exception is caused by the table in the HTML having too many columns. I also have included an example of the code and a test file which causes the exception above.
TestFile.zip (4.1 KB)

public void TestPdfGeneration (string sHtml, string sPath)
    {
        itErrorStore oErrors = new itErrorStore();
        try
        {
            Aspose.Pdf.HtmlLoadOptions oOptions = new Aspose.Pdf.HtmlLoadOptions(sPath);
            using (Stream oStream = GenerateStreamFromString(sHtml))
            {
                Aspose.Pdf.Document oDocument = new Aspose.Pdf.Document(oStream, oOptions);
            }
        }
        catch (Exception oException)
        {
            itErrorStore.Add(oErrors, oException);
        }
    }

    public static Stream GenerateStreamFromString(string sString)
    {
        MemoryStream oStream = new MemoryStream();
        StreamWriter oWriter = new StreamWriter(oStream);
        oWriter.Write(sString);
        oWriter.Flush();
        oStream.Position = 0;
        return oStream;
    }

@Georgem99

Thanks for contacting support.

We were able to replicate the issue in our environment using Aspose.PDF for .NET 19.3 and for the sake of correction, we have logged it as PDFNET-46218 in our issue tracking system. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-46218) have been fixed in Aspose.PDF for .NET 21.12.