Make pdf readonly in perl

346 views Asked by At

I have a .pdf that contains alot of forms that i dont want the user to be able to edit.

Have tried CAM::PDF but i cant manage to load my pdf file into this. I only get a page with checkboxes but no text

This is how the pdf is supposed to look like:

-

This is how the file looks like from CAM::PDF

-

Does anyone know what i'm doing wrong? If i remove the setPrefs line i get the rigth pdf put without the settings i want.

Sample of code:

my $file = CAM::PDF->new($pdf_file_path);
$file->sefPrefs('', '', 1, 0, 1, 0);
$file->output('C:\temp\campdf.pdf');
$file->save();

EDIT: used pdftk, this had an option to flatten the pdf and made my pdf not editable.

2

There are 2 answers

3
iCanHasFay On

If you want read only try this.

chmod 0555, "example.pdf";
0
kbosak On

For anyone else with this problem, I was able to use CAM::PDF to make a PDF read-only:

$file->sefPrefs(undef, undef, 1, 0, 0, 0);

I believe if the 'copy' pref is set to true, the user can still edit the fields because they still have the option to "save a copy" but not to overwrite the original.

In my case I also had to do the following to get the form fields to properly fill out:

$file->getFormFieldList;   # I think this forces the fields to be cached but it wouldn't work without
...
$file->clean;