Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read only option #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/fpdm.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function Allow($permissions=null) {
*@internal flatten mode is not yet supported
*@param Boolean flatten Optional, false by default, if true will use pdftk (requires a shell) to flatten the pdf form
**/
function Merge($flatten=false) {
function Merge($flatten=false,$read_only=false) {
//------------------------------

if($flatten) $this->Flatten();
Expand Down Expand Up @@ -504,7 +504,7 @@ function Merge($flatten=false) {
//==== Alterate work is made here: change values ============
if($count_fields) {
foreach($fields as $name => $value) {
$this->set_field_value("current",$name,$value);
$this->set_field_value("current",$name,$value,$read_only);
// $value=''; //Strategy applies only to current value, clear others
// $this->set_field_value("default",$name,$value);
// $this->set_field_value("tooltip",$name,$value);
Expand Down Expand Up @@ -823,7 +823,7 @@ function _encode_value($str) {
return $this->_bin2hex($str);
}

function _set_field_value2($line,$value,$append) {
function _set_field_value2($line,$value,$append,$read_only) {
$CurLine=$this->pdf_entries[$line];
$OldLen=strlen($CurLine);

Expand All @@ -843,6 +843,9 @@ function _set_field_value2($line,$value,$append) {
else
$this->Error('/V not found');
}
if ($read_only) {
$CurLine .= ' /Ff 1';
}

$NewLen=strlen($CurLine);
$Shift=$NewLen-$OldLen;
Expand All @@ -859,7 +862,7 @@ function _set_field_value2($line,$value,$append) {
*@param string $name name of the field annotation to change the value
*@param string $value the new value to set
**/
function set_field_value($type,$name,$value) {
function set_field_value($type,$name,$value,$read_only=false) {
//------------------------------------
$verbose_set=($this->verbose&&($this->verbose_level>1));

Expand All @@ -886,9 +889,9 @@ function set_field_value($type,$name,$value) {
if($verbose_set) echo "<br>Change $type value of the field $name at line $field_value_line to '<i>$value</i>'";
$offset_shift=$this->_set_field_value($field_value_line,$value);*/
if(isset($this->value_entries[$name]["values"]["current"]))
$offset_shift=$this->_set_field_value2($this->value_entries[$name]["values"]["current"],$value,false);
$offset_shift=$this->_set_field_value2($this->value_entries[$name]["values"]["current"],$value,false,$read_only);
else
$offset_shift=$this->_set_field_value2($this->value_entries[$name]["infos"]["name_line"],$value,true);
$offset_shift=$this->_set_field_value2($this->value_entries[$name]["infos"]["name_line"],$value,true,$read_only);
}
// }else
// $this->Error("set_field_value failed as invalid valuetype $type for object $object_id");
Expand Down