• Home
  • Forum
  • Fare Web
  • PHP

creare pdf

  • Creatore Discussione Creatore Discussione amhal
  • Data di inizio Data di inizio 8 Nov 2013
A

amhal

Utente Attivo
17 Feb 2011
89
1
8
  • 8 Nov 2013
  • #1
ciao a tutti, vorrei dare la possibilità all'utente di creare un pdf, ho scaricato la libreria fpdf.php e le righe di codice che creano il pdf stesso. Funziona tutto, ma vorrei sapere come
fare per dirgli cosa deve inserire nell'output. Es: se lanciate queste righe di codice con la libreria, nel pdf appare 'ciao', come faccio a sostituire il ciao con una pagina con delle righe
che vanno a capo? Grazie

Codice:
define('FPDF_FONTPATH','font/');
require('fpdf.php');

$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial','',12);
$pdf->Cell(20,10,'ciao');
$pdf->Output();


?>
 

marino51

Utente Attivo
28 Feb 2013
3.205
207
63
Lombardia
  • 8 Nov 2013
  • #2
ti mando un mio script perfettamente funzionante e se trovo il modo ti allego anche il pdf ...

se sostituisci NextStream(99) con il nome di uno script non ti serve scr.php
mentre DB.php contiene la gestione del database ed è chiamato da
$data_counter = exec_DB('select', $sql);
in cascata io chiamo uno script (99) che consente all'utente di visualizzare il pdf e poi continuare nel lavoro
ciao

PHP:
<?php

# http://localhost/test_site/php/Optidea/Optidea_CAR_report_car.php

error_reporting(E_ALL);
$swN = "RCAR";

require("FPDF/fpdf.php");
require("Optidea__Class_PDF.php");
require('Optidea__Config_Scr.php');
require('Optidea__Config_DB.php');

if ($OPlog) error_log(" ", 0);
if ($OPlog) error_log("$swN main : ". basename ($_SERVER['PHP_SELF'],".php"). ".php", 0);

$h = true;

$w = array(34,10,73,20,20,20,20,5,5,5,5,5,5,5,5,5,5,30);

$title = 'Optidea - Lista delle caratteristiche';

$header[] = 'caratteristica';
$header[] = 'ID';
$header[] = 'descrizione';
$header[] = 'UM';
$header[] = 'secco';
$header[] = 'cartellino';
$header[] = 'stampa';
$header[] = '1';
$header[] = '2';
$header[] = '3';
$header[] = '4';
$header[] = '5';
$header[] = '6';
$header[] = '7';
$header[] = '8';
$header[] = '9';
$header[] = '10';
$header[] = 'aggiorn.';

$fill = false;

$PageBreak = true;

$data = array();

$sql  = "SELECT ca_cod,ca_nr,ca_descr,ca_um,ca_secco,ca_cartel,ca_sort,";
$sql .= "ca_tipo1,ca_tipo2,ca_tipo3,ca_tipo4,ca_tipo5,ca_tipo6,ca_tipo7,ca_tipo8,ca_tipo9,ca_tipo10,";
$sql .= "convert(varchar, ca_aggior, 103) as ca_aggior_c ";
$sql .= "FROM caratteristiche WHERE ca_nr>0 ORDER BY ca_sort,ca_cod";

$data_counter = exec_DB('select', $sql);

$pdf = new PDF('L', 'mm', 'A4');

$pdf->SetAuthor("Optidea project");
$pdf->SetCreator("mrgas");
$pdf->SetSubject("caratteristiche");
$pdf->SetTitle($title);

$pdf->SetMargins(10,10,10);

$pdf->SetDrawColor(0,153,255);
$pdf->SetLineWidth(.4);
$pdf->AliasNbPages();

$pdf->AddPage();
$pdf->BodyTable();

$_SESSION['OPreportname'] = date('Ymd_His') . "_caratteristiche.pdf";
$OPpdffile = $_SESSION['OPreportfolder'] . "\\" . $_SESSION['OPreportname'];

$pdf->Output("$OPpdffile", 'F');

unset($pdf);
unset($h);
unset($w);
unset($title);
unset($header);
unset($fill);
unset($PageBreak);
unset($data);
unset($data_counter);
unset($OPpdffile);

header(NextStream(99));
?>


PHP:
<?php

class PDF extends FPDF {

