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

Free Support Forum - aspose.com

Appending a TextFragment to TextBuilder gives an IndexOutOfRangeException

I have code that modifies a pdf by adding a TextFragment to TextBuilder. It works for most PDFs but for this specific PDF it throws an IndexOutOfRangeException on the line:

Any ideas what could be the reason?
I’m using Aspose PDF version 22.7 but also tried and verified on 23.2
File “PDF_1.pdf” is attached, testmethod below:
PDF_1.pdf (4.1 MB)


public void VerifyBug()
     var fs = File.OpenRead(@"C:\tmp\PDF_1.pdf");
     var contentEditor = new Aspose.Pdf.Facades.PdfContentEditor();
     for (int i = 0; i < contentEditor.Document.Pages.Count; i++)
          var currentPageNumber = i + 1;
          Aspose.Pdf.Page pdfPage = contentEditor.Document.Pages[currentPageNumber];
          double maxX = pdfPage.Rect.URX;
          maxX -= 50;
          //Create text fragment
          Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment();
          Aspose.Pdf.Text.TextSegment segment1 = new Aspose.Pdf.Text.TextSegment();
          segment1.Text = "Indicates R  in µm";
          segment1.Position = new Aspose.Pdf.Text.Position(maxX - 470, 178);
          segment1.TextState.FontSize = 8F;
          segment1.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Helvetica");
          Aspose.Pdf.Text.TextBuilder textBuilder = new Aspose.Pdf.Text.TextBuilder(pdfPage);

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

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.

Thanks Sergei!