I generated a PDF using the dompdf library and used this:
$dompdf->stream('my.pdf',array('Attachment'=>0));
to force the browser to let the user view the PDF before downloading. But it's not working. A Google search isn't bringing up any answers either. Can anyone help?
Try using the below code. Let me know are you create data from form or html file data.
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
If someone still looking for answer and it's still not resolved, try installing and turning on the PDF Viewer / PDF JS extension in the browser.
After adding parameter array(“Attachment”=>0) or array(“Attachment”=>false) to the stream and still not working. It's because your browser doesn't have a pdf reader available/activated. Installing and activating browser extension like PDF Viewer / PDFJS will force the browser to read and review the pdf.
Try this
$dompdf->stream("", array("Attachment" => false));
Instead of
$dompdf->stream();
It worked for me
Related
I generated a PDF using the dompdf library and used this:
$dompdf->stream('my.pdf',array('Attachment'=>0));
to force the browser to let the user view the PDF before downloading. But it's not working. A Google search isn't bringing up any answers either. Can anyone help?
Try using the below code. Let me know are you create data from form or html file data.
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
If someone still looking for answer and it's still not resolved, try installing and turning on the PDF Viewer / PDF JS extension in the browser.
After adding parameter array(“Attachment”=>0) or array(“Attachment”=>false) to the stream and still not working. It's because your browser doesn't have a pdf reader available/activated. Installing and activating browser extension like PDF Viewer / PDFJS will force the browser to read and review the pdf.
Try this
$dompdf->stream("", array("Attachment" => false));
Instead of
$dompdf->stream();
It worked for me
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);
My PDF file cannot be opened with Adobe Reader. What's weird is that the PDF used to work in Adobe Reader just a few days ago and now it does not work, and of course I didn't modify the code otherwise it would be easy to fix.
I validated my PDF and learned it was a PDF/A-3, could be that it is not a PDF/A-1? If so why did it work for a time and suddenly stopped working?
EDIT
The problem was that somehow, some HTML code was output inside the PDF file, thus making the PDF file invalid for Adobe Reader, but not for Firefox, making all this much more confusing than it should be.
So a tip to anyway having trouble with PDF, open it with a text editor such as Notepad++ for Windows or GEdit for Linux, and compare with another PDF file which works fine. You should find the problem pretty quickly.
I read a lot of questions about this and I understood that the problem is happening with:
ob_start();
Without this line, my FPDF was not working with the message explained that there was another buffer first.
With this line, the PDF was readable only with Browser.
I changed this line to:
ob_clean();
and now I can open PDF with any reader.
This was happening to me, too. It did work in Firefox for me, but not in Chrome and it wouldn't open in Adobe.
The problem was that I was trying to run the script in a function and calling the function from a button. I fixed it simply by adding the script to it's own PHP file, and then linking to the php file directly.
Note: I did try ob_start() (and alternatively ob_clean() as noted in the other answer) and ob_end_flush(), but it didn't make a difference in the function. When it's in its own file it doesn't need it anyway.
// file.php
<?php
require $_SERVER['DOCUMENT_ROOT'].'/wp-content/plugins/eri-webtools-plugin/libraries/fpdf/fpdf.php'; // <-- File path for WordPress plugin
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output(); // To Download, use $pdf->Output('D', 'test.pdf', true);
?>
// html
View PDF
I am using Codeigniter as a PHP framework and DOM PDF to generate pdf files. I have the following codes in my Controller.
// Some other codes
include_once('dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$base_path = $_SERVER['DOCUMENT_ROOT'];
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("invoice_$studentid.pdf");
redirect("my_Controller");
The problem is after generating the pdf file it is not redirecting to the Controller. Could you please tell me how to solve this problem?
$dompdf->stream is sending the PDF to the browser. You can't also send a redirect header. You're trying to output two responses to one request, which is impossible.
This doesn't seem like it should be a problem. The browser will stay on whichever page the user was on when they clicked the link to download the PDF. If you really want them to be forced elsewhere (you probably don't, that's a very different user experience from how download links work everywhere else) you could do something with JavaScript.
I am done with generating PDF file using FPDF in php. But the problem is how to open this pdf without the Save As option? I want to display the pdf document in the browser.
http://www.fpdf.org/en/doc/output.htm
Syntax: Output([string name] , string dest) , use I as Destination and fdpf will try to show it in the browser, if browser plugings and so on enable it
You cannot force this display, as it is up to the user to choose to display the PDF inline or systematically save them. I prefer the second option...
Now, there is a JavaScript / HTML 5 project (experimental!) to display PDF without plugin, so perhaps you can try that.
Even when using fpdf passing the output to the browser, I believe its still up to the user if they open or save it.
A solution would be to use some kind of PDF viewer, for example http://view.samurajdata.se/
Try this $pdf->Output('I', 'filename.pdf')
See the reference http://www.fpdf.org/en/doc/output.htm
Set header's content-type to 'application/pdf'. Then, most browsers will try to open it and show in-browser (or at least ask user to save or open file)
Your browser must have pdf plugin installed. If you havent done so install latest version of Acrobat Reader. If you are using fpdf, output the string instead of forcing download
For details
http://www.fpdf.org/en/doc/output.htm
Try echoing the PDF instead to using header function. The header function will force the browser to download. The echo 'might' show the pdf.