Error on Sign with TPAdES some PDF Files.

I have this error on some PDF files...
'' is not a valid integer value.

at this point...

r000107j.pdf (67.1 KB)
function TPAdES.FirstPart(ts: TStringList): string;
var
dateT, timeT, temp: string;
d: TDateTime;
i: integer;
begin
Ffirstobjnumber := StrToInt(ExtractNumber(copy(ts.Strings[0], 0,Pos(' ', ts.Strings[0]))));

This pdf files are generated (exported) from CrystalReports by SAP.

image

program

The string contains characters that are not digits. You may have to investigate the exact content of the strings and possibly add extra conditions before you extract it to eliminate some characters before they are conveted to a number.

But the error is on TPades Class, how could i resolve this?
Try to sign the attachment r000107j.pdf to see where the error occur.

I could reproduce the error and will investigate.

Here is a fix for PAdESObj.pas.

In function TPAdES.FirstPart(ts: TStringList): string;

Replace

begin
Ffirstobjnumber := StrToInt(ExtractNumber(copy(ts.Strings[0], 0, Pos(' ', ts.Strings[0]))));

By
s: string; // add this definition to the var section
begin
s := copy(ts.Strings[0], 0, Pos(' ', ts.Strings[0]));
if System.Character.IsDigit(s[1]) = true then
Ffirstobjnumber := StrToInt(ExtractNumber(copy(ts.Strings[0], 0, Pos(' ', ts.Strings[0]))))
else begin
i := Pos(' ', ts.Strings[0]);
s := ts.Strings[0].Substring(i, ts.Strings[0].Length);
Ffirstobjnumber := StrToInt(ExtractNumber(copy(s, 0, Pos(' ', s))));
end;

I signed your file with this change and my USB token. The issue was there is an extra ' ' in the string before what we need to extract and this raised an exception as the extracted substring could not be converted to a number.

Let me know if it works on your side.

bernard

Correction:

if System.Character.IsDigit(s[s.length - 1]) = true then

1 Like

Thank you, now its working!
I add the uses of unit: System.Character - that was necessary to find the function (System.Character.IsDigit).

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.