Rick Scolaro
Rick Scolaro

Reputation: 495

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

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:

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?

Upvotes: 4

Views: 2633

Answers (1)

imclean
imclean

Reputation: 349

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;

Upvotes: 7

Related Questions