codeshell / fpdm Goto Github PK
View Code? Open in Web Editor NEWPDF form filling using FPDM Class written by FPDF author Olivier (+multifile-filling-fix, +checkboxes)
License: MIT License
PDF form filling using FPDM Class written by FPDF author Olivier (+multifile-filling-fix, +checkboxes)
License: MIT License
Hello,
I have an pdf and got field name from pdftk as "FieldName: 02_Prescrição
"
So, several field names works, but thin in particular gives a "FPDF-Merge Error: field 02_Prescrição not found" error. I think it's because the accent in "Prescrição".
Note that "02_Prescrição
" tuns in "02_Prescrição".
I can't change the name field. SO, how to fix it?
Hi, I tried the new feature for checkbox, but it is not working in my local laptop, here is my code below, I didn't get error and other text boxes are working, could someone let me know possible issue for me?
require_once '../fpdm-2.9.2/fpdm.php';
$fields = array(
'name' => 'My name',
'address' => 'My address',
'city' => 'My city',
'phone' => 'My phone number',
'checkbox1' => 'Yes',
);
$fileName='template2';//test.pdf
$pdf = new FPDM('../forms/IR/'.$fileName.'.pdf');
$pdf->useCheckboxParser = true;
$pdf->Load($fields, false); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$output="corp_IR.pdf";
$pdf->Output('I',$output);
Using FPDM and instead of viewing the merge doc I am attempting to auto-save the doc on the server with variations of this syntax:
$pdf -> Output('filename.pdf', \folder\Destination::FILE);
No matter what I try I get an error and it will not save the results in a PDF file on the server.
(if i do not specify the DESTINATION:: i get incorrect output destination, if I include it then I get a class Destination not found error)
Can anyone help me with a variation of this command that will save the merged PDF doc? or perhaps a different method?
Thanks!
Bonjour,
j'aimerais savoir s'il est possible avec FPDM d'ajouter des pages à son document ?
Je précise ma demande : je dois générer un récapitulatif de commande. Je ne sais pas à l'avance combien de lignes de produits va contenir ma commande mais le modèle de base est conçu pour 10 lignes. Comment faire pour que je puisse générer x pages à partir de mon document n'en contenant qu'une seule à la base ?
La commande AddPage de FPDF n'est pas reconnu avec FPDM.
ou à defaut d'une solution existe-t-il une librairie permettant de fusionner plusieurs pdf générés avec FPDM ? J'en ai essayé plusieurs mais aucune ne fonctionne avec des documents issus de FPDM.
Hello,
I would like to know if it is possible with FPDM to add pages to its document?
I specify my request: I must generate an order summary. I do not know in advance how many product lines will contain my order but the basic model is designed for 10 lines. How can I generate x pages from my document containing only one at the base?
The FPDF AddPage command is not recognized with FPDM.
or in the absence of a solution is there a library allowing to merge several pdf generated with FPDM? I tried several but none of them work with documents from FPDM.
Thank you in advance.
Have a good day.
i got some warning php in fpdm.php line 550
$buffer=implode("\n",$this->pdf_entries);
sometime $this->pdf_entries is null it is not array
suggestion $buffer=implode("\n",!empty($this->pdf_entries) ? $this->pdf_entries : []);
another warning php in fpdm.php line 1627
Warning: count(): Parameter must be an array or an object that implements Countable in \fpdm\fpdm->parsePDFEntries()
$CountLines = count($entries);
i suggest $CountLines = !empty($entries) ? count($entries) : 0;
Can't seem to get this working with my PDF.
PDF form created in Adobe Acrobat DC, then ran through pdftk, but FPDF still says the field names are not found.
Exact error is:
FPDF-Merge Error: field PremiseName not found
I can get the example working no problem, so I know this is an issue with my PDF.
If I run pdftk data_dump_fields the field name shows up correctly and I have copied and pasted that into my array.
I'm completely stuck where to turn for advice on what I'm missing here...
The script doesn't populate field names like this one
topmostSubform[0].Page4[0].DateTimeField1[0]
Cannot open PDF file when within Wordpress structure (within plugins specifically).
Hi,
I need to sign 2 fields in a PDF with PHP.
Is it possible with FPDM or other ?
Thanks !
I generate a new PDF with the filled data but Firefox can not render it correctly so i tried to flatten the PDF so i used:
$pdf = new FPDM('pattern.pdf'); $pdf->Load($fields, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8 //$pdf->Flatten(); $pdf->Merge(); $pdf->Output();
command which make unreadable the pdf in every platform.
Writing values to fpdm with array from the test script works great for fields if field only occurs once. My form has duplicated fields so that they will copy from one page to another. They are named Address#0 Address#1 Address#2
The hashtag and number are added by Acrobat, not me and are only on duplicated fields. I get field Address not found error when I try to run the merge script. (runs fine if I don't use duplicated fields)
I try using Address, Address#0, Address#0 and numerous iterations.
Is this even possible? Any advice please?
pdftk shows the above field name as Address
require_once './fpdm.php';
$fields = array ('Address' => '999 Brook Drive S', 'City' => 'Zooland' );
$pdf = new FPDM('../testOp2.pdf');
$pdf->Load($fields,false ); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output(F,'/home1/rect/bin/fpdf182/newFile.pdf');
?>
Hello Team,
Your code and this library is perfect and awesome - I really liked it.
But I have only one concern - once the data is merged into the PDF - I want the final PDF but not in Editable mode.
Is it possible? If Yes then please let me know how.
Really Appreciate your earliest reply.
Thank you.
I installed the package with this: composer require tmw/fpdm
This is the line that triggers the error: $pdf = new \FPDM($file);
The documentation doesn't say I need to do anything to my composer.json autoload section but I tried a few different things there with no luck.
Is fpdm a standalone php tool that can be used for filling PDF forms? Or does it require pdftk under the hood?
Thanks!
Note that
composer require shihjay2/fpdf
Will give an error; works with
composer require shihjay2/fpdm
When I use fpdm, checkbox appears correctly in okular but not in latest acrobat reader.
With the following change in src/fpdm.php, it works but I do not know what I am really doing...
@ -966,7 +958,7 @@
}
$CurLine =$this->pdf_entries[$field_checkbox_line];
$OldLen=strlen($CurLine);
- $CurLine = '/AS /'.$state;
+ $CurLine = '/AS /'.$state."\n/DV /$state\n/V /$state";
$NewLen=strlen($CurLine);
$Shift=$NewLen-$OldLen;
$this->shift=$this->shift+$Shift;
I need to merge multiple pdf into one can you please help me
Hi there, I have converted my incompatible PDF with pdftk and now I'm getting this error. How do I fix this?
"FPDF-Merge Error: Number of objects (277) differs with number of xrefs (280), something , pdf xref table is corrupted :("
Hi,
i have a strange issue on checkbox filled with FPDM, on mac preview there is no problem in showing but on adobe acrobat reader the checkboxes aren't showed.
Sometimes on other Mac OS i can see that on checkboxes are present 2 marks...
Maybe the issue is that the font that is used for check mark is ZapfDingbats, but in pdf template created with adobe acrobat pro, the default font used for is AdobePi.
Here : http://webprogramming.ninja/2015/12/28/fpdf-and-the-check-mark/
there is a solution for fpdf.
is there a way for using a different font/char in fpdm for check marks?
thanks for your great work! i hope we can found a useful solution for community!
Carlo
FPDF-Merge Error: Fast Web View mode is not supported
I am getting the above error please suggest
When trying to run $pdf->Merge(true)
I am getting this error:
FPDF-Merge Error: No more resource to execute the command
I have copied the pdftk executable to /src/export/pdf/pdftk.exe
.
My System is on Windows 10 and PHP 7.2
When using $support='native' and merging field values, the output pdf file will have fields that are not visible on iOS using the built-in pdf handlers. The fields are also not visible in mupdf viewer on Windows. If using a third party viewer on iOS (like Acrobat), then the filled-in field values look okay. But in a typical scenario, where the pdf is attached to an email message or viewed in Safari, the pdf will not preview correctly.
If using $support=’pdftk' on the same source pdf and same fill-in field values, the resulting pdf renders fine under iOS and mupdf viewer.
Viewed merged pdf file on iOS 13.3.1, iOS 9.3.5; Windows 10 version 1903 with MuPDF 1.14.0
Attached are the template pdf, merge output using native, and merged output using pdftk modes.
The templatePDF file was prepared with pdftk executable.
The calling PHP code looks like this [for $support='native']
$pdf = new FPDM($this->templatePDF);
$pdf->Load($flds, false);
// $pdf->Plays('pdftk');
$pdf->Fix();
$pdf->Merge();
$pdf->Output('I', $fName);
On my pdf forms, fpdm is unable to identify value for checkbox_yes and check_box_no.
Problem is in the line
} elseif (($ap_line==$Counter-4)&&($ap_d_line==$Counter-2)&&($ap_d_yes=='')&&$this->extract_pdf_definition_value("name", $CurLine, $match)) {
the offset of ap_d_line with counter is not 2 in my pdf file
If I remove this condition, it finds the two values but order is random with some pdf files I have inversion between checked and unchecked state.
I can send the pdf if needed.
The pdf was generated by Acrobat PDFMaker 10.1 pour Word with french locales.
Can someone helps me ?
I try to set a URL on a textbox, but, show the HTML code.
` $fields = array(
'linea0' => 'My name 0',
'linea1' => 'My name1',
'linea2' => 'My name2',
'linea3' => 'My name3',
'linea4' => 'My name4',
'cvs' => 'My city5',
);
$pdf = new FPDM('/path/template.pdf');
$pdf->Load($fields, false);
$pdf->Merge();
$pdf->Output('F', '/path/to/output.php');`
Anyone?
Thanks
On line 637, I recommend you change the error messaging when trying to Output to a file from:
Unable to create output file: '.$name.' (currently opened under Acrobat Reader?)
to:
Unable to create output file: '.$name.' (check that your application has file/folder permissions on the local server (ie. if a web app, does www-group have group permissions/access to write; if a CMS based application, did you provide a public files path?), or is it currently opened under Acrobat Reader?)
Hi!
After upgrading to php 8.1.5 from php 7.4 I get the following error.
Everything worked for two years in the project with the 7.4 version.
Any others having problem after upgrading?
Any solutions?
I got some warning for PHP 7.4 Please fix in filters/FilterASCIIHex.php line 57
$hex .= sprintf("%02x", ord($str{$i}));
to
$hex .= sprintf("%02x", ord($str[$i]));
Hello, thank you for your work.
is there away to get an extracted list of fields of the template pdf?
lets assume its compatible and even ran through the "pdftk modele.pdf output modele2.pdf" already, too.
Hi
I am using updated FPDM library to tick checkbox on editable form. But its not working for me. Can you please or send me an example so that i can.\
Thanks
I have a pdf form with some radio boxes in it, and when I try to fill the form I get an error message that says <b>FPDF-Merge Error:</b> field radio1 not found
Are radios not supported? If so that would be great to get support for
The code seems to assume that the checkbox "on" definition is aways first in the "/AP" Appearance Dictionary. This causes the checkbox code to set the wrong state for any PDF where the "off" definition is before the "on" definition.
For example a PDF with this checkbox Appearance Dictionary
/AP
<<
/D
<<
/Off 14 0 R
/Yes 15 0 R
>>
/N
<<
/Off 16 0 R
/Yes 17 0 R
Will generate the following troubling data in the fpdm [infos] => Array:
[checkbox_yes] => Off
[checkbox_no] => Yes
I have checked the ISO 32000 and older PDF 1.4 reference and there seems to be no requirement for the "on" definition to appear before the "off" definition which would explain why a lot of PDFs have the reverse definition layout. The references do, on the other hand, seem to both state that the off-state definition must be named "Off", so this might be a better way to tell which definition is which.
Here is my horrible, rushed, hacked, redundancy filled solution.
In fpdm.php from line 1859 I replaced this
} elseif (($ap_line==$Counter-4)&&($ap_d_line==$Counter-2)&&($ap_d_yes=='')&&$this->extract_pdf_definition_value("name", $CurLine, $match)) {
$ap_d_yes=$match[1];
if ($verbose_parsing) {
echo("<br>Object's checkbox_yes is '<i>$ap_d_yes</i>'");
}
$object["infos"]["checkbox_yes"]=$ap_d_yes;
} elseif (($ap_line==$Counter-5)&&($ap_d_line==$Counter-3)&&($ap_d_no=='')&&$this->extract_pdf_definition_value("name", $CurLine, $match)) {
$ap_d_no=$match[1];
if ($verbose_parsing) {
echo("<br>Object's checkbox_no is '<i>$ap_d_no</i>'");
}
$object["infos"]["checkbox_no"]=$ap_d_no;
With this:
} elseif (($ap_line==$Counter-4)&&($ap_d_line==$Counter-2)&&$this->extract_pdf_definition_value("name", $CurLine, $match)) {
$ap_d_first=$match[1];
if($ap_d_first!="Off") {
if ($verbose_parsing) {
echo("<br>Object's checkbox_yes is '<i>$ap_d_first</i>'");
}
$ap_d_yes=$ap_d_first;
$object["infos"]["checkbox_yes"]=$ap_d_first;
}
else {
if ($verbose_parsing) {
echo("<br>Object's checkbox_no is '<i>$ap_d_first</i>'");
}
$ap_d_no=$ap_d_first;
$object["infos"]["checkbox_no"]=$ap_d_first;
}
} elseif (($ap_line==$Counter-5)&&($ap_d_line==$Counter-3)&&$this->extract_pdf_definition_value("name", $CurLine, $match)) {
$ap_d_second=$match[1];
if($ap_d_second!="Off") {
if ($verbose_parsing) {
echo("<br>Object's checkbox_yes is '<i>$ap_d_second</i>'");
}
$ap_d_yes=$ap_d_second;
$object["infos"]["checkbox_yes"]=$ap_d_second;
}
else {
if ($verbose_parsing) {
echo("<br>Object's checkbox_no is '<i>$ap_d_second</i>'");
}
$ap_d_no=$ap_d_second;
$object["infos"]["checkbox_no"]=$ap_d_second;
}
}
Also, just another possible minor issue. It seems that the code is looking for the definitions in the Appearance Dictionary's optional "down appearance" (/D) instead of the required "normal appearance" (/N). This seems like it might also cause issues for some PDFs if they include the "normal appearance" definitions but not the optional "down appearance".
I am getting gzuncompress(): data error when trying to merge a file, I am just running the following code
$pdf = new \FPDM($contractPath); $pdf->Load($fields, false); // second parameter: false if field values are in ISO-8859-1, true if UTF-8 $pdf->Merge(); $pdf->Output();
It works fine with template.pdf but fails on my pdf file. Any ideas what might be the issue or cause of this error?
When I try to Merge data with this pdf file https://dev-sdge-esp.pantheonsite.io/modules/custom/sdge_generic/SDSEP_reservation_request_form.pdf I get "FilterFlateDecode: invalid stream data"
I have fixed the file with pdftk file output file2 but still getting this error.
Hello,
after multiple test, i think that we have some trouble with checkbox.
1 . Checbox must be have "exported value" ( don't now wording exact ) set. ( see that with : https://www.pdfescape.com )
`
if ($verbose_set) {
echo "
Change checkbox of the field $name at line $field_checkbox_line to value [$value]";
}
$state = $this->value_entries["$name"]["infos"]["checkbox_no"];
if ($value) {
var_dump('change state plop : ' . $state);
}
$CurLine =$this->pdf_entries[$field_checkbox_line];
$OldLen=strlen($CurLine);
$CurLine = '/AS /'. $state;
$NewLen=strlen($CurLine);
$Shift=$NewLen-$OldLen;
$this->shift=$this->shift+$Shift;
//Saves
$this->pdf_entries[$field_checkbox_line]=$CurLine;
return $Shift;
`
when we dump var_dump($this->value_entries["$name"]["infos"]) and $this->pdf_entries ( script in and out )
we can see that value of checkox is not changed . Script change state ( $CurLine = '/AS /'. $state; ) but not the value .
So..my pdf checbox is never change.
now if u add :
$this->pdf_entries[$field_checkbox_line - 1]= '/V /' . $state; ( i change value )
It's working !!
But... maybe it's not good and cause trouble.. i don't know.
I
After uppgrading from php 7.4 to php 8.1.5. Fields contatining åäö do not work
FPDF-Merge Error: field Månader not found
Anyone else with this issue?
Sometimes checkboxes are organized as children (/Kids
) of a parent object. Those checkboxes could not be addressed an values could not be set.
THANK YOU for your work!
As noted on the first page, it was based on Script93, you also have asked to keep on eye on fpdf.org for newer versions. Its now on 103 :)
I have recently modified the core-script src/fpdm.php in such a way that it now manages to cope with groups of checkboxes.
At least I think so;)
I'm not familiar with the github-habbits, yet: Shall I upload it here? Maybe after further testing and eliminiting some possible bugs left the modificatiosn might be worth another update.
The example-Form to integrate also contained some ugly umlauts and also a hyphen in the field-definitions. As for this I'd recommend to change the intial regex definition (Line 41) to
$FPDM_REGEXPS= array(
...
"name"=>"//([-#\w]+)/",
...
);
though I think this needs some more testing.
For the checkboxes, if I pass true or a string value or 1, the checkbox is not checked rather if I pass false or an empty string or 0 it gets checked. So I believe the functionality is working in the reverse order contradictory to the documentation provided. Can you please verify this.
Is there a way to create a QR code using information from the field array into a merged pdf? Is it just a matter of creating a QR code type field in the pdf and then sending text to it like other text fields? Do you have any examples of how this might be done?
I don't know all the different layouts for the PDF arrays that can be checkboxes, but the pdf I'm using did not contain "checkbox_no" and "checkbox_yes", but rather just a "checkbox_state". When viewing this, it has the word "Off". I adjusted the the "set_field_checkbox($name, $value)" function to include another if check:
else if(isset($this->value_entries["$name"]["infos"]["checkbox_state_line"]) && isset($this->value_entries["$name"]["infos"]["checkbox_state"])) { $field_checkbox_line=$this->value_entries["$name"]["infos"]["checkbox_state_line"]; if ($field_checkbox_line) { $CurLine =$this->pdf_entries[$field_checkbox_line]; $OldLen=strlen($CurLine); $CurLine = '/AS /'; if($value) { $CurLine .= 'On'; } else { $CurLine .= 'Off'; } $NewLen=strlen($CurLine); $Shift=$NewLen-$OldLen; $this->shift=$this->shift+$Shift; //Saves $this->pdf_entries[$field_checkbox_line]=$CurLine; return $Shift; } else { if ($verbose_set) { echo "<br>Change checkbox value aborted, parsed checkbox definition incomplete."; } }
This does "fill in" my checkbox but not with a "x" or checkmark, but rather just a colored blob/square.
Please provide some examples with a checkbox.
checkbox check and uncheck not working.
When looking at the code I came across this hack in src/fpdm.php
//My PHP4/5 static call hack, only to make the callback $this->replace_value($matches,"$value") possible!
$callback_code='$THIS=new FPDM("[_STATIC_]");return $THIS->replace_value($matches,"'.$value.'");';
$field_regexp='/^\/(\w+)\s?(\<|\()([^\)\>]*)(\)|\>)/';
if(preg_match($field_regexp,$CurLine)) {
//modify it according to the new value $value
$CurLine = preg_replace_callback(
$field_regexp,
create_function('$matches',$callback_code),
$CurLine
);
}else {
if($verbose_set) echo("<br>WARNING:".htmlentities("Can not access to the value: $CurLine using regexp $field_regexp"));
}
PHPs create_function() seems to be deprecated as of 7.2. So this hack might fail in the future.
Is it possible to replace variable text ${var} and generate the new PDF?
How would I submit a PDF, and have it be available to send as an email through SendGrid?
I took an existing pdf with various fields, converted it in Acrobat so the fields will allow input, and then I tested it out. But I'm getting this error now: FPDF-Merge Error: Object streams are not supported
The test worked fine with the template.pdf that was provided in the code. And when I look at the template.pdf in Acrobat, I can't see what the difference between the two .pdfs are.
Hi,
I am new to FPDM and have a problem the first time I use it.
When I want to replace a field whose value is:
/V (\(Saisir l'adresse sur 3 lignes minimum\)\rDESTINATAIRE\rADRESSE \rCP VILLE ))
He replaces with:
/V <20727565206465732063616E61726473>\rDESTINATAIRE\rADRESSE \rCP VILLE )
instead of
/V <20727565206465732063616E61726473>
So I corrected line 836 on /fpdm/fpdm.php :
if(preg_match('#/V\s?[<(]([^>)]*)[>)]#', $CurLine, $a, PREG_OFFSET_CAPTURE))
in
if(preg_match('#/V\s?[<(]([^>]*)[>)]#', $CurLine, $a, PREG_OFFSET_CAPTURE))
But is this the correct correction?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.