Write Line: Object reference not set to an instance of an object. from pdf

Hello everyone.
I am working on a project where the BOT reads a pdf file and extract pieces of text from it. It has been a while since I worked on it last time and now it brings me this error: “Write Line: Object reference not set to an instance of an object.” I have already updated the dependent packages, but it persists. Does anybody know what it could be?
Thanks

Run the code in debug mode and check the value of variable that you are using in write line.

Looks like it brings something different from what I expect: “CastIterator { }”

Can you share pdf and regular expression you are using

Hi Nirjara,

The RegEx is: (Válida até )(\d\d(/)\d\d(/)\d\d\d\d)

And the piece of text in PDF is:

Emitida às 14:52:21 do dia 19/05/2022 <hora e data de Brasília>.
Válida até 15/11/2022.
Código de controle da certidão: 83B4.T2C7.9FBA.3W12
Qualquer rasura ou emenda invalidará este documento.

When I input the text in the Test Text it is captured, but when I run the code for some reason it doesn’t come.

Hello @mferrare is it possible for you to attach xaml file or screenshots.
screenshots should be of error message, full line of code of write line activity and local panel where value of that variable can be seen.

Write Line_issue.docx (319.5 KB)

Hi Akashay, please find attached the screenshots.

Thank you very much!

@mferrare your pattern is working fine for me.
The variable ValidDate is empty hence the write line code is failing with object reference because there is no data at index 0.
image

I believe there could be issue with the input string then.

Try below in log message:

System.Text.RegularExpressions.Regex.Match(strInputString,"Válida até ([0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4})").Groups(1)

let me know if this works for you or not . This pattern is handled for single digit dates as well.

if does not work then please attached a text with data from pdf file (do not copy paste manually) . PLEASE REMEMBER to replace PI (personal identifiable) data with junk data.

Hello Akshay
Thank you so much for your support. By doing this exercise I could realize that in some cases the text is captured and others no. Unfortunately I don’t have an Adobe Pro license to change the pdf files and share them. By simply copying two cases, one that works and another that doesn’t it is impossible to identify where the error is. Look below:

  1. This Works:
    Certidão emitida gratuitamente com base na Portaria Conjunta RFB/PGFN nº 1.751, de 2/10/2014.
    Emitida às 20:17:51 do dia 30/04/2019 <hora e data de Brasília>.
    Válida até 27/10/2019.
    Código de controle da certidão: 4FA0.FB09.6E89.A82E
    Qualquer rasura ou emenda invalidará este documento.

  2. This Doesn’t work:
    Certidão emitida gratuitamente com base na Portaria Conjunta RFB/PGFN no 1.751, de 2/10/2014.
    Emitida às 12:52:54 do dia 22/04/2022 <hora e data de Brasília>.
    Válida até 19/10/2022.
    Código de controle da certidão: E2F6.5E36.BE98.8E22
    Qualquer rasura ou emenda invalidará este documento.

I will continue investigating this. Thank you very much for your help! I really appreciate it!