Fdf to pdf How to check a checkbox on pdf filling - php

I am using FDF to fill the pdf with php . I have some checkboxes in the pdf .
I searched a lot on interment . I refered these links refer1 link2.
currently i used this
<</T(form1[0].#subform[6].Checkbox1a[0])/V(1)>>
<</T(form1[0].#subform[6].Checkbox1b[0])/V(checked)>>
<</T(form1[0].#subform[6].Checkbox1c[0])/V(yes)>>
<</T(form1[0].#subform[6].Checkbox1d[0])/V(on)>>
I have tried 1, checked, yes , on etc but failed to ckeck the checkbox . this is one of the pdf i am using to fill pdf link

In the PDF specification the V entry of a check box is described as following:
The V entry in the field dictionary [...] holds a name object representing the check box’s appearance state, which shall be used to select the appropriate appearance from the appearance dictionary.
It is also defined that the name for the in state should be Yes but that's not always the case. In your document the on state is defined as Y.
So your FDF data should look like:
<</T(form1[0].#subform[6].Checkbox1a[0])/V/Y>>
For completion: If the export value is non-Latin text (by using an Opt array) e.g. Acrobat doesn't use a name object but a string, too:
<</T(form1[0].#subform[6].Checkbox1a[0])/V(Y)>>
This behaviour seems to be un-documentated.

Related

How do I save texts sent by users via GET input in separate text files in php?

I know how to save the sent texts in 1 text file created beforehand. but I need some way to save each text in separate text files which are created automatically
The code below will save the text, which was provided by the user via GET parameter named param, to a new file with unique name in form of hash (something like 6cc50baac239a47e165a320d03c76731.txt).
<?php
$text = $_GET['param'];
file_put_contents(md5(uniqid(rand(), true)) . '.txt', $text);
You can use fopen to create a file, but before using that, read following PHP Manual to find which mode is suitable for your case. Have a look in A list of possible modes for fopen() using mode section:
php.net - fopen function
Be successful.

How do I return a PDF document from TCPDF as a string?

The TCPDF documentation is very useful:
Output( $name = 'doc.pdf', $dest = 'I' )
Send the document to a given destination: string, local file or browser. In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.
The method first calls Close() if necessary to terminate the document.
... very useful indeed. It tells me that what I want is possible, but doesn’t begin to tell me how. Is there any documentation on the various options for $dest, what they are and what they do?
I used tcpdf many times and saved it :). Just check:
I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
D : send to the browser and force a file download with the name given by name.
F : save to a local server file with the name given by name.
S : return the document as a string (name is ignored).
FI : equivalent to F + I option
FD : equivalent to F + D option
E : return the document as base64 mime multi-part email attachment (RFC 2045)
The documentation on the project’s own site is lacking, but the documentation for the Ruby gem has the information we need:
#param string :dest
Destination where to send the document. It can take one of the following values:
I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the “Save as” option on the link generating the PDF.
D: send to the browser and force a file download with the name given by name.
F: save to a local server file with the name given by name.
S: return the document as a string. name is ignored.
FI: equivalent to F + I option
FD: equivalent to F + D option
So to return it as a string, we want Output('ignored.pdf', 'S');.

FPDF add a hidden data in pdf

I would like to add a simple hidden data (could be comment or something) for generate pdf file through fpdf library. I need simple protection of authenticity, that this file has been generated through my application .
Thanks for answers
Option 1 :
You can set the pdf with below. (the properties only viewable at pdf reader)
$pdf->SetTitle("Any Title");
$pdf->SetAuthor("Any Author");
$pdf->SetSubject("Any Subject");
$pdf->SetCreator("Any Creator");
I think you need extend your FPDF class to FPDFP (Protection), If not will be able to change the setting.
Option 2 :
using Watermark class extension.
Option 3 :
generate some non-understand wording as your pdf signature at bottom page. If you don't want print out at the paper, set the text color. (look like cheat way but simple)
$pdf->SetTextColor(255,255,255);//Set to White color
$pdf->Cell(20,10,'onlyme_understand_signature',1,1,'C');
$pdf->SetTextColor(0,0,0);//Set to Black color
I don't see any way to add metadata (XMP) data using FPDF. TCPDF can do it:
TCPDF::setExtraXMP($someCustomString);
The only way to do this that I see (it's far from waterproof but adding something to XMP also isn't waterproof) is to set the creator of the file correctly using:
SetCreator(string creator [, boolean isUTF8])
This will allow you to have a specific string for who created the file which you could easily test for later. As most PDF consumers leave the creator string alone once it's there, this might be good enough for your purposes.

PHP not auto-populating data in PDF

I've been using the advice given in this question:
Merge FDF data into a PDF file using PHP
to determine how I can pre-populate a pdf form with data pulled from a database but not getting the data to file. I'm running php 5.3.15 on Mountain Lion and I'm using the following link to combine the pdf with the fdf on a table page that I'd like to allow the user to click and take them to a populated pdf file:
something.pdf#FDF=generatePdf.php
The generatePdf.php looks like this:
<?php
$pdf_form_url= "";
require_once('forge_fdf.php');
$fdf_data_names= array(); // none of these in this example
$fdf_data_strings= array(); // none of these in this example
$fdf_data_strings['form1[0].#subform[0].q1a_LastName'] = "Smith";
$fields_hidden= array();
$fields_readonly= array();
// set this to retry the previous state
$retry_b= false;
header( 'content-type: application/vnd.fdf' );
echo forge_fdf( $pdf_form_url,
$fdf_data_strings,
$fdf_data_names,
$fields_hidden,
$fields_readonly );
?>
and the FDF file looks like this when I run it through the pdftk command line:
FieldType: Text
FieldName: form1[0].#subform[0].q1a_LastName[0]
FieldNameAlt: Enter Family Name
FieldFlags: 0
FieldJustification: Left
FieldMaxLength: 35
Still, when I run it the form doesn't auto populate. I've tried many variations including just using the q1a_LastName by itself and I still end up with an empty form. The forge_fdf.php is in the same directory.
Update:
I've also attempted the conventional method outlined in the Merge FDF data into a PDF question that I've linked to using PHP, meaning I didn't just direct the user to a pdf file but also attmepted to have the user download the pdf. In that particular case, I would receive a message saying the pdf was empty. I've checked the created raw FDF file and it appears to be populating with data. In either case, I'm not getting what I need.
After much trial and error I realized that the best way to autopopulate to a url linking to a pdf is to define the $pdf_form_url variable for the code above. This code will echo out the details of the fdf file. If you explicitly specify what the pdf url is, php and your browser will take the necessary steps to link you to a the pdf in your web browser with the embedded field information coming from the fdf output.
So I stumbled upon this thread and couldn't get it to work even when I populate the $pdf_form_url variable. Here's my code:
require_once('forge_fdf.php');
// leave this blank if we're associating the FDF w/ the PDF via URL
$pdf_form_url= "http://test.pdf";
// $pdf_form_url= "";
// default data; these two arrays must ultimately list all of the fields
// you desire to alter, even if you just want to set the 'hidden' flag;
//
//
$fdf_data_names= array(); // none of these in this example
$fdf_data_strings= array(); // none of these in this example
$fdf_data_strings['Address, Row 1']="XXXX Balboa Arms Drive #XXX, San Diego CA 01234";
$fields_hidden= array();
$fields_readonly= array();
// set this to retry the previous state
$retry_b= false;
header( 'content-type: application/vnd.fdf' );
echo forge_fdf( $pdf_form_url,
$fdf_data_strings,
$fdf_data_names,
$fields_hidden,
$fields_readonly );
And here's the form field I want to update using pdftk dump_data_fields:
FieldType: Text
FieldName: Address, Row 1
FieldNameAlt: (Address, <Row 1>)
FieldFlags: 0
FieldJustification: Center

Populating PDF form fields with PHP

I am converting a classic ASP application to PHP.
In the Classic ASP app, we are programatically populating fields that have been created in PDF documents using a component called ASPpdf.
I need to reproduce this behavior in PHP, but need to know if PHP can populate PDF fields on its own or if any third party plug in is needed.
Is this functionlity posible in PHP with or without a plug in?
Thanks.
Note: I already have the PDFs created, I do not need to create the actual PDF. I need to grab a preexisting PDF with form fields, populate those form fields and then save that custom PDF.
This is the first google search result I got, is there a reason this doesn't work for you?
http://koivi.com/fill-pdf-form-fields/tutorial.php
UPDATE
After reading a little further, this generates an FDF (which Acrobat can read). To generate an actual PDF you'll need to use this: http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
The resolution to my problem was to use the same COM component I used in Classic ASP in my new PHP apps. The COM object give me tremendous control over PDF documents.
The component I use is AspPdf
<?php
$pdf = new COM("Persits.Pdf") or die("Unable to instantiate Word");
$pdfdoc = $pdf->OpenDocument( "pdf.pdf" );
$pdffont = $pdfdoc->Fonts("Helvetica-Bold");
$pdfdoc->Form->RemoveXFA();
$pdffield = $pdfdoc->Form->FindField("FirstName");
$pdffield->SetFieldValue("PHP Text", $pdffont);
$pdffile = $pdfdoc->save( "php.pdf" , false);
echo $pdf->version;
$pdf = null;
?>
It looks as though the pdftk PDF toolkit may be able to do this. Reading the manual:
fill_form < FDF data filename | XFDF data filename | - | PROMPT >
Fills the single input PDF’s form fields with the data from an FDF file, XFDF file or stdin. Enter the data filename after fill_form, or use - to pass the data via stdin, like so:
pdftk form.pdf fill_form data.fdf output form.filled.pdf

Categories