Using CAM::PDF For Perl - Can I Read Text From A (v1.7) Password-Protected PDF File?

StackOverflow https://stackoverflow.com/questions/16821585

  •  30-05-2022
  •  | 
  •  

Question

I noticed the CAM::PDF Perl module is built to read the text from a PDF file. Right now I have CAM::PDF v1.59 installed. I've successfully used it to read text from a (v1.2) PDF file that is not password protected, but when I try to open a (v1.7) password-protected PDF file using this code...

use strict;
use warnings;
use PDF::API2;
use CAM::PDF;
use CAM::PDF::PageText;

my $file = 'C:\Users\gwilliams\Documents\PWS20130517new.pdf';

my $pdf = CAM::PDF->new($file, '-', '-', 's3cretpasswd', fault_tolerant => 1)
  or die "$CAM::PDF::errstr\n";

my $pageone_tree = $pdf->getPageContentTree(1);

print CAM::PDF::PageText->render($pageone_tree);

... I receive the error message:

Invalid xref stream: could not decode objstream 3085

The attributes of the PDF file itself are:

  • Version: 1.7
  • Security Method: Password Protection
  • Printing: Not Allowed
  • Fill In A Form: Not Allowed
  • Commenting: Not Allowed
  • Manage Pages: Not Allowed
  • Modify Document: Not Allowed
  • Content Copying: Not Allowed
  • Extract Contents: Not Allowed
  • Signing: Not Allowed

For what it's worth - it looks like the PDF in question was created with Adobe PDFMaker 10.1 for Excel.

What gives? Am I doing this right - or is the PDF incompatible with CAM::PDF?

Sincerely, Confused

Was it helpful?

Solution

I'm the author of CAM::PDF. It's probably an newer PDF feature that CAM::PDF doesn't support. I wrote the encryption support back in PDF 1.2 days and have barely updated it since. So most likely it's not your fault but is a limitation of the library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top