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