PDFTK not working to fill out pdf form created in livecycle

ぃ、小莉子 提交于 2019-12-21 04:39:39

问题


I created a form in livecycle es 2 and i am trying to use pdftk to fill out the form but it doesn't work. It says it fills it out successfully but when i try to open the pdf it just gives me an error saying "If this message is not eventually replaced by the proper contents of the document, your PDF viewer may not be able to display this type of document."

Below is the code i am using to fill out the pdf

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$Clicks = "567";
$Impressions = "43,434";
$Cost = "$45.44";

$fdf = '%FDF-1.2
1 0 obj<</FDF<< /Fields[
<</T(Clicks)/V('.$Clicks.')>>
<</T(Impressions)/V('.$Impressions.')>>
<</T(Cost)/V('.$Cost.')>>
] >> >>
endobj
trailer
<</Root 1 0 R>>
%%EOF';

file_put_contents('fields.fdf', $fdf);

$results = shell_exec("pdftk REPORT.pdf fill_form fields.fdf output FINAL_REPORT.pdf flatten");

After doing some research i found out that pdf forms created in live cycles are created as XFA forms and not acroforms. Not sure what the difference is, but has anyone done something similar and been able to get it to work.

Thank you


回答1:


There are two flavors of interactive forms in PDF:

  • AcroForm technology: in this case the form is defined using PDF syntax. All fields have fixed coordinates. They can't change dynamically. If data doesn't fit, fields don't grow. If there's less data then there is space, fields don't shrink. Forms like this are usually created using Adobe Acrobat, OpenOffice,...
  • the XML Forms Architecture: in this case, the PDF serves as a container for XML. The data is formatted as XML using a schema of your choice. The form is described using XML that corresponds with the schema of your data. As the XML is rendered at the moment the document is opened, forms can be very dynamic. They can adapt to the data (as opposed to AcroForms where the data has to adapt to the form). Forms like this are created using Adobe LiveCycle Designer.

In your question, I see that you're using the Forms Data Format (FDF). FDF is a format that is compatible with AcroForm technology. It's not compatible with XFA. To fill out an XFA form, you need to inject an XML file, not an FDF file.

PdfTk is a command line tool based on an obsolete version of iText. This version of iText dates from before XFA functionality was supported in iText. This means you won't be able to fill out a form created in LiveCycle using PdfTk.

As there is no business relationship between the creators of PdfTk and the owners of iText (me being one of these owners), there's very little chance that PdfTk will ever support XFA. iText Software offers a tool called XFA Worker, but that's a closed source add-on written on top of iText. I don't know of any open source tools supporting "XFA filling and flattening".




回答2:


I to am in the same boat. I've been using pdftk for almost 10 years to fill in a PDF form and then flatten it to a PDF file (with no form).

I just figured out today how to make this work with the latest version of LiveCycle Designer ES4 (v.11).

  1. File-> Form Properties-> Compatibility
  2. Click each Revert button
  3. Then you must save your PDF as Static PDF Form (NOT Dynamic XML Form)

Couple of screen shots.

Run your pdftk command as always and it should work.

I spent most of a morning on this very topic because I had to upgrade from LifeCycle v.8 (on an old XP VM) to LifeCycle v.11.




回答3:


I know it's been a while, but just in case someone is researching this, here's the way I solve this problem:

First, if you don't mind removing the XFA format from the file, thereby creating a new pdf 'template' to do your form fills with, then simply, remove extra XML data with the following command line:

"pdftk xfa-pdf-form.pdf output acro-pdf-form.pdf drop_xfa"

If this still gives you trouble, start over with the original XFA file and in LiveCylce save the the file as an Adobe Static PDF form. Or using Acrobat X Pro I think you can do this too. Then repeat the step above, by calling the command line to drop_xfa.

You should have a regular Acroform at this point.

From here you will be able to save the ouput file's data as an XFDF or FDF. Then it's business as usual.

Thanks to @enriquein, who pointing me in the right direction.



来源:https://stackoverflow.com/questions/24335279/pdftk-not-working-to-fill-out-pdf-form-created-in-livecycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!