Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'insufficient data for an image' message when opening PDF

Tags:

php

image

pdf

tcpdf

My php cli application creates PDF's by using the TCPDF library. In most cases PDF's are created successfully, but sometimes a PDF is created that makes adobe reader pop up the error: 'insufficient data for an image'.

I obviously did some research on this message, and none of the named causes nor provided solutions are relevant in my case or solve the problem. Although Adobe products are the only ones that pop up an error and other PDF viewers can open the corrupt file and display it correct, this doesn't mean it's an adobe related problem. For an advanced PDF editor, NITRO 9, can display the corrupt files but at the same time does detect the issue and pops up an alert.

By using Nitro I am able to fix the PDF file. Steps are: extract the image from the corrupt image object from the pdf and then replace the image in the pdf file by the saved image...

The specific images that trigger the error/alert aren't of one type (f.e. jpg2000). BMP, png and gifs have triggered the erorr/alert as well.

I read in a few similar topics on stackoverflow that the 'XOBJECT stream' might be malformed? However, I have no idea how to check this.

I hope one of you guys knows where to look.

I tried to look for similar topics on the TCPF form as well, but the creator tells the topic starters this is an adobe issue or a pdf issue and he can't help them.

Attached files I have uploaded two pdf files: one with a broken 'image' that triggers an error (naamloos1_bad.pdf) and one that is fixed (naamloos1_fixed.pdf) by using Nitro. You can download them here

I hope someone with knowledge of the PDF file type can compare these and let me know details on what's going wrong so I know what to look for in my code and that of the TCPDF library in order to fix this issue.

The bottom-right image in the PDF file is the one that triggers the alert/error.

Thanks!

like image 838
Maarten Mentzer Avatar asked Jul 25 '14 11:07

Maarten Mentzer


1 Answers

Problem solved for me : when i add image in a pdf with TCPDF, i got the message "insufficient data for an image" on adobe pdf reader when i open my pdf (but same file is ok in chrome). i open the same image in photoshop i got error 'bad profil icc'

so i remove icc profil with imagick (stripimage command)

$sPathImg= 'something.jpg';
$image = new Imagick($sPathImg);
$image->stripImage();
$image->writeImage($sPathImg);

Tadam : No more error when i open my pdf with adobe reader

like image 122
Jérome S. Avatar answered Sep 23 '22 20:09

Jérome S.