pdf-raku / PDF-Class-raku

PDF Document Object Model (under construction)
Artistic License 2.0
7 stars 3 forks source link

Error Converting Int to UInt #21

Closed tsalada closed 1 year ago

tsalada commented 1 year ago

I have a script that uses PDF::API6 to extract pages from a larger PDF. For one particular file I'm getting an endless series of errors about coercing Int to UInt. when I run pdf-checker --repair here is what the errors look like

Warning: unable to coerce object -167 of type Int to UInt Warning: unable to coerce object -167 of type Int to UInt Error in 4649 0 R (PDF::Annot::Link) /StructParent entry: Int.StructParent: -167 not of type: UInt

It seems that coercing an Int to a UInt is something that should be easy. I upgraded to the latest modules available with not change. I'm running Ubuntu Linux 20.04.5

dwarring commented 1 year ago

pdf-checker is complaining because it's expecting a UInt (non-negative integer) for /StructParent entries, but the above example it's getting a negative value -167.

I rechecked Annotations (table 164 in the spec). I think the error is valid. These values are an array index and shouldn't be negative.

Although pdf-checker being a bit spammy and reporting multiple warnings, before it finds the error.

dwarring commented 1 year ago

Where are the errors coming from in the first place?

dwarring commented 1 year ago

The pdf-append script produces this warning, if I add a negative /StructParent to a PDF Annotation. It probably shouldn't.

$ raku -I . bin/pdf-append.raku /tmp/pdf-annot.pdf  /tmp/pdf-annot.pdf
unable to coerce object -1 of type Int to UInt
  in method coerce-to at /home/david/git/rakudo-main/install/share/perl6/site/sources/5E3ADB461D8B2C83796E0BC14B0BE93B46986FFF (PDF::COS::Coercer) line 62
unable to coerce object -1 of type Int to UInt
  in method coerce-to at /home/david/git/rakudo-main/install/share/perl6/site/sources/5E3ADB461D8B2C83796E0BC14B0BE93B46986FFF (PDF::COS::Coercer) line 62
unable to coerce object -1 of type Int to UInt
  in method coerce-to at /home/david/git/rakudo-main/install/share/perl6/site/sources/5E3ADB461D8B2C83796E0BC14B0BE93B46986FFF (PDF::COS::Coercer) line 62
dwarring commented 1 year ago

Warning is useless anyway, it doesn't indicate where in the PDF the problem is.

dwarring commented 1 year ago

@tsalada - I've removed those warnings. They were being produced while the PDF objects were being copied.

pdf-checker (as you've already noticed) can be used to find an errors in the input PDF anyway.

Please upgrade to the latest PDF 0.5.4, which I've just uploaded to the zef ecosystem. This release suppresses those warnings.

tsalada commented 1 year ago

This worked. I was able to extract the pages I needed. Thanks.