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:
textBuilder.AppendText(textFragment);

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)

Thanks,
Karl

public void VerifyBug()
{
     var fs = File.OpenRead(@"C:\tmp\PDF_1.pdf");
     var contentEditor = new Aspose.Pdf.Facades.PdfContentEditor();
     contentEditor.BindPdf(fs);
     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");
          textFragment.Segments.Add(segment1);
          Aspose.Pdf.Text.TextBuilder textBuilder = new Aspose.Pdf.Text.TextBuilder(pdfPage);
          textBuilder.AppendText(textFragment);
     }
          
     contentEditor.Document.OptimizeResources();
     contentEditor.Save(@"C:\tmp\output.pdf");
     contentEditor.Dispose();
     fs.Dispose();
}

@ka.broden
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!

@sergei.shibanov We’re now on paid support, is there any way I could transfer this ticket to paid support in order to hopefully get it prioritized?

Regards,
Karl

@ka.broden
You can use your Paid Support Account/Subscription and post a query in your Paid Support Helpdesk to raise the priority of PDFNET-53941. You also just needs to mention the link Appending a TextFragment to TextBuilder gives an IndexOutOfRangeException while creating a new thread at Paid Support Helpdesk (No need to explain his issue all over). Helpdesk team will then take it over.

1 Like