Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

converting pdf form to pdf document

by jonnyfolk (Vicar)
on May 30, 2008 at 17:22 UTC ( #689283=perlquestion: print w/replies, xml ) Need Help??
jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using CAM::PDF to generate a completed pdf form, following node: Filling out PDF forms with data from DBI? However to send it I want to remove the editable fields and convert it into a pdf document. Can anyone help me to do this, please?
#!/usr/bin/perl # use strict; use warnings; use CAM::PDF; # my $infile = 'input.pdf'; my $outfile = 'output.pdf'; my $pdf = CAM::PDF->new($infile) or die 'wtf'; my @FIELDS = $pdf->getFormFieldList(); # foreach ( @FIELDS ) { my $fieldnum = $_; $pdf->fillFormFields($_ => $fieldnum); } $pdf->cleanoutput($outfile);
Update: I used the following code to achieve this:
$pdf->clearAnnotations(); $pdf->cleanoutput($outfile);

Replies are listed 'Best First'.
Re: converting pdf form to pdf document
by zentara (Archbishop) on May 30, 2008 at 18:22 UTC
    Just a quick glance at the CAM-PDF examples, especially, shows an option
    -C --clearannots remove all annotations (including forms)
    I don't know if that will do the trick, but you might want to look at the examples. The man pages also talk about $self->clearFormFieldTriggers(fieldname, fieldname, ...)

    I'm not really a human, but I play one on earth CandyGram for Mongo


      Thanks very much for your input - you were bang on the money!

      I've annotated the code in the OP for clarity.

      The only reservation I have is that in one set of form fields the input text is right justified whereas that is ignored on using the clearannots, leaving the layout slightly deficient. I suppose that the right justification is in itself an annotation - can I exempt it?


Re: converting pdf form to pdf document
by almut (Canon) on May 30, 2008 at 20:45 UTC

    Not a Perl solution, but if all else fails, you could try pdftk's flatten option (worked fine for me so far)

    $ pdftk filled-form-doc.pdf output flat-doc.pdf flatten


    [flatten] Use this option to merge an input PDF's interactive form fields (and their data) with the PDF's pages. Only one input PDF may be given. Sometimes used with the fill_form operation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://689283]
Approved by MidLifeXis
Front-paged by MidLifeXis
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-03-24 20:53 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (299 votes). Check out past polls.