1

hi, I'm trying this code that creates a div dynamically by values ​​taken from a form ...
<?php $html = " <style> #contenitore { width:".$width."; height:".$height."; background:#ffffff; display:table; } #testo{ display:table-cell; vertical-align:middle; text-align:center;} span.primariga { font-size:".$grandezza_font1."; font-family:".$tipo_font1."; } span.secondariga { font-size:".$grandezza_font2."; font-family:".$tipo_font2."; } </style> <div id=contenitore> <div id=testo> <span class=primariga>".$prima_riga."</span><br> <span class=secondariga>".$seconda_riga."</span> </div> </div>"; echo $html; require_once(dirname(__FILE__).'/html2pdf.class.php'); $html2pdf = new HTML2PDF('P','A4','it'); $html2pdf->WriteHTML($html); $html2pdf->Output('exemple.pdf'); ?>

but the result is this error:

Warning: Cannot modify header information - headers already sent by (output started at /xxx/xxx/xxx/xxx/timbri/indextimbri.php:14) in /xxx/xxx/xxx/xxx/timbri/_tcpdf_5.0.002/tcpdf.php on line 6122
TCPDF ERROR: Some data has already been output to browser, can't send PDF file

can you help me please?

2

Hello guys !

Try simply to remote echo $html ;

You display $html before do $htm2pdf->Output() but echo send date before $htm2pdf->Output() so that's why you got this error !!

Have a nice day smile

3

hello and thank you for your reply ... I've moved "echo" after the code like you said but I have always the same error at line 14, where there is ...

<?php
$width = 403;
$height = 142;

// PRIMA RIGA
$prima_riga = $_POST['prima_riga'];
$grandezza_font1 = $_POST['grandezza_font'];
$tipo_font1 = $_POST['tipo_font1'];
$grassetto1 = $_POST['checkb1'];
$corsivo1 = $_POST['checkc1'];

ecc... ?>

which are the variables that make up the html code I want to print to pdf ...
how can I do? thanks

4

Hello again , try to move your require_once at the first line after <?php , tcpdf.php uses some header('xxxx') fonction on the files, maybe the problem is here...

And i don't understand what you want to do at all ... So if you can explain a little bit more it could be great wink

5

practically is a online application for creating stamps ... the user changes the lines of text that are placed in the variables that change the css ... everything is written in a variable ($ html) and should be saved in pdf ...here's the code
line 14 <?php $width = 403; $height = 142; // PRIMA RIGA $prima_riga = $_POST['prima_riga']; $grandezza_font1 = $_POST['grandezza_font']; $tipo_font1 = $_POST['tipo_font1']; $grassetto1 = $_POST['checkb1']; $corsivo1 = $_POST['checkc1']; if (isset ($grassetto1)) { $grassetto1 ="bold"; }else{ $grassetto1="normal";} if (isset ($corsivo1)) { $corsivo1 ="italic"; }else{ $corsivo1="normal";} // SECONDA RIGA $seconda_riga = $_POST['seconda_riga']; $grandezza_font2 = $_POST['grandezza_font2']; $tipo_font2 = $_POST['tipo_font2']; $grassetto2 = $_POST['checkb2']; $corsivo2 = $_POST['checkc2']; if (isset ($grassetto2)) { $grassetto2 ="bold"; }else{ $grassetto2="normal";} if (isset ($corsivo2)) { $corsivo2 ="italic"; }else{ $corsivo2="normal";} // TERZA RIGA $terza_riga = $_POST['terza_riga']; $grandezza_font3 = $_POST['grandezza_font3']; $tipo_font3 = $_POST['tipo_font3']; $grassetto3 = $_POST['checkb3']; $corsivo3 = $_POST['checkc3']; if (isset ($grassetto3)) { $grassetto3 ="bold"; }else{ $grassetto3="normal";} if (isset ($corsivo3)) { $corsivo3 ="italic"; }else{ $corsivo3="normal";} // QUARTA RIGA $quarta_riga = $_POST['quarta_riga']; $grandezza_font4 = $_POST['grandezza_font4']; $tipo_font4 = $_POST['tipo_font4']; $grassetto4 = $_POST['checkb4']; $corsivo4 = $_POST['checkc4']; if (isset ($grassetto4)) { $grassetto4 ="bold"; }else{ $grassetto4="normal";} if (isset ($corsivo4)) { $corsivo4 ="italic"; }else{ $corsivo4="normal";} ?> <?php $html = " <page><style> #contenitore { width:".$width."; height:".$height."; background:#ffffff; display:table; } #testo{ display:table-cell; vertical-align:middle; text-align:center; line-height:5px;} p.primariga { font-size:".$grandezza_font1."; font-family:".$tipo_font1."; color:#000000; margin-top:10px; margin-bottom:20px; font-weight:".$grassetto1."; font-style:".$corsivo1."; line-height:10px; } p.secondariga { font-size:".$grandezza_font2."; font-family:".$tipo_font2."; color:#000000; margin-bottom:20px; font-weight:".$grassetto2."; font-style:".$corsivo2."; } p.terzariga { font-size:".$grandezza_font3."; font-family:".$tipo_font3."; color:#000000; margin-bottom:20px; font-weight:".$grassetto3."; font-style:".$corsivo3."; } p.quartariga { font-size:".$grandezza_font4."; font-family:".$tipo_font4."; color:#000000; margin-bottom:20px; font-weight:".$grassetto4."; font-style:".$corsivo4."; } </style> <div id=contenitore> <div id=testo> <p class=primariga>".$prima_riga."</p> <p class=secondariga>".$seconda_riga."</p> <p class=terzariga>".$terza_riga."</p> <p class=terzariga>".$quarta_riga."</p> </div> </div></page>"; require_once(dirname(__FILE__).'/html2pdf.class.php'); $html2pdf = new HTML2PDF('P','A4','it'); $html2pdf->WriteHTML($html); $html2pdf->Output('exemple.pdf'); echo $html; ?>

6

can you help me? how do I save a pdf from a dynamic variable?

7

Hello,
You can try with output buffering :

ob_start(); // at the beggining of your script
$html = ob_get_clean();
$html = 'your html content';

etc...

ob_clean(); // at the end of your script

8

in the end we are able to create a function and moving the creation of the pdf in another page ...