PDA

View Full Version : [php e tcpdf]


zebmckey
29-03-2018, 15:15
Buongiorno a tutti,
vorrei scrivere il risultato di una query su di un pdf ma non riesco a fargli vedere le variabili. Vi allego il file php per farvi capire meglio:

<?php
session_start ();
require_once ('../conf/conf.php');
require_once('../tcpdf_include.php');
$con = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!isset($_GET['stampa']))
{
die ("Error, ID selezionato inesistente");
}
$idcorso=addslashes(htmlspecialchars($_GET['stampa']));


$data = "SELECT idcorso,grado,cognome,nome,reparto,corso,header,data_inizio,data_fine,data_esame,giudizio,superato,voto,email FROM persg,gradi,bcorsi,tipo_corso
WHERE persg.idgrado=gradi.idgrado AND bcorsi.user=persg.idpersinsp AND bcorsi.tipo_corso=tipo_corso.idtipocorso AND tipo_corso.idtipocorso=tipo_corso.header AND bcorsi.idcorso=$idcorso;";
$result = mysqli_query($con,$data);
if(!$result)
{
die("Database query failed: " . mysqli_error());
}
while ($row = mysqli_fetch_array($result))
{
$id=$row["idcorso"];
$grado=$row["grado"];
$cognome=$row["cognome"];
$nome=$row["nome"];
$reparto=$row["reparto"];
$email=$row["email"];
$corso=$row["corso"];
$header=$row["header"];
$data_inizio=$row["data_inizio"];
$data_fine=$row["data_fine"];
$data_esame=$row["data_esame"];
$superato=$row["superato"];
$giudizio=$row["giudizio"];
$voto=$row["voto"];
}

// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// get the current page break margin
$bMargin = $this->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $this->AutoPageBreak;
// disable auto-page-break
$this->SetAutoPageBreak(false, 0);
// set bacground image
$img_file = K_PATH_IMAGES.'Immagine1.jpg';
$this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
$this->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$this->setPageMark();
}
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Autore ');
$pdf->SetTitle('Attestato');
$pdf->SetSubject('Corsi');
$pdf->SetKeywords('TCPDF, PDF, corsi');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);

// remove default footer
$pdf->setPrintFooter(false);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/ita.php')) {
require_once(dirname(__FILE__).'/lang/ita.php');
$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
//$pdf->SetFont('times', '', 12);

// add a page
$pdf->AddPage();

// Print a text
$pdf->SetFont('times', '', 24);

$html = <<<EOT
'<h1 style="text-align: center;"><strong>ATTESTATO DI FORMAZIONE</strong></h1>

<h3 style="text-align: center;"><em><strong> $header si attesta che il </strong></em></h3>

<h2 style="text-align: center;"><strong> $grado $cognome $nome </strong></h2>'
EOT;

$pdf->writeHTML($html, true, false, true, false, '');


// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('corso.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+
?>


nelaa variabile $html non mi vede le variabili $header, $grado, $cognome e $nome.
Come posso risolvere?
Grazie

Nuke987
29-03-2018, 20:31
Premesso che potresti omettere l'apostrofo ' di apertura e chiusura all'interno di EOL, almeno "ATTESTATO DI FORMAZIONE" e "si attesta che il" dovresti riuscire a vederlo. Se vedi una pagina bianca direi che da qualche parte prima nel codice si verifica un fatal error. Attiva la visualizzazione degli errori e vedi che cosa ti dice.

zebmckey
30-03-2018, 07:40
Vedo tutto tranne il valore delle variabili.
error_log mi restituisce:

PHP Notice: Undefined variable: header ....
PHP Notice: Undefined variable: grado ....
PHP Notice: Undefined variable: nome ....
PHP Notice: Undefined variable: cognome ....

iezzetto
17-04-2018, 09:27
Ciao,

dovresti utilizzare la parentesi graffe in questo caso..

$html = <<<EOT
'<h1 style="text-align: center;"><strong>ATTESTATO DI FORMAZIONE</strong></h1>

<h3 style="text-align: center;"><em><strong> {$header} si attesta che il </strong></em></h3>

<h2 style="text-align: center;"><strong> {$grado} {$cognome} {$nome} </strong></h2>'
EOT;

in questo modo potrebbe funzionare.

Ciao

zebmckey
17-04-2018, 12:23
Ciao,

dovresti utilizzare la parentesi graffe in questo caso..


in questo modo potrebbe funzionare.

Ciao

Ok provo e vediamo che succede!

zebmckey
17-04-2018, 13:37
Ok provo e vediamo che succede!

Ho risolto ma non con le graffe ma in questo modo:

$html= '<h1 style="text-align: center;"><strong>ATTESTATO DI FORMAZIONE</strong></h1>

<h4 style="text-align: center;"><em><strong>'.$header. 'si attesta che il </strong></em></h4>

<h2 style="text-align: center;"><strong>' .$grado.'&nbsp;' .$cognome.'&nbsp;' .$nome. '</strong></h2>';

Grazie a tutti per i suggerimenti

iezzetto
18-04-2018, 08:53
Ok... hai risolto in un altro modo.

Anche se con le graffe doveva funzionare.
In quel modo si "passano" le variabili negli heredoc.

ciao

zebmckey
20-04-2018, 09:04
Ok... hai risolto in un altro modo.

Anche se con le graffe doveva funzionare.
In quel modo si "passano" le variabili negli heredoc.

ciao

grazie per le info