Hi people when i use this code it saves the pdf file without problem. But when i use: $pdf->Output("pdf_test.pdf", "I");. It gives me :
FPDF error: Some data has already been output, can't send PDF file
thank for helping
Related
I'm creating a pdf from formdata using fpdf (http://www.fpdf.org/).
Using Jquery I'm able to send the data to the pdf-creating script, and make the pdf appear in browser.
Now I'm trying to return the pdf-data to the formpage using fpdf's option to get the pdf as a string and echoing it.
$pdf_file_contents = $pdf->Output("","S");
echo $pdf_file_contents
My question now is
How do I use this data to preview the pdf under the form?
Do I need to use an pdf-viewer or can I use an <iframe> and am I doing this the correct way by returning the variable in an echo?
I can think of two options:
Embed a PDF viewer and handle that call in JS. (Wait for the response from PHP and display the outputted file inline)
Trigger a redirect or load an iframe which displays $pdf->Output($filename,"F") from a temp file.
The result of $pdf->Output() is displayed using the browser's built-in viewer. If there is any output above that in the page FPDF will return an error to say FPDF error: Some data has already been output, can't send PDF.
FPDF error: Some data has already been output, can't send PDF
There might be some other option I'm missing but those would be my first suggestions.
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!
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
Okay, so at least I found a workaround that I can automatize. I learned nothing more about this issue, but in case this topic ends dead and people read it in the future, here it is:
Im running Linux and calling ghostscript like this:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -dUseCIEColor -sOutputFile=ouput.pdf input.pdf
will repair the pdf in such a way the insufficient data error goes away. (Note that some arguments are set because I need to create pdfs for print. If you dont need it, set dPDFSETTINGS to /screen, f.e.)
Jerome had the answer for me.
In C#:
MagickReadSettings settings = new MagickReadSettings();
ImageMagick.MagickImageCollection images = new MagickImageCollection();
images.Read(sourceFile, settings);
images[0].Strip();
images.Write(targetFile);
i wanna encode my pdf file using FPDF so i used this code :
require('C:\Program Files/EasyPHP-5.3.9/www/PDF/fpdf16/font/makefont/makefont.php');
MakeFont('C:\Windows.old\Windows\Fonts\\comicbd.ttf','cp1250');
but it keeps showing me an error :
Error: AFM file not found: cp1250
can't find where the problem comes from ! Any suggestions ?and can anyone tell me what to do to encode my file?
I can convert html page to pdf and send it via email with out any problem, but I am facing trouble with converting php file to pdf.
is it possible to convert php file to pdf using mpdf or do I need to use some other php class for this?
Thanks!
The option seems to be like, first convert the output of the php file to html file, save it and pass that file to mpdf.
Thought my solution may seem other way round but it worked well for me.
Or otherwise this Link
<?php
$file = '/home/user/Desktop/myfile.html';
$result = file_get_contents("url/of/ur/page");
echo $result; //view source now
file_put_contents($file, $result);
?>
now u can pass this file to mpdf. Realie sorie bt i havnt used mpdf till date. May be this solution works for you.
Also, other option is curl.
http://babymoments.co/preview/highres%20preview/5_357/
According to the FPDF documentation here: http://www.fpdf.org/en/doc/image.htm
You are supposed to be able to use an Image from a dynamic source.. however, as per the first link, i'm getting an fopen error.
Any suggestions?
Code Snippet:
// Overlay Text & Images
$pdf->Image($conf['rbase'].'page_maker/image_hr.php?id=5&side=1&bg=cover_pink&lo=0_1&imgtxt=0|0|u5_1310329746.jpg##1|1|Elina\'s Puppies 9/2/2010|15|arial_bi.ttf|db0ddb|fedfe4&applet_type=cover',$sx,$sh,(0-$dpi), 0, 'png');
You are trying to open a local php file with get parameters - try instead to open the image file as a url. For example :
http://domain.com/image.php?id=5
Or in your case...
http://babymoments.co/preview/page_maker/image_hr.php?id=5&side=1&bg=cover_pink&lo=0_1&imgtxt=0|0|u5_1310329746.jpg##1|1|Elina's%20Puppies%209/2/2010|15|arial_bi.ttf|db0ddb|fedfe4&applet_type=cover
I wouldn't fetch the preview over HTTP but would include the required code and generate the image in the same script that generates the PDF. That way there is no problems with setups that have disabled fopen()-usage with URLs.
I was implementing a barcode for a label printer. So I was using the 'barcodegen' library and 'fpdf' library for this project, but I was having problems including dynamically the image generated with barcodegen, giving me the following error:
FPDF error: Not a PNG file: ./misc/barcodegen/mostrar-codigo-bcgcode39.php
Afeter that, I use one of the answers described here, and I solved the problem using the full URL of the image, like this:
$pdf->Image("http://localhost/caaf/misc/barcodegen/mostrar-codigo-bcgcode39.php",0,0,20,0,'PNG');
And it worked for me.