pdftk-php Officially Released

Wow. It’s been almost two years since I wrote a little tutorial on how to use LiveCycle, PHP, and MySQL together to make a web application that served dynamic PDF forms. Since then it has become the number one page on this site. I still get a substantial number of comments a week here on the blog and via e-mail—many of those comments are stuck in my inbox, sent to me before I rebuilt my site on WordPress and enabled commenting.

Unfortunately, though, I wrote that tutorial as my first foray into the world of PHP/MySQL web development and had little idea of what I was really doing. Since then, however, I’ve done a fair amount of real-world web design and development, and even implemented this pdftk form system into a live, public-facing application.

In the interim, I’ve refined my system and released it as an open source PHP class, named pdftk-php. The project is hosted at GitHub, a brilliant hosting service for collaborative projects, which uses Git, the best version control software I’ve ever used. Anyone can check out, or clone, the project, make any edits to the core set of classes, and merge those with the main project branch—it is now a true community project. If you don’t want to contribute, you can still download it from GitHub as a .zip or .tar file.

Included in the project is a (hopefully) extensively documented example application that you can set up on your own server. You can try a live working example at pdftk-php.andrewheiss.com.

I’m working on writing a new step-by-step tutorial on how to set everything up, akin to the old one. In theory, the new pdftk-php should work with PDFs created in any program, not just LiveCycle. In the meantime, download pdftk-php, try it out, and report any bugs here on the blog or directly at GitHub (where I hope to keep everything related to pdftk-php from now on). Fork the project and contribute if you feel like it, too!

