0Day Forums
FPDF error: Some data has already been output, can't send PDF - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: CMS (https://0day.red/Forum-CMS)
+---- Forum: Drupal (https://0day.red/Forum-Drupal)
+---- Thread: FPDF error: Some data has already been output, can't send PDF (/Thread-FPDF-error-Some-data-has-already-been-output-can-39-t-send-PDF)

Pages: 1 2


FPDF error: Some data has already been output, can't send PDF - shackle783 - 07-24-2023

I am using the [fpdf][1] 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.


[1]:

[To see links please register here]




RE: FPDF error: Some data has already been output, can't send PDF - batik216 - 07-24-2023

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.




RE: FPDF error: Some data has already been output, can't send PDF - charleyxig - 07-24-2023

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 :-)




RE: FPDF error: Some data has already been output, can't send PDF - hutchins315 - 07-24-2023

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)*


RE: FPDF error: Some data has already been output, can't send PDF - sejm863 - 07-24-2023

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.



RE: FPDF error: Some data has already been output, can't send PDF - photoinductive718934 - 07-24-2023

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


RE: FPDF error: Some data has already been output, can't send PDF - lawmaker228 - 07-24-2023

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.



RE: FPDF error: Some data has already been output, can't send PDF - fine360955 - 07-24-2023

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();
?>

[To see links please register here]


[To see links please register here]




RE: FPDF error: Some data has already been output, can't send PDF - sozine320819 - 07-24-2023

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();
?>


RE: FPDF error: Some data has already been output, can't send PDF - Drmecham0 - 07-24-2023

First step
check the permissions on the folders
second step
put this

ob_start();

before the line

$pdf->Output();