Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FPDM Merge Error extract_pdf_definition_value() does not support definition '/Type'

Tags:

merge

pdf

fpdf

I'm trying to fill out my PDF document using FPDM with a script I found here:

http://www.fpdf.org/en/script/script93.php

First, keep in mind that I don't want to install any additional libraries on the shared hosting setup I am using. I would have to switch hosts to do this.

Here's what I've tried:

  • Downgrading my PDF template to Acrobat 5.x (v1.4)
  • Disabling compression and fast web mode
  • Using the paid version of PDFTK and the Advanced output params "%PDFTK% %PDFIN% output %PDFOUT%" to modify the template I'm using (this prevents the weird error about object streams)
  • Used variations of FDF files with a different method.
  • Successfully wrote out an HTML version of my PDF, but it didn't look like my template exactly

My code:

require('/libs/fpdm/fpdm.php');

$fields = array(
    'dealer_name'    => 'My name',
    'dealer_address' => 'My address',
    'dealer_phone'    => 'My city',
);

$pdf = new FPDM('/some/pdf/filename.pdf');
$pdf->Load($fields, false);
$pdf->Merge();
$pdf->Output('someoutput.pdf', 'F');

The Error

The error that I cannot seem to find anywhere is the following:

<b>FPDF-Merge Error:</b> extract_pdf_definition_value() does not support definition '/Type'

The Question

Are there any other things I can do to my PDF or any other methods to make this work?

like image 311
Rick Scolaro Avatar asked Aug 31 '25 22:08

Rick Scolaro


1 Answers

fpdm.php is quite old but can be fixed up. The problem is the global variables can't be accessed from within the class FPDM.

To resolve the issue, the global variables need to be moved inside the class as protected properties.

Step 1

Remove the following lines:

$FPDM_FILTERS=array(); //holds all supported filters
$FPDM_REGEXPS= array(
    "/Type"=>"/\/Type\s+\/(\w+)$/",
    "/Subtype" =>"/^\/Subtype\s+\/(\w+)$/"
);

Step 2

Put the following immediately after "class FPDM {", around line 65:

protected $FPDM_FILTERS = array(); //holds all supported filters
protected $FPDM_REGEXPS = array(
        "/Type"=>"/\/Type\s+\/(\w+)$/",
        "/Subtype" =>"/^\/Subtype\s+\/(\w+)$/"
);

Step 3

Delete all instances of global $FPDM_FILTERS; and global $FPDM_REGEXPS;.

Step 4

Update the remaining references (except the property declarations).

Change $FPDM_FILTERS to $this->FPDM_FILTERS

Change $FPDM_REGEXPS to $this->FPDM_REGEXPS

Step 5

To properly include filters from the filters/ directory, we need to move the includes into the class. Remove the require_once()s from the beginning of the file then add the following at the beginning of the constructor FPDM()

          $FPDM_FILTERS = array();
          //Major stream filters come from FPDI's stuff but I've added some :)
          require_once("filters/FilterASCIIHex.php");
          require_once("filters/FilterASCII85.php");
          require_once("filters/FilterFlate.php");
          require_once("filters/FilterLZW.php");
          require_once("filters/FilterStandard.php");                  
          $this->FPDM_FILTERS = $FPDM_FILTERS;
like image 76
imclean Avatar answered Sep 04 '25 03:09

imclean