Thanks and good luck!

  • Hi Andrew,

    Thank you. I have almost everything working. I think have installed everything as described. However, I have an interesting situation. The example PDF opens up when I download the information inserted into sql. The example PDF is blank. However, as soon as I close this PDF the newly named PDF opens and says it is corrupted. The FDF file looks good. I can open the FDF file with the example pdf manually and everything displays great! However, for some reason the the FDF and the example are not correctly linking.
    Any ideas?
    I went to the command prompt and the pdftk.exe works fine.

    Here are two errors that I see in my apache log

    [Sun Jun 28 20:43:52 2009] [error] [client 127.0.0.1] PHP Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\www\pdftk-php.php on line 77, referer: http://127.0.0.1/view.php

    I also get this error but the database and data seems to be ok
    [Sun Jun 28 20:50:05 2009] [error] [client 127.0.0.1] PHP Notice: Undefined index: submitted in C:\Program Files\www\index.php on line 48, referer: http://127.0.0.1/index.php
  • I just responded to someone with a similar question here

    In short, your script can't run pdftk for some reason, probably because the path in passthru() is set wrong. Check the path, and try running just "pdftk --help" in passthru() to see if you get any output until it works. See the other comment for better instructions.

    Good luck! Let me know if that doesn't fix it...
  • Mak

    Hi Andrew,


    I am having a similar type of problem running pdftk from php script. It works fine from command line but dosen't work from php script. below is the passthru I am using. pdftk is installed in /usr/sbin/.


    passthru("/usr/sbin/pdftk --help");


    Thanks in advance
    Mak

  • Hedgehog
    Hi Thank you,

    Yes part of the problem on the windows system was the path name. You can't have spaces... Doh!

    I did a little more trouble shooting.

    I wrote a test.php file with the following


    this works as I get a return of
    "pdftk 1.41 a Handy Tool for Manipulating PDF Documents Copyright (C) 2003-06, Sid Steward - Please Visit: www.pdftk.com......."

    So assume the passthru is working?

    When I change the pdftk-php.php and made sure it had the proper file location.

    passthru("c:\www\pdftk.exe $pdf_original fill_form $fdf_fn output - flatten");

    I get this error in my apache log...

    Unhandled Java Exception:
    java.io.CharConversionException
    at 0x0056175e (Unknown Source)
    at 0x00561c52 (Unknown Source)
    at 0x00561d03 (Unknown Source)
    at 0x0057692d (Unknown Source)
    at 0x0055f64d (Unknown Source)
    at 0x006bc0ad (Unknown Source)
    at 0x006994e0 (Unknown Source)
    at 0x00567a96 (Unknown Source)
    at 0x0056e8f2 (Unknown Source)
    at 0x0056e92c (Unknown Source)
    at 0x00445fa6 (Unknown Source)
    at 0x0048b15e (Unknown Source)
    at 0x0048b5b8 (Unknown Source)
    at 0x0048c238 (Unknown Source)
    at 0x0046c81f (Unknown Source)
    at 0x00469301 (Unknown Source)
    at 0x004666a6 (Unknown Source)
  • I think the pdftk.exe can't parse the new livecycle form.. I can do the command prompt and have it parse your example.pdf and have it out =put
    ---
    FieldType: Text
    FieldName: firstname
    FieldFlags: 0
    FieldJustification: Left
    ---
    FieldType: Text
    FieldName: lastname
    FieldFlags: 0
    FieldJustification: Left
    ---
    FieldType: Text
    FieldName: email
    FieldFlags: 0
    FieldJustification: Left

    However, for my forms (created in adobe livecyle ES 8.2) if they are created as "dynamic" pdftk won't work. If i create them as static pdftk will open them up and give you something like this.

    The issue is that all of our forms are dynamic meaning pdftk won't work?...


    example static:
    ---
    FieldType: Text
    FieldName: form1[0].#subform[0].Name[0]
    FieldNameAlt: Name
    FieldFlags: 0
    FieldJustification: Left
    ---
    FieldType: Text
    FieldName: form1[0].#subform[0].City[0]
    FieldNameAlt: City
    FieldFlags: 0
    FieldJustification: Left
  • Yeah, the Java errors you are getting are because pdftk is choking on your PDF (passthru() is working just fine now)

    This could be because of fonts you have embedded in the PDF or because it's a newer version of the PDF standard. Try backsaving your form as a version 1.5 or 1.6 PDF (in the advanced options of the save dialog, hopefully) and try again.

    Because you're getting character exceptions, I'd guess there's a problem with an embedded font. Try changing all the fonts to something uber universal like Times New Roman or Arial and take out any foreign characters you might have and see if that helps.

    Also, check the new Troubleshooting page for more details.
  • Thank you. I would put that troubleshooting as part of your install instructions or at least a link to it. Also as part of the install I would make it clear to download pdftk.

    I finally got my linux box passthru working properly. I used the same pdf and got no java errors on the linux version of pdftk. For some reason the linux version of pdftk can handle different fonts than the windows version?....

    Here are my two pdf's one is static and one is dynamic. The pdftk doesn't work on any dynamic pdf's but works great on static pdfs

    http://www.pathway2curis.com/pdf/Dynamic.pdf
    http://www.pathway2curis.com/pdf/static.pdf

    Is this a limitation of pdftk?

    Blurb from a website
    http://www.appligent.com/adobeaccessibility/Ado...

    Static forms present a fixed set of text, graphics, and fields at all times, regardless of the amount of data merged with the form. If more data is available than the static form was designed to hold, the excess data is not displayed in the rendered form. Conversely, if less data is available than the static form was designed to hold, the excess space is left blank in the rendered form.
    Designer enables you to create dynamic interactive forms that users open and fill online with Acrobat or Adobe Reader. Dynamic interactive forms combine both dynamic and interactive form functionality such that users can enter data directly into expandable fields, add or remove sections, and return the form data electronically.
    Unlike a static interactive form, which has a fixed layout (format and length), the layout of a dynamic interactive form adjusts according to the amount of data the user enters into the various fields and the number of items they add or remove. For example, in the sample dynamic interactive Purchase Order form, users can add or remove item rows, and choose to add their comments to the form. In either case, the layout of the form adjusts to accommodate the changes.
    Creating dynamic interactive forms involves implementing the same features and methods you use to create static interactive forms. However, to add dynamic functionality to interactive forms,you also work with master pages, content areas, and subforms to control how Designer lays down objects in the form as the form adjusts to display varying amounts of data.
  • I just finished updating the project's documentation wiki at Github, with troubleshooting instructions gleaned from several years of e-mails and comments from other people, so that should cover most main issues.

    And, yeah, I think the issue with static vs. dynamic pdfs is a limitation of pdftk. It hasn't been updated in a few years, so dynamic forms were probably invented after the latest version.
  • Thank you. I emailed "Sid" and asked him about the dynamic forms & PDFTK

    Also I had the call the forge_php file in order to make my static livecycle forms work. With your example.pdf I didn't have make any changes to the code (only the ones listed in your install instructions).

    If I didn't call the forge_php file I got an undefined function. I believe it was called (escape_pdf_string) on line 248 of pdftk-php (I can re-create the exact issue if you would like?... Will have to wait until I get home).

    As soon as I called the OLD forge_php file it worked fine.
  • I've heard from a couple other people that there's a problem with escape_pdf_string. Could you recreate the issue and e-mail it to me at andrewheiss at gmail?

    Thanks!
  • I hope you got my email,

    With livecycle you can also create a database connection and call information back based on a query.

    The other option that my brother will be playing around with is passing the FDF or XFDF file is via the web URL

    For example a url like this
    http://localhost/fine_form.pdf#FDF=http://local...

    See http://books.google.com/books?id=HRFtXWtbAdwC&a...
  • Darrell
    escape_pdf_string Problems

    Original problems were posted here: http://www.andrewheiss.com/blog/2007/10/06/popu... but it should go here.

    I finally re-downloaded the latest and greatest tarabll from GitHub dated 07-03-2009 in which the description says it fixed the escape_pdf_string by making it public... I don't think that it fixed the problem and I think it may be part of my problem as stated in the previous posts.

    I have full access to my servers over here... I cleared the error_log on my webserver to see what is going on.

    To re-iterate the problem, using A.W's Acrobat form in the tarball, I am able to sumbit data thru the web interface and submitable form without issue. I can also repopluate the form without issue with the code as is.

    I made a clean LiveCycle Design Form using the three fields as listed in A.W.'s Acrobat Form ( firstname, lastname and email) and inserted the Live Cycel Form Field Names that correspond to these fields into the download.php file... However at this point, trying to repopluate the LiveCycle Form produces an "http 500 - Internal Error".

    Upon viewing the error_log file, this is what is logged:

    PHP Fatal error: Call to undefined function escape_pdf_string() in /var/www/html/new-pdf/pdftk-php.php on line 247

    So it appears that by making the escape_pdf_string a public function does not fix the error in LC forms...

    Hedgehog, I see in your post above you made reference to this, but I don't see a solution (I assume the description on the tarball that A.W. published is the direct product of your post). Any help would be appreciated...

    Darrell
  • Hmm... What version of PHP are you using?

    I'll check the escape_pdf_string issue again, too.
  • Darrell
    Hello Andrew,

    Here is my work environment:

    I am running Fedora11 with pdftk-1.41-19.fc11.i586,
    httpd-2.2.11-8.i586 (apache),
    php-5.2.9-2.fc11.i586 and
    mysql-5.1.35-1.fc11.i586…

    All forms are created in LiveCycle 8.0 and are all saved as Acrobat 7 (static) pdf forms…

    I just built this server with a fresh install of Fedora 11.

    Thanks
  • Excellent - I'll take a look.

    I was hoping the public/protected issue was a PHP version problem, but you're on the same version as me, so it's back to the drawing board.

    Thanks!
  • I'm pretty sure I just fixed it. Line 247 was calling a procedural function rather than the escape_pdf_string function in the class. Adding a $this-> to the line fixed it.

    It'll probably work with escape_pdf_string as protected or private again, since that was the problem all along.

    I pushed the patch to GitHub, so you can download the latest tarball (not the tag, though) to get the fixed version.

    Let me know if there are any other problems.

    Thanks!
  • Actually, I decided to tag it after all. You can download version 1.0.2 from GitHub (or just the automatically packaged tarball/zip - they're one and the same at this point)
  • Darrell
    Hello Andrew, thank you for working on that problem so quickly... The fix does allow me to now begin to download a pdf with no crash. Problem now is, the downloaded pdf shows a flattened form of the original pdf but has blank fields (not repopluating).

    I have commented out the unlink on Line 71 and the script seems to produce a properly formed fdf file.. See here:

    %FDF-1.2
    %����
    1 0 obj
    <<
    /FDF << /Fields [ << /T (form1[0]) /Kids [ << /T (#subform[0]) /Kids [ <>
    <>
    <>
    ] >>
    ] >>
    <>
    <>
    ]
    >>
    >>
    endobj
    trailer
    <>
    %%EOF


    And I have run the pdftk at the command line to try to directly merge the newly created fdf file with the original pdf file which results in a test.pdf that is the original pdf flattened file without the form fields repopulated (exactly what I experience thru the web download.php)... The passthru path has the correct location of pdftk...

    If you look at my previous post, it may be because the fdf_data_string is not properly formed in the download.php (pdftk dump_data_fields produces a & # 0 ; after each path in the DOM formatted field name-which I thought was odd..) I have tried the fdf_data_string with these characters (they are really altogether with no spaces) and without them... I have also used the fieldnames as reported in the header of the Script Editor Window in LC (which doesnt have some of the [0] at the ends of the DOM paths).

    By chance can you send me or upload a working copy of a LC form and the download.php form with the fdf_data_strings line set in which you can successfully repopluate the data fields in a Live Cycle Form... Then I could compare each of the three variations of the fdf_data_strings I am using to determine which is correct and/or if none of them are correct...

    Again Andrew, thank you for all of your work on this project... If I get this working, it will be a fantastic addition to my company's work flow...

    Darrell
  • I made a super simple LC form that you can download here.


    I only modified two lines in download.php--you can get the diff here.


    The LC form works fine on my two servers, so hopefully it'll help clear up any problems you're having.


    Let me know if you need anything else.

  • Darrell

    Thanks for posting the LC form Andrew... Unfortunately, using your form with the $fdf_data_string in the download.php file (as indicated above) still gives me the flattened form without the data repopulated...


    I guess it must be something on my end... Wonder if it is a setting in my php.ini script... Do you know of any specific setting in the php.ini file that may "break" your code if implemented?


    Again thank you Andrew... If I find a solution I will be sure to post.

  • Darrell

    Live Cycle Forms Will Not Repopluate


    Just a follow up... I decided to download the source file for pdftk directly from the www.accesspdf.com website... However, the gcc version on Fedora 11 is 4.4.0-4 which is greater than the 3.4.2 version which the latest and greatest pdftk-1.41 version was built with (the newer gcc package removed some of the libgcj functions according to the www.accesspdf.com website needed for a successful build)... Anyway, that said, the only option is to use pdftk that you can install with yum from the default Fedora repositories.


    Using this version of pdftk however results in the Live Cycle Forms not being repoplutated.


    I had an old Fedora 6 machine laying around and tested the LC form that Andrew sent to me using an rpm of pdftk that I found compiled for fc6... To my amazement, it repopulated the flattened LC form without issue. (It does not, however, repopulate an unflattened form - but I can live with it)..


    I am assuming that the problem is with the version of pdftk that comes on Fedora 10 and 11 as when you run the command


    pdftk example.pdf dump_data_fields


    the form field names have the code sequence for a null character appended to each path segment in the DOM name.. ie


    form1[0] & # 0 ;.#subform[0] & # 0 ; .email[0] & # 0 ;


    (Note I had to put spaces between the code sequence so it would show up in this comment blog)


    So I am assuming the pdftk command in the Fedora 11 version doesn't know how to handle the merging of these fields with the odd ball null code sequence ... If I use the exact same LC form on Fedora 6 and run dump_data_fields the null code sequence does not appear in the form field names...


    Anyone have a clue as to why pdftk on Fedora 11 would be doing this? and is there a way to fix it prior to the merge.

  • skeeter101
    Andrew,
    I am trying your example on a linux based sys. 'Ubuntu 9.04 to be exact. And during the installation you say to type 'whereis pdftk' to verify the path of it. When I type that in, it is specifying a path. What am I not doing?
  • skeeter101
    Sorry......IT IS NOT

    telling me the path........I type 'whereis pdftk' and hit enter.....all it shows is:

    pdftk:

    and that is all......
  • Darrell
    Skeeter, try using this command:

    which pdftk
  • skeeter101
    Thank you Darrell,

    got it
  • skeeter101

    Andrew,


    Do you have a step by step tutorial available on this? I have created my own pdf document and got all the specified field names in place, and have created my form. But I am in need of a little bit more support on what to place where, and all that. Could you please respond and let me know? Or provide a link to a page with step by step instructions?

  • Can you be a little more specific as to what you need help with? The original tutorial has the general instructions on how to get most of this working--the newer version of the project has instructions in the comments of both pdftk-php.php, example/download.php, and README.txt


    In general, just use example/download.php as your template download script. The script gets data from a database, saves the data to different variables, maps those variables to PDF form fields (in line 39), and then injects that data into a blank PDF form, where you specify at line 65.


    So, make sure the example is working first--then modify and extend it to work with your specific application.


    Let me know any specific questions you have getting this set up.

  • skeeter101

    Another thing.


    pdftk-php.php should be located in the dir above the index,view and download files correct? And, on the line that you specify that location of the pdf document, I uploaded mine to the server, and it could not find it. I just renamed it to 'example.php' and BOOM, it came up......I have got to be missing something small here on this issue.

  • skeeter101

    Andrew,



    I am creating my pdf in LiveCycle. One thing I have noticed is that I needed to do a 'dump' for the field names. This is what I got:

    FieldType: Text
    FieldName: firstname
    FieldFlags: 0



    FieldJustification: Left

    FieldType: Text
    FieldName: lastname
    FieldFlags: 0



    FieldJustification: Left

    FieldType: Text
    FieldName: email
    FieldFlags: 0
    FieldJustification: Left


    On one of your tutorials, it had more info such as:
    FieldName: form1[0].#subform[0].#area[0].FirstName[0]


    and mine did not have that. Am I doing something wrong in LiveCycle? I had the pdf already created and imported it into LiveCycle, but then it told me something about the 'artwork' that could not be imported if the pdf was not made in LiveCycle, so I am tying it from scratch.


    What do you suggest?

  • It should be okay if your LiveCycle form doesn't follow my example--you must have changed some of the frame or page settings. Use whatever form names pdftk tells you to.


    As for the location of pdftk-php.php, it can go wherever you want it to--you just need to make sure the relative path is set correctly in download.php at line 18.


    The same goes for the pdf file. Make sure it is located at the relative path you tell it to be.

  • skeeter101

    Andrew,


    Thank you......got it going and inputting data from my sql db. Only got three fields and got about 40 more to go. S


    I was wondering if you could give some insight on how to get it to work with 'check boxes'?? Is it possible? Or is simply the php coding......and also concerned how it would reflect in the sql db......


    Your advice is greatly appreciated.

  • HTML checkboxes work like text input fields. A field like this:


    <input type="checkbox" name="option" id="option" value="yes" />

    will look like this to PHP when submitted:


    $_POST['option'] = "yes";

    which you can then store in the database somewhere.


    When you get the data out of the database and prepare it to be injected to the pdf form, you'll need to set the value to either "Yes" or "Off" for pdftk to work. See line 44 in download.php for an example.

  • skeeter101

    Thank you for that. And I have run into something else. Is there a limit of the amount of fields I can place within my submittal form?


    I am now trying to add 'one by one' to confirm if I am missing something or not.


    Again, thank you.

  • As far as I know, there isn't a real limit (theoretically it might be up in the hundreds of thousands, but shouldn't be a problem in a real life situation)

  • skeeter101

    Kewl......taking it one by one


    :)

  • skeeter101

    Andrew,


    I am having a heck of a time figuring out these checkboxes. The pdf form I am trying to populate has several of them.
    1. Can I change the names of '$pdf_checkbox1' to $pdf_whatever'??
    2. Is there anywhereon the net that you have a more detailed tutorial?


    Please let me know.....this has got me stuck

  • @skeeter101 and anyone else who is/will be interested...


    I just posted an updated and more detailed tutorial on the blog at http://www.andrewheiss.com/blog/2009/07/29/inst...>

  • Chris

    Hey Andrew... glad to see pdftk-php officially released! I was a little worried when I saw it disappear from Google code.


    Is there a change log anywhere I could see what might have been added or fixed since I first downloaded pdftk back in January? I downloaded the new version but didnt see any version documentation.... Just wondering if there's anything new that might be a good reason to upgrade from the old version


    Thanks again, pdftk-php has been a huge help in serving customer certificates on our site, and the InDesign+LIveCycle+pdftk-php+MySQL project for my dynamic 300dpi CMYK label pdfs has gone great other then a need to reposition some of the form fields in LiveCycle...

  • Yeah, you'll probably want to upgrade. There was a typo in one of the functions. You should just be able to replace the old pdftk-php.php and everything should go fine.


    Additionally I added some example documentation in the /example folder, but since you already have it working, you probably don't need it.


    And I'm glad to hear it's working for you :) It's amazing what this little hobby project of mine has done.

  • @Darrell Like you said, I think it's a problem with the packaged Fedora pdftk, which is probably linked to gcc's lack of full gcj support


    You might want to install an older version of gcc (like 3.4.2) that works with libgcj on your Fedora 11 box. Stick it in /usr/local/bin or something and only use it to build pdftk--once you're done, go back to the real gcc. That might clear up the irregularities you're seeing...

  • Hi Andrew,


    thanks for pdftk-php! I had big time trouble using pdftk on Linux / PHP / Apache. You might want to read my error description.

  • I read your description and agree that it's a problem with PHP and/or Gentoo. I've run it successfully on Debian, Ubuntu, RedHat, openSuse, and OS X without having to use a Perl wrapper or anything. Your situation is mindboggling :)


    Here's a Mac-saved pdf file and a sample fdf file. When you run pdftk fill_form on OS X everything works; when run on pretty much any Linux box, you get this error:


    Unhandled Java Exception:
    java.io.CharConversionException
    at gnu.gcj.convert.Input_iconv.read(Unknown Source)
    at java.lang.String.init(Unknown Source)
    at java.lang.String.<init>(Unknown Source)
    at java.lang.String.<init>(Unknown Source)
    at com.lowagie.text.pdf.PdfEncodings.convertToString(Unknown Source)
    at com.lowagie.text.pdf.DocumentFont.fillEncoding(Unknown Source)
    at com.lowagie.text.pdf.DocumentFont.doType1TT(Unknown Source)
    at com.lowagie.text.pdf.DocumentFont.<init>(Unknown Source)
    at com.lowagie.text.pdf.AcroFields.getAppearance(Unknown Source)
    at com.lowagie.text.pdf.AcroFields.setField(Unknown Source)
    at com.lowagie.text.pdf.AcroFields.setFields(Unknown Source)

    This seems to happen whether I use more Mac specific fonts (Helvetica, Myriad Pro) or universal fonts (Arial, Times New Roman). When I save the file with Windows, even when using a fancier font like Myriad Pro, it works because Windows uses a universal font encoding when embedding fonts.


    And, sadly, there is no forum for pdftk. The last update was five years ago, but it still works.

  • yes, it really took a lot of headache to figure that out.


    anyway: the Mac PDF works without problems on my setup. Lucky this time :) - generated well and look good in Windows and MacOS.

  • Andrew,


    I read your note about Mac generated PDFs. Are you able to please post / mail me a PDF file which you know is NOT working?


    stefan.-

  • Maybe pdftk worked with the Mac-produced PDF on your system because you're running on an international distro, so you have the full internationalized Java runtime environment?

  • to be honest, I dont even know, I didnt care about java that much :). Will take a look at it tomorrow.

  • Compiling pdftk on gentoo linux failed first. Reason: gcj support is disabled for certain new GCC versions. Recompiling GCC with GCJ support (gentoo: ufed) did the trick (gcc 4.3.x).


    Too bad pdftk does not have a forum. Do they? Did I miss something?

  • Mak

    Hello All


    I am having a problem running pdftk from php script on Redhat Enterprise Linux 4AS. It works fine from command line but dosen't work from php script. below is the passthru I am using. pdftk is installed in /usr/sbin/. Any help would be appreciated.


    passthru("/usr/sbin/pdftk --help");


    Thanks in advance
    Mak

  • Mak

    I am getting return code 126 which is command not executable.


    Mak

  • did you try moving pdftk to another location, e.g. /usr/bin/? Also, try chmod 777 pn pdftk for test purposes to make shure your PHP / Apache is allowed to execute it. I assume PHP Safe Mode is already off - with Safe mode on it probably wont work anyway.

  • Mak

    It was a permissions issue. I resolved it by granting permissions to the user on folder usr/sbin/pdftk.


    Thanks for your help
    Mak

  • kimani

    Thanks for your tutorial Andrew.
    I've a problem when creating an interactive pdf forms which is populated from mysql database.
    When I flatten the output, I'm able to display the data from the database but the resulting pdf form is not interactive, Whereas if I ommit the flatten keyword in the passthrough function, the resulting pdf form is interactive but it doesnt display information from the database. Any help

  • I also output non-flattened PDFs and it works fine.
    For debugging, I suggest to output your PDF to a file and then manually download an read / open it. This way you can make sure you dont have any HTTP header, chunking or compression issues.
    Simply append "output [/path/to/myfile.pdf]" to the passthru command and make sure you can access that location (in case you dont have root access).

  • kimani

    Thanks Stefan for u comments.
    My Problem is that if I output non-flattened PDFs it is outputing the pdf to the browser BUT THE OBJECTS like TEXTFIELDS are not populated by data from the database. I want to create interactive pdf which will can be populated by both the user or from the database.
    Thanks

  • I understand your problem. Thats why I recommend to first check the generated PDF by outputting it to a file and downloading it, not directly pass it to the browser. This way you can exclude browser, header and transfer errors.


    If that still does not work, you might have a charset or PDF version issue. Also, make sure your PDF is not generated on a mac, as Andrew suggests. Is your PDF rights managed?


    Hint: whenever I run into problems with forms, my first step is to log into my server, paste the exact passthru command into the shell and run it from command line.


    Another hint: I once was having an issue with UTF8 data fetched from a mySql database. I needed to utf8-decode everything before passing it to pdftk-php.

  • kimani

    I tried outputting it to a file which is still not working.
    When I flatten the form, it can display data from the database, but immediately i remove the flatten keyword, the generated form does not contain data from database.
    I'm not well versed with running through the command line. I'm using xampp on windows, acrobat reader 9 and form designer 7.0 with upgrades.

  • Im not sure about form designer since I´m not using it, but did you check this tutorial about livecycle bindings? Maybe its one of these static / dynamic issues?

  • kimani

    Would you mind checking my test code n form to see where could i be getting it wrong
    adobe form http://www.autoassured.com/tests/LoanAgreement.pdf
    sample code http://www.autoassured.com/tests/viewpdf.php.tx...>

    I would like when users open that form, if there is a record it is searched, and populates the pdf form. Users should also be able to edit the existing record from the same pdf or insert a new record.


    For now what is happening, If i remove the flatten keyword details are not displayed on the pdf form from the database but if I allow the pdf to be flatten, it is displaying details from the database.
    Any Help??

  • thats hard to check without your data. Please post a link with your actual generated FDF file. To do this, comment out the "unlink ($fdf_fd);" line in your script, so the temporary FDF will not be deleted. Then download the generated FDF and upload it somewhere so we can access it.

  • kimani
  • sorry kimany, I cannot help any further - but I can give you another hint: when I open the Filled, Flattened PDF in Safari (Mac) using the build-in PDF viewer, it works! I see the data an can change it.


    Using Acrobat reader on PC or MAC does not show the data.


    So below the line: parsing seems to work. If you have access to Adobe Acrobat (not Reader), I suggest to create another form using acrobat itself, not adobe form designer, and give it a try. Be sure to make it static.


    please let us know what happened.

  • kimani

    Thanks for your contribution. It seems the package I have only have adobe designer 7.0, acrobat professional 7.0, distiller 7.0 and reader 9. I have looked for options of creating forms apart from using desiger without success. Where do i get adobe acrobat??. Anyway I almost giving up to redisigning the pdf forms using HTML.
    Once again Thanks alot

  • you already got it: Acrobat Professional 7. Thats Adobe Acrobat! It should do the job.


    Usually, if you want a nice layout, its the best way to create a "Template" PDF with some layout application like illustrator, indesign, corel draw or whatever an then load this PDF into acrobat an insert your form fields on top.

  • kimani

    Thanks alot It worked when using acrobat professional.

  • Jeremy

    Hey, just wanted to say thanks...I had asked quite a few questions a while back. My company has been using this program for almost a year now...


    I have an input form for our service people to enter a client's information. I then have many applications saved as pdf's which will pre-populate with the help of your program when selected from a drop down. Because of our competitive industry, it is important for us to send out 2-3 applications for competitive quotes every year to each client. Since most of our clients (up to 1600 now) are in the system (as it's been a year) this program is going to help out tremendously from here on out. Instead of spending 30-45 minutes per client each year on the applications the time is going to be reduced to more like 3-5 minutes.


    Just wanted to let you know how much you helped.


    Thank you!

  • Joshua

    First off, thanks for the great info for an obscure solution. Your time is greatly appreciated!


    I downloaded and installed everything according to your tutorial. Your example.pdf works great with the download.php, however, I can only get it to work when I use a browser on the server itself. A client connection yields the dreaded "not supported file type or the file has been corrupted"error.


    Any clues to resolving this one?


    I am using Fedora 11 w/Apache, PHP, MySQL (latestest stable builds) as well as .

  • The most common reason for that error is that pdftk can't run, either because the path can't be found or because it lacks sufficient privileges. Make sure you've typed the full path to pdftk in pdftk-php.php


    I'm assuming it's happening because the browser can somehow legally access pdftk locally and probably not because of any problems with your LAMP stack itself. That said, you might want to check to make sure you haven't overprotected PHP or Apache--there might be something there that's restricting calls with passthru()

  • Joshua

    Problem solved. I am including it here for anyone running into this issue.


    The problem was that I was calling the "download.php" with an include statement. It appears passthru() was trying to interpret the file as HTML instead of PDF. Changing MY code to header("Location: download.php") fixed the issue.


    Cheers!

  • Todor

    I have the same problem but I don not change anything except the path to pdftk with the following row from pdftk-php.php:
    passthru("example/pdftk $pdf_original fill_form $fdf_fn output - flatten");
    I use xampp client and in the htdocs root folder I have a example folder in which is the pdftk.exe file.
    Thanks in advance :)

  • What platform are you using with xampp? If you're on Windows, change example/pdftk to example/pdftk.exe. If you're on Linux or OS X you'll need to install pdftk system wide and put the absolute path to the installed binary.

  • Todor

    I use Windows and if I change it to example/pdftk.exe it doesn't work again :( Is there any way to send you the files via e-mail and you to take a look , I cannot fix it at all.

blog comments powered by Disqus