S
S
sashazaaa2015-09-26 23:09:22
PHP
sashazaaa, 2015-09-26 23:09:22

How to save generated pdf file without errors in tcpdf?

I have a php page that needs to be converted to pdf. I use tcpdf for translation. I include a PHP page using include(). The page is rendered but not saved and throws TCPDF ERROR: Some data has already been output, can't send PDF file.

<?php


require_once('tcpdf.php');

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));

$pdf->AddPage();

$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));

$html = include('file.php');

$pdf->writeHTML($html, 'false', 'false', 'false', 'false', '');
$pdf->Output('example_001.pdf', 'I');
?>

How can I remove this error? Or how to remake the code, so that the page would not be displayed, but saved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2015-09-27
@sashazaaa

Recently I was engaged in pdf generation, the only one that helped normally is mpdf www.mpdf1.com/mpdf/index.php
A good example of using it is here https://github.com/kartik-v/yii2-mpdf/blob/master/...

M
matperez, 2015-09-26
@matperez

Try like this:

ob_end_clean();
$pdf->Output('example_001.pdf', 'I');

But in general, something is output before PDF generation, better figure out what exactly. stackoverflow.com/questions/16011050/tcpdf-error-s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question