PDF Form Filler =============== Version 1.3 23.04.2008 (c) 2008 by Lars Wegmann mail: info@wegmann-it.de www: http://www.wegmann-it.de url http://www.wegmann-it.de/php_pdf_form_filler.html phone: 03647 5295 Description ------------ - makes server-filled PDF form templates which has been generated by Adobe Acrobat, OpenOffice etc. - values for the field contents can be derived from Database, HTML-form, text files etc. - output of the filled PDF can be sent selectively or in combination: > to browser > by mail > as a file into the file system - the field content of the generated PDF form can (if necessary) can be subsequently changed by the user - there are no PDF-extensions/libraries from server or classes such as PDFLib and FPDF etc. needed - filling is possible only for text fields (numerical values are also possible) - Checkboxes, radiobuttons or other PDF form elements are not supported! System requirements -------------------- - Web server environment with installed PHP4.x or 5.x License Informations --------------------- -> For private purposes or for testing this script can be used royalty free. About an attached note or link i'd be glad -> The license fee is 4,95 EUR including 19% VAT. This applies for each domain used on the PDF Form Filler. Acquisition of a license, including 2 open office form templates obtainable under: http://www.wegmann-it.de/php_pdf_form_filler_lizenz_erwerben.html Installation/ Integration of the DEMO -------------------------------------- 1.) unZIP the file 2.) Upload the following 4 files to the web environment via FTP to: www.your-domain.de/pdf/ index.html (Demo form) exec.php (Demo script) mitgliedsantrag.pdf (Demo PDF-template) pdf_form_fill.php (contains functions to fill in the PDF template) 3.) Call the URL in your browser e.g. www.your-domain.de/pdf/index.html NoteThe PDF template mitgliedsantrag.pdf must be legible, if necessary, set chmod 755 Adapt to own needs ------------------- 1.) Creating a PDF template a) Design your template e.g. with OpenOffice, which supports PDF and PDF forms by default. b) PDF Form Filler works in accordance with the search&replace procedure. The filling of the fields is not done at the field name but pre-assigned to the field content. This has to be defined. First when you create the PDF template and then in the program part under 2). Distribute so all text fields, that have to be filled later by pdf_form_fill.php with dynamic values , a clear standard text (pre-assigned field content). e.g. “AUTO-forename**********************************” for the field "forename" [50 characters] e.g. “AUTO-surname***********************************” for the field "surname" [50 characters] e.g. “AUTO-title*************************************” for the field "title" [50 characters] e.g. “AUTOP” for the field "postal code" [ 5 characters] c) The stars serve as a placeholder. Please vote for each text box a sufficient character length for the standard text. This is necessary to ensure that the dynamically registered values are less than or equal to the length of the standard text. Is one of the dynamically filled fields longer than the length of the standard text characters, the filling process is terminated and an error message appears: -> Target-String strlen(String[dynamic value]) is larger than source string strlen(String[pre-assignment]) Cancelling is necessary, otherwise the internal file structure of the PDF template will be damaged. That leads to an error message in Adobe Acrobat. The original template remains in any case unaffected. The term AUTO-Name*****************************************serves as an example, it does not have to be inevitably in this form. You can use also: $FD1*****************************************”, $FD2*****************************************”, $FD3***************************************** etc. or other identifier/default values (inconsistent, too) IMPORTANT: The default values should have a minimum length of 3 characters, better 4 characters or bigger. Otherwise the results can be in undesirable replacements in the PDF document. That results in error messages while opening it in Adobe Reader. 2.) Customizing or integration exec.php in own scripts The lines in exec.php contains all four relevant informations. These you can take in your own scripts. require(pdf_form_fill.php) // binds the file pdf_form_fill.phpinto the current script. $pdf_template = mitgliedsantrag.pdf; // the name of the PDF template is assigned to this variable $pdf_form_values = array (); // this array can contain any number of values e.g. $pdf_form_values = array ( AUTO-Name***************************************** => Doe, AUTO-forename************************************* => row['forename'], AUTO-forename************************************* => $_POST['titel'], AUTOP => border(0,99999) ); $filled_pdf = generate_pdf($pdf_template, $pdf_form_values); // function call to complete and generate the PDF-file 3.) Output of the filled PDF ... > to Browser pdf_to_browser($filled_pdf, $filename); > by mail pdf_to_mail($filled_pdf, $filename, $to, $fromname, $fromemail, $subject, $message); > as a file into the file system pdf_to_file($filled_pdf, $path.$filename); Note - It allows multiple types of output at the same time Error: ------ ### by calling generate_pdf() ...Target-String strlen($dest) longer than Quellstring strlen($src) -> expand the standard text in the PDF template and by analogy, in the array $pdf_form_values ...”no pdf found” -> adjust the path and file name of the variable $pdf_template ...”pdf-template could not be opened => The file is possibly corrupt” -> Set chmod 755 to your PDF template or make sure that the file is not corrupted. ...”array $pdf_form_values contains no values” -> set $pdf_form_values = array ( pre-defined standard text=> dynamic text); ...”PDF template does not contain default value ”: The array $pdf_form_values contains a default value which is not defined in the PDF template. -> Enter in the PDF template exactly the same default value like in $pdf_form_values. (note lower/upper case) -> If the value is not needed, remove it also from the array $pdf_form_values. ### by calling pdf_to_file() ...”no pdf content specified.” -> make shure that $filled_pdf was set by generate_pdf() (a value -> die befllte PDF als String enthlt) ...”no file name given.” -> Enter a file name. e.g. $filename = dokument.pdf ...”can not open the file $filename” -> make sure that the path and file are within your access area ... within your homepage (with absolute path indicate) -> make the parent directory writable, set chmod 775 or 777 ..."can not write in file $filename" -> make sure that the path and the file are within your access area ... inside your homepage (for absolute path) -> make the parent directory writable, set chmod 775 or 777 ### by calling pdf_to_mail() ..."no pdf-content given for attachment " -> make sure that $ filled_pdf was set by function generate_pdf () (variable contains the filled PDF as a string) ..."no file name given" -> give a file name e.g. $filename = "document.pdf"; ..."no receiver address given" -> give $to e.g. $to = "customername@customerdomain.com"; ..."receiver address is invalid" -> make sure that the format (structure) of the receiver address is valid e.g. $to = "customername@customerdomain.com"; ..."no sender name given" -> give a sander name e.g. $fromname = "fromname surname"; ..."no sender adress given" -> give a sander mail adress e.g. $fromname = "info@your-domain.com"; ..."sender adress is invalid" -> make sure that the format (structure) of the sender address is valid e.g. $fromname = "info@your-domain.com"; ..."no subject given" -> give a subject e.g. $subject = "Your registration as a PDF"; ..."no message given" -> give a message e.g. $message = "Dear customer, ...."; ### by calling pdf_to_browser() ..."no pdf content given." -> make sure that $ filled_pdf was set by function generate_pdf () (variable contains the filled PDF as a string) ..."no file name given" -> give a file name e.g. $filename = "document.pdf";