Related
I have a simple app where the php file updates the database then it generates a pdf file and stores in local folder. below is the code. the pdf file is getting generated and working fine. but am not able to add text into it. when i insert image its working. but inserting cell or text is not working. i dont know whats gone wrong.. pl;z help me.. thanks
$pdf = new FPDF();
$pdf->AddPage();
// $pdf->Image('images/logo.png',90,15,90,0,'PNG');
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output("pdffiles/testsuccess.pdf",'F');
When I test your code it works fine for me. The only thing I DON'T see in your code is the require statement for the fpdf.php file.
heres the FULL php file contents for the example that works for me:
<?php
require('fpdf/fpdf.php'); // MAKE SURE YOU HAVE THIS LINE
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output("testsuccess.pdf",'F');
?>
Finally, I found it.. weird but it will be very useful for the developers who is new to fpdf... I have mentioned that image is working and only text is not working.. Means you should include the fonts folder which comes with fpdf when downloading. If fonts folder is missing it does not print any text..
Thank you
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 FPDF class to generate a pdf on my website. Everything worked well until last few weeks when I started getting error:
FPDF error: Some data has already been output, can't send PDF file
During last few weeks haven't change anything in my code and I have also checked for any output execpt the fpdf (including unecessary space before php, disabled BOM signature etc.)
I have my website on 000webhost.com so I have also disabled the analytic code at the end of the page, but the pdf still doesn't work. The only trace I have left is misterious "" in a source code (I can see it when checking source code in Chrome browser).
I cant get to work even this simple example:
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Is there a way to disable any other output on web page by php? or does someone use fpdf on 000webhost?
just insert ob_end_clean(); before outputing.
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
ob_end_clean();
$pdf->Output();
?>
I think that session.auto_start is set to 1. This will start a session and send a PHPSESSID cookie to the browser.
You can try to disable it using the following code:
<?php
ini_set("session.auto_start", 0);
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
In case setting session.auto_start to 0 does not work, then try this:
<?php
ob_start();
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage()
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush();
?>
In my case i had set:
ini_set('display_errors', 'on');
error_reporting(E_ALL | E_STRICT);
When i made the request to generate the report, some warnings were displayed in the browser (like the usage of deprecated functions).
Turning off the display_errors option, the report was generated successfully.
Use line like this:
require('fpdf.php'); ob_end_clean(); header("Content-Encoding: None", true);
Issue will resolved ;)
This error will occur if you try to generate the PDF after you have already rendered something else on that browser page, for example, if you have done something like this:
echo $value;
The FPDF code wants a "blank canvas" to render its output on (or, one surmises, a blank iframe, although I haven't tested that yet).
SELECT motivo,
unidad_trans,
km_inicial,
km_final,
rut_chofer,
To_char(hora_inicial, 'DD/MM/YYYY HH:mm'),
To_char(hora_final, 'DD/MM/YYYY HH:mm'),
total_recorrido,
destino,
cod_combustible,
cantidad_litros,
cod_vehiculo,
d.cod_estableci
FROM mov_bitacora b,
mov_chofer c,
nuc_dependencias d,
mov_combustible co,
mov_vehiculo v
WHERE b.unidad_tran = d.cod_estableci
AND b.rut_chofer = c.rut_chofer
AND b.cod_combustible = co.cod_combustible
AND b.cod_vehiculo = v.cod_vehiculo
AND id_bitacora = 6fpdf
Error: Some data has already been output, can't send PDF file.
I putted this to fix this problem in the beggining (ob_clean) doesn't change PDF structure:
require('fpdf/fpdf.php');
ob_clean();
well I get this error trying to use php class FPDF:
FPDF error: Some data has already been output, can't send PDF file (output started at
/mnt/webc/e1/12/5691512/htdocs/adminpanel/fpdf/test.php:1)
My test.php
<?php
require_once("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
There are no blanks or anything... So where is the error???
Some editors adds BOM at the start of a file.
View your file in hex and remove it
it is becouse of two reason
1-there is no leading space before the opening
2-are some data has been output before
The solution of 2 reson is
go to fpdf.inc.php
and find this funciton
function Output($name='', $dest='') {
and then in the defination of this function write this at starting
ob_clean();
this will clean the previous output.
For me, it was the deprecation warnings. I added & ~E_DEPRECATED to my error_reporting in my php.ini and rebooted Apache.
I got same problem in Live Server only. But its working on Local Machine. Adds BOM at the start of a file also its not working on Server. But working in local Machine. Some changes need in your Live code.
1. Place the ob_start() in first line of your file.
Example:
ob_start();
$DOCROOTPATH = $_SERVER['DOCUMENT_ROOT'];
$DOCROOTBASEPATH = dirname($_SERVER['DOCUMENT_ROOT']);
include_once($DOCROOTPATH."/lib/commonarray.inc");
include_once($DOCROOTPATH."/includes/class.payslip.php");
include_once($_SERVER['DOCUMENT_ROOT']."/menucontrol.php");
define('FPDF_FONTPATH','fpdf/font/');
require('fpdf/fpdf.php');
2. After the $pdf->Output(),you should place ob_end_flush() in Same File .
Example:
$pdf=new PDF();
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$pdf->pdfAllPages();
$pdf->Output();
ob_end_flush();
Now go to hit the browser and see the pdf which you want.
(OR)
Some editors adds BOM at the start of a file.
View your file in hex and remove it
I am using the fpdf library for my project, and I'm using this to extend one of the drupal module. These lines
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
give me an error: FPDF error: Some data has already been output, can't send PDF
I tried creating this in a separate file outside the drupal area name test.php and when viewed it worked. Anyone here know why this don't work? Or anyone here can point me a right pdf library which I can use in drupal to view HTML to PDF format.
For fpdf to work properly, there cannot be any output at all beside what fpdf generates. For example, this will work:
<?php
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
While this will not (note the leading space before the opening <? tag)
<?php
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Also, this will not work either (the echo will break it):
<?php
echo "About to create pdf";
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
I'm not sure about the drupal side of things, but I know that absolutely zero non-fpdf output is a requirement for fpdf to work.
add ob_start (); at the top and at the end add ob_end_flush();
<?php
ob_start();
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush();
?>
give me an error as below:
FPDF error: Some data has already been output, can't send PDF
to over come this error:
go to fpdf.php in that,goto line number 996
function Output($name='', $dest='')
after that make changes like this:
function Output($name='', $dest='') {
ob_clean(); //Output PDF to so
Try to save the file without the option: "BOM comment", i.e. in Adobe Dreamweaver, you Save File As..., uncheck the box below the filename that says, "Include Unicode signature(BOM)".
On Notepad++ you should select the menu: Encoding, "Encode in UTF-8 without BOM".
And make it default for other files you create, it will spare you a lot of headaches in future.
Hi do you have a session header on the top of your page.
or any includes
If you have then try to add this codes on top pf your page it should works fine.
<?
while (ob_get_level())
ob_end_clean();
header("Content-Encoding: None", true);
?>
cheers :-)
In my case i had set:
ini_set('display_errors', 'on');
error_reporting(E_ALL | E_STRICT);
When i made the request to generate the report, some warnings were displayed in the browser (like the usage of deprecated functions).
Turning off the display_errors option, the report was generated successfully.
The FPDF Error Message will point you to the PHP Line that is sending some content.
If you get no hint what File & Line send some content you probably have an encoding mismatch in your include / require Files.
For me
fpdf.php was ANSI-encoded,
my pdf-generator.php was UTF-8-encoded and
my database-connect-inlude was UTF-8-encoded (this UTF-8-encoding did raise the FPDF error. I had to switch it back to ANSI)
if you're code outputs notices/warnings before the PDF generation, try turning them off. error_reporting(0). Then work on the warnings there-after
Add to the beginning of the script
ob_start();
require ('fpdf.php');
and at the end, after output()
ob_end_flush();
It worked for me! =)
First step
check the permissions on the folders
second step
put this
ob_start();
before the line
$pdf->Output();
I used the following and it worked for me
require_once ('pdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output(F,'/var/www/html/PATH/filename.pdf');
ob_end_flush();
Even a single space in the included php files causes that warning. There shouldn't be any output in any way.
You need to call the library
require ('fpdf.php');
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'¡Hola, Mundo!');
$pdf->Output();
?>
http://www.fpdf.org/
http://www.fpdf.org/es/tutorial/tuto1.htm
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can't send PDF file (output started at /home/asri123/public_html/bill/invoice/invoice.php:743)' in /home/asri123/public_html/bill/invoice/fpdf.php:271 Stack trace: #0 /home/asri123/public_html/bill/invoice/fpdf.php(1052): FPDF->Error('Some data has a...') #1 /home/asri123/public_html/bill/invoice/fpdf.php(1012): FPDF->_checkoutput() #2 /home/asri123/public_html/bill/invoice/mirasbill.php(262): FPDF->Output('MSFS/2018-19/76...', 'D') #3 {main} thrown in /home/asri123/public_html/bill/invoice/fpdf.php on line 271
Another answer that nobody else has posted here... Double-check the encoding of your PHP file and make sure that it's not something other than UTF-8. The wrong code editor (or FTP upload?) can mess with the file's encoding in which case none of the other fixes mentioned in this thread will help.