Error Finding Text in a PDF

I am trying to find text in a PDF (a credit card statement) and coming up against this error. Can you help?

System.NullReferenceException: Object reference not set to an instance of an object.
at #=zl_AQ_qrFxdfFXmDtg6cJHcin9w2oV3Cb60DIBaMM9lX65T3bj4ijl3j8e6vF$3py5WlvBoTlHspB.#=zTYxPGwE=(String #=z3pYKSpY=, #=zNnZKUM1IXHHjum$VoZx63wPG2DKpbVJS_6ifnKU= #=zoF0XDTs=, #=zVCpWUBUoqHMQ2zfntTiDaW1R8G10sXdSaX7riY90Y2ANA4kD$KZ5GAE= #=z1wTDHm4TWbF4, Boolean #=zzT4SO3g=, Boolean #=zQNplf2g=, #=z7y4eZJDONGUVDEUZoiijkdIPrs21ljFa4g==& #=zVTrmqx0=, #=zaMPLq29GnytDlsw_a9$mM_BWDYkg3xtUYmoCVkR7HxMa& #=ztDFRTuL95Gxe, String& #=zyLmqEq$suHLC)
at #=z_uXQUUTOD1x0nWp6D5Ny5P_Ud84xmgtQvCFQGAXdzDji1A0vbwxk8bI=.#=zK1r187Y=(#=z7OYuAG6f2B6JknBGFTA5vPmZDzAdTGVbDLxd$32iJxvogrj2pKiz48P_UIFpEGckMNKf77xqBmgjN9WOzQ==[] #=zPv3c0_QV7PBFmtNIVU4OIAiaiMR_, String #=z3pYKSpY=, #=zNnZKUM1IXHHjum$VoZx63wPG2DKpbVJS_6ifnKU= #=zoF0XDTs=, #=zVCpWUBUoqHMQ2zfntTiDaW1R8G10sXdSaX7riY90Y2ANA4kD$KZ5GAE= #=z1wTDHm4TWbF4, Boolean #=zzT4SO3g=, Boolean #=zQNplf2g=, #=z7y4eZJDONGUVDEUZoiijkdIPrs21ljFa4g==& #=zVUAvuoQ=, #=zaMPLq29GnytDlsw_a9$mM_BWDYkg3xtUYmoCVkR7HxMa& #=ztDFRTuL95Gxe, String& #=zyLmqEq$suHLC)
at #=zigVcVy0kF4TRalKjQfSZwQEu01C2FiCwAv6DHIbR37Ye_jdeiA==.#=z4W9TDa5Z3NEY(#=zgX_GgPP22sc_RMe$90kwmwSO5amZ5TcBZg== #=zl_449hg=, TextEditOptions #=zds9OORg=)
at Aspose.Pdf.Text.TextSegment.set_Text(String value)
at Aspose.Pdf.Text.TextFragment.set_Text(String value)

@stevenamani

Can you please share the source PDF file and code so that we may try to reproduce the same on our end.

Please find file attached. The text I am trying to redact is 422691000727 in the document. Here is the code that I am using:
` Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber(“422691000727”);
pdfDocument.Pages.Accept(textFragmentAbsorber);
Aspose.Pdf.Text.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (var frag in textFragmentCollection)
{
try
{
frag.Text = new string(‘X’, frag.Text.Length); //error gets thrown here or the text ends up underlined and not replaced
}
catch (Exception) { }

                    frag.TextState.BackgroundColor = redactColor;
                    frag.TextState.ForegroundColor = redactColor;
                    totalInstances++;

                }`

test_org.pdf (120.8 KB)

@stevenamani

I can not reproduce the exception with your code and file. I request you to install latest version and share your feedback.

Ok I will give that a try.

I updated my project to v21.7 and I am still having this issue. If you look at the attached image, instead of changing the fragment’s text and color, it is simply adding an underline…

Screen Shot 2021-07-16 at 4.11.13 PM.png (102 KB)

@stevenamani

I have been able to reproduce the issue on our end. A ticket with ID PDFNET-50222 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.