Getting "Error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index(1)"

Hi, I’m getting the “Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index(1)” error, similar to the errors mentioned in Error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index(1) - #4 by mpkostek (PDFNET-54537) and "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index" (PDFNET-42179). The error is not consistently occurring. Is there any update on these?

Code:

                    MemoryStream outStream = new();
                    var pdf = new Document(new MemoryStream(convertRequest.FileData));
                    var fileEditor = new PdfFileEditor();
                    var scaleFactor = 1;
                    var parameters = new PdfFileEditor.ContentsResizeParameters(
                    PdfFileEditor.ContentsResizeValue.Percents(scaleFactor * 0), // Left margin
                    PdfFileEditor.ContentsResizeValue.Percents(scaleFactor * 100), // Width
                    PdfFileEditor.ContentsResizeValue.Percents(scaleFactor * 0), // Right margin
                    PdfFileEditor.ContentsResizeValue.Percents(scaleFactor * 0), // Top margin 
                    PdfFileEditor.ContentsResizeValue.Percents(scaleFactor * 100), // Height
                    PdfFileEditor.ContentsResizeValue.Percents(scaleFactor * 0));  // Bottom margin
                    fileEditor.ResizeContents(pdf, parameters);

                    foreach (var (page, annot) in
                    // Parse through all the annotations on each page and check for Link type annotations
                    from page in pdf.Pages
                    from annot in page.Annotations
                    where annot.AnnotationType == Aspose.Pdf.Annotations.AnnotationType.Link
                    select (page, annot))
                    {
                        // Delete the annotation
                        page.Annotations.Delete(annot);
                    }

                    var conversionOptions = new HtmlSaveOptions(HtmlDocumentType.Html5, true)
                    {
                        PartsEmbeddingMode = PartsEmbeddingModes.EmbedAllIntoHtml,
                        LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss,
                        RasterImagesSavingMode = RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground
                    };
                    // save PDF as HTML
                    pdf.Save(outStream, conversionOptions); <-- error here

@jdunning

The error may be related to the specific type of PDF document. Can you please share your sample PDF file with us so that we can test the scenario in our environment and address it accordingly?

dell 10k.pdf (3.3 MB)

Thanks; here is one file that has failed several times (and worked many more)

In our most recent test this file (above) failed 2 times in 42 tries, using version 23.8.0

@jdunning

We request you please test the case using 24.5.1 version of the API and let us know if you still notice any issues.

Thanks; I have noticed improvements with some files, but others like the attached consistently fail when they did work with version 23.8.
After-OCR-text-searchable.pdf (56.4 KB)

@jdunning

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-57468

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.

@jdunning

The issue was not reproduced when working on the generated test. Seems like the document attached by you does not correspond to the issue.

Attempts to reproduce the issue on a document containing LinkAnnotation did not result in errors.
A valid document is required. Would you please test the scenario with 24.9 version again and share the problematic PDF with us?

Thanks; I am no longer seeing this issue when using version 24.9.

@jdunning

Its nice to hear that your issue has been resolved. Please feel free to create a new topic in case you need any kind of assistance.