FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI
Asked Answered
P

11

38

I am running the following code and giving me this error : FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI. I used another pdf named test.pdf and that works fine but it is giving me error in testcopy.pdf.

I think this is parser problem. Anyone know any other parser that can be used with fpdf to avoid this error?

My code:

require('fpdf17/fpdf.php'); 
require('fpdf17/fpdi.php'); 
// initiate FPDI 
$pdf = new FPDI(); 
while (ob_get_level())
ob_end_clean();
header("Content-Encoding: None", true);
// set the sourcefile 
$pagecount = $pdf->setSourceFile('testcopy.pdf');

I want to split pdf in two pdfs and want to attach both pdfs in file attachments field.How to save pdf to server. Can it be possible with fpdf?

Papyrus answered 28/8, 2012 at 6:54 Comment(2)
I have not faced such issue before. BTW, here is a similar question which might help: #5441607Hydrograph
thnx.. i checked this question but didn't help me.. i want to know if there is any parser can be used with fpdf??? I think Fpdi didn't support all type pdf format.Papyrus
T
54

Yes, Exactly the FPDI library supports only PDF version 1.4 & lesser. So to over come from this issue use GhostScript. This script helps to change the PDF versions dynamically.

(1) Download the Ghostscript here.

(2) Install the Ghostscript and define the environment variable PATH.

(3) Then, use the below php code to change the PDF version.

shell_exec( "gswin32 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf.""); 

(4) Now we get PDF with version 1.4 as output, then continue with FPDI.

Enjoy!

Till answered 10/4, 2015 at 11:52 Comment(5)
Thanks for this ! I had to change gswin32 to gs for this to workTrumpetweed
What do you mean by "define the environment variable PATH"? Thanks in advance.Pomeroy
@Pomeroy It means you should add the path of ghostscript executable to the PATH variable on your Windows OS. search this keyword and it will tell you how. "adding path to windows"Stoneware
This should be marked as answer this is so far the very best shot I saw.Bookcase
this link shows how it is done using a full practical example, it may help someone: infoconic.com/blog/…Countermand
K
29

I had the same issue that PDFMerger does not work with certain PDF. It seems that Adobe keep updating compression way of pdf extension.

I found solution with Chrome.

1. Open the PDF file(which does not work with PDFMerger) with Chrome
2. Right Click and Print
3. Change destination as [Save as PDF]
4. This exported PDF file is compatible with PDFMerger
Kala answered 13/9, 2017 at 6:11 Comment(1)
I used to use Ghostscript to do this but this does indeed work, way more convenient. Thanks!Noncompliance
U
18

Looking through the answers so far, I wasn't able to resolve the issue. Here's why and you may have the same issue so this answer would be invaluable to you too.

I did not have access to acrobat, so I couldn't downgrade the version of the original PDF. I wasn't in a position to purchase the newer version of the library which has upgraded encryption.

In the end I used an online PDF converter to downgrade my PDF file to version 5 (1.4)

If you are not able to find one, here's a link for completeness.

https://docupub.com/pdfconvert/

(bear in mind that the contents of a link may change)

Unready answered 15/2, 2016 at 10:53 Comment(2)
This should be the accepted answer. By far the easiest approach.Haller
Thank you! You save my time! Best answer))Acuity
O
15

The file needs to be PDF 1.4 (Acrobat 5) or lower. If you have Adobe Acrobat Pro you can change this with Document->Decrease File Size.

Ostia answered 12/9, 2012 at 11:8 Comment(0)
T
6

Here is my answer from another topic:

"It can be overcome by re-saving the template and change compression type. In Adobe Acrobat Pro go to File->Save As->Optimised PDF-> Popup left list - Clean Up, Object Compression Options -> Change to "Compress document structure" -> OK to save"

Ref. Editing password protected pdfs with fpdi

Troudeloup answered 14/12, 2012 at 13:6 Comment(0)
W
3

GPL Ghostscript 8.70 (2009-07-31) / Centos 7

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new_file.pdf file.pdf
Whelm answered 23/6, 2021 at 17:0 Comment(0)
A
1

For those that don't have any of the pro versions of Acrobat:

I was having this problem with new versions of Word when trying to use the Office functionality to save to a PDF. It seems the PDF conversion tool supplied in Office is using the newer formats. Here's how I fixed it.

  • Install NitroPDF free version (May work with another free PDF creator that can be downloaded)
  • Go to the Word document and select 'Print'.
  • In the print options, instead of your printer, select 'Nitro PDF Creator (Reader 3)' or whatever the current version is.
  • A dialog box will open and allow you to select where to save the PDF.

The version saved was able to be opened by FPDF.

Hope it helps

Antoninaantonino answered 18/8, 2013 at 17:23 Comment(1)
Chrome seems to do the same thing, open in Google Chrome and print as PDFHouseroom
C
1

In the case of Mac, you can open the PDF file in Preview and "export as PDF". The exported one can then be used.

Caraway answered 9/11, 2020 at 6:31 Comment(0)
C
0

I had a very similar error like you. My solution was to convert the pdf to a lower pdf version. Than everything worked like expected.

I hope that simple trick will help you!

Clintonclintonia answered 1/9, 2012 at 8:32 Comment(1)
i know that i was asking about another parser that can be used with fpdf that support all type version.Papyrus
F
0

if your PHP server is running on linux. use this :

shell_exec( "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf."");

but if you need a synchronous process inside your PHP script. then use this instead:

exec( "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=".$new_pdf." ".$old_pdf."");

Frontier answered 18/6 at 8:1 Comment(0)
C
0

I had same problem . I solved it with qpdf

i was trying to merge some PDF file into one PDF . And for some it shows me

This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details)

I ran all merging command and executed using exec() function.

function mergePdfsWithCommand($outputFile, $inputFiles)
{
    // Construct the QPDF command
    $command = ['qpdf', '--empty', '--pages'];
    foreach ($inputFiles as $file) {
        $command[] = $file;
    }
    $command[] = '--';
    $command[] = $outputFile;
    $text = implode(' ', $command);

    // Execute the command
    exec($text, $output, $returnVar);

    if ($returnVar !== 0) {
        return "Error: Unable to process PDF file.";
    }

    return $outputFile;
}
Concerto answered 30/6 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.