  function Header() {
    global $h,$w,$title,$header,$fill;

    // TITLE
    $this->SetTextColor(0);
    $this->SetFont('Helvetica','B',16);
    $this->Cell(120,10,$title,0,1,'L');

    // HEADER
    //Colors, line width and bold font
    $this->SetFillColor(0,153,255);
    $this->SetTextColor(255);
    $this->SetFont('Helvetica','B',10);

    for($i=0;$i<count($header);$i++)
      $this->Cell($w[$i],7,$header[$i],1,0,'C',1);
    $this->Ln();

    $h = true;
  }

  function BodyTable() {
    global $swN,$h,$w,$title,$header,$fill,$data;

    //now spool out the data from the $data array
    $preced = "";
    foreach($data as $row) {

      $this->Cell(0,6,' ',0,0,'L');   // Check Page Break by empty cell
      $this->Ln(0);

      if ($h) {
        $fill = false;
        $this->SetFillColor(178,178,178);
        $this->SetTextColor(0);
        $this->SetFont('');
      }
      for($i=0;$i<count($header);$i++) {
        $valore = $row[$i];

        switch ($swN) {
          case "RCOMP":
            if ($i == 4 or $i == 6) $valore = ($valore == 0 ?  " " : number_format($valore, 4, ',', '.'));
            if ($i == 8)            $valore = ($valore == 0 ?  " " : number_format($valore, 2, ',', '.'));
            break;
          case "RCOST":
            if ($i > 3 and $i < 10) $valore = ($valore == 0 ?  " " : number_format($valore, 2, ',', '.'));
            break;
          case "RCxF":
            if ($preced == $row[0] and $i < 3 and !$h) $valore = " ";
            if ($i > 6)             $valore = ($valore == 0 ?  " " : number_format($valore, 2, ',', '.'));
            break;
        }

        $this->Cell($w[$i],6,$valore,'LR',0,'C',$fill);
      }
      $this->Ln();

      // flips from true to false and vise versa
      $fill =! $fill;

      $preced = $row[0];
      $h = false;
    }
  }

  function Footer() {
    global $w;

    $this->Cell(array_sum($w),0,'','T');

    $this->SetY(-15);
    $this->SetFont('Helvetica','I',8);
    $this->Cell(0,10,'Optimal Solution System',0,0,'L');
    $this->Ln(0);
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    $this->Ln(0);
    $this->Cell(0,10,date('l, F jS, Y - H:i:s'),0,0,'R');
  }
}

?>
 
Ultima modifica: 8 Nov 2013

marino51

Utente Attivo
28 Feb 2013
3.205
207
63
Lombardia
  • 8 Nov 2013
  • #3
scusa ti mando anche la gestione del DB perchè un' array e passata come global
io uso ms sql ma puoi convertire adeguatamente in mysql se ti interessa

PHP:
<?php

$OPlog = 1;

function exec_DB($CmdType, $sql) {
  global $swN,$OPlog,$data,$data_val;

  $OPdbHOST = 'DB_server_name';
  $OPdbUSER = 'DB_user_name';
  $OPdbPASS = 'DB_user_password';
  $OPdbNAME = 'DB_name';

  if ($OPlog) error_log("$swN $CmdType : $sql", 0);

  try { $db = new PDO("sqlsrv:Server=$OPdbHOST;Database=$OPdbNAME", "$OPdbUSER", "$OPdbPASS"); }
  catch (PDOException $e) { die( print_r( 'Connection failed : ' . $e->getMessage(), true)); }

  if ($CmdType == "select") {
    $sth = $db->prepare($sql); $sth->execute(); $data = $sth->fetchall(PDO::FETCH_NUM);
    return $OPdbresult = count($data);
  }

  if ($CmdType == "select_val") {
    $sth = $db->prepare($sql); $sth->execute(); $data_val = $sth->fetchall(PDO::FETCH_NUM);
    return $OPdbresult = count($data_val);
  }

  if ($CmdType == "insert" or $CmdType == "update" or $CmdType == "delete") {
    return $OPdbresult = $db->exec($sql);
} }

?>
 
A

amhal

Utente Attivo
17 Feb 2011
89
1
8
  • 12 Nov 2013
  • #4
Miticooooo!!!
ti ringrazio infinitamente :fonzie:
 
Devi accedere o registrarti per poter rispondere.

Discussioni simili

B
  • Bloccata
[PHP] Creare PDF dopo inserimento dati form
  • bipolare75
  • 28 Set 2019
  • PHP
Risposte
4
Visite
4K
PHP 28 Set 2019
Max 1
S
Creare in automatico PDF da MySQL
  • sarox85
  • 27 Ott 2016
  • PHP
Risposte
2
Visite
3K
PHP 27 Ott 2016
marino51
M
Creare stampe pdf con tabelle relazione uno a molti
  • Max61
  • 17 Dic 2015
  • PHP
Risposte
0
Visite
2K
PHP 17 Dic 2015
Max61
M
A
Creare da form un PDF da inviare come allegato.
  • Alexanders
  • 7 Dic 2015
  • PHP
Risposte
1
Visite
5K
PHP 15 Dic 2015
filomeni
F
Script PHP + MySql - immettere dati e creare un documento Word o PDF
  • freddie24
  • 3 Giu 2014
  • PHP
Risposte
4
Visite
10K
PHP 3 Giu 2014
marino51
Creare PDF con Php e PDFlib
  • GoshMaledetto
  • 8 Gen 2013
  • PHP
Risposte
1
Visite
2K
PHP 8 Gen 2013
GoshMaledetto
M
liberia fpdf creare form che al premere al bottone di sumit mi crei il pdf
  • marzar
  • 30 Nov 2012
  • PHP
Risposte
0
Visite
2K
PHP 30 Nov 2012
marzar
M
G
creare PDF da url
  • gazza82
  • 14 Nov 2011
  • PHP
Risposte
3
Visite
2K
PHP 14 Nov 2011
Eliox
Z
Creare PDF o ePub
  • z.cristiano
  • 9 Apr 2011
  • PHP
Risposte
3
Visite
4K
PHP 12 Apr 2011
Eliox
M
creare pdf con php - libreria mpdf
  • mo_70
  • 15 Apr 2010
  • PHP
Risposte
0
Visite
3K
PHP 15 Apr 2010
mo_70
M
A
Creare PDF online
  • angeloulivieri
  • 10 Feb 2010
  • PHP
Risposte
12
Visite
3K
PHP 18 Feb 2010
softhare
I
Creare documento stampabile in pdf
  • intimoviro
  • 7 Set 2009
  • PHP
Risposte
2
Visite
2K
PHP 7 Set 2009
Eliox
F
Creare un file in PDF
  • Fexys
  • 10 Mag 2009
  • Windows e Software
Risposte
4
Visite
2K
Windows e Software 11 Mag 2009
Fexys
F
G
creare pdf da pagina corrente
  • genco
  • 14 Ott 2007
  • PHP
Risposte
1
Visite
1K
PHP 15 Ott 2007
Eliox
Creare PDF via asp su server remoto
  • grottafelix
  • 8 Set 2006
  • Classic ASP
Risposte
11
Visite
5K
Classic ASP 21 Set 2006
chycky
C
L
Creare File Pdf
  • lorenzo
  • 1 Mar 2005
  • PHP
Risposte
2
Visite
2K
PHP 16 Gen 2006
lukeonweb
R
Creare report da una data.
  • Ramon
  • 10 Mag 2025
  • MS Access
Risposte
0
Visite
322
MS Access 10 Mag 2025
Ramon
R
S
Creare un bollettino postale in html o altro linguaggio
  • salvo_76
  • 8 Giu 2024
  • HTML e CSS
Risposte
3
Visite
2K
HTML e CSS 2 Feb 2025
Fra_23
F
F
Salve a tutti, devo creare un sito web/gioco online dove cliccando il tasto 'Inizia' del form viene estratta una capitale casualmente dal
  • faccone
  • 8 Mag 2024
  • PHP
Risposte
1
Visite
1K
PHP 23 Apr 2025
webest
C
Come ricreare questo calcolatore di prezzi a step con woocommerce?
  • calmabubbasst
  • 20 Feb 2024
  • WordPress
Risposte
0
Visite
2K
WordPress 20 Feb 2024
calmabubbasst
C
Condividi:
Facebook X (Twitter) LinkedIn WhatsApp e-mail Condividi Link
  • Home
  • Forum
  • Fare Web
  • PHP
  • Italiano
  • Termini e condizioni d'uso del sito
  • Policy Privacy
  • Aiuto
  • Home
Community platform by XenForo® © 2010-2024 XenForo Ltd. | Traduzione a cura di XenForo Italia
Menu
Accedi

Registrati

  • Home
  • Forum
    • Nuovi Messaggi
    • Cerca...
  • Novità
    • Featured content
    • Nuovi Messaggi
    • Ultime Attività
X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?

X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?