Visualizzazione dei risultati da 1 a 10 su 10

Discussione: html2fpdf che non va

  1. #1

    html2fpdf che non va

    ho preso un esempio di script dal sito ufficiale, ma mi continua a stampare del codice incomprensibile sulla pagina del browser senza generarmi il file pdf, ecco il codice:

    Codice PHP:
    <?
    require_once('fpdf/html2fpdf.php');
    // activate Output-Buffer:
    ob_start(); ?>
    <html>
    <head>
    <title>HTML 2 (F)PDF Project</title>
    </head>
    <body>
    <h2 align="center">FEATURES</h2>
    Current version: <?= HTML2FPDF_VERSION ?>



    This script supports the following tags:
    <code>

    <? //Automatically get html2fpdf tag info
    $pdf = new HTML2FPDF();
    $pdf->DisableTags();
    $pdf->DisplayPreferences('FullScreen');
    $tags strtoupper($pdf->enabledtags);
    $tags str_replace('>','>, ',$tags);
    $tags{strlen($tags)-2} = ' '//erase last comma
    $tags htmlspecialchars($tags);
    echo 
    $tags;
    ?></code></p>



    This script supports the following CSS properties (not perfectly or fully
    supported): 

    [i]width, height, border, font-family, font-size, font-style, font-weight,
    text-decoration, text-align, text-transform, direction, background, color.[/i]
    </p>
    This script supports the following image types: [i]jpg, png, gif[/i].

    This script is not 100% accurate! It simply helps in normal html conditions.
    Works best with XHTML 1.0




    <div style='background:#ccc;border:thin dashed black'>
    This page was dinamically created using PHP ob_get_contents and HTML2FPDF
    class.

    Read more on FAQ on how to make this or check the 2<sup>nd</sup> page (use the
    'PageDown' keyboard key)</div><newpage>
    <div style='background:#eee;font-weight:bold'><code>
    <? $metaphp htmlspecialchars($metaphp);
    $metaphp str_replace("\n",'
    '
    ,$metaphp);
    echo 
    "&lt;?".$metaphp."?&gt;"?>
    </div></code>
    </body>
    </html>
    <? // Output-Buffer in variable:
    $html=ob_get_contents();
    // delete Output-Buffer
    ob_end_clean();
    $pdf->AddPage();
    $pdf->WriteHTML($html);
    $pdf->Output('doc.pdf','I');
    ?>

  2. #2
    probabilmente io ho qualche problema, ho preso un altro esempio, sempre dal sito, ancora più semplice:

    Codice PHP:
    <?
    require('fpdf/html2fpdf.php');
    // activate Output-Buffer:
    ob_start();
    //START-OF-PHP code
    ?>
    PROVA XXXXXX

    <?
    // PHP code here
    //END-OF-PHP code
    // Output-Buffer in variable:
    $htmlbuffer=ob_get_contents();
    // delete Output-Buffer :
    ob_end_clean();
    require(
    'fpdf/html2fpdf.php');
    $pdf=new PDF();
    $pdf->AddPage();
    $pdf->WriteHTML($htmlbuffer);
    $pdf->Output(); //Outputs on browser screen
    ?>

    ... niente da fare, mi dice :

    Fatal error: Cannot redeclare class html2fpdf in /home/viat/public_html/fpdf/html2fpdf.php on line 65

    mentre se tolgo uno dei due REQUIRE:

    Fatal error: Cannot instantiate non-existent class: pdf in /home/viat/public_html/test2.php on line 17

    ... giustamente!... ma come si fa a farlo funzionare sto coso???

  3. #3
    beh ... l'errore parla molto chiaro

  4. #4
    vienimi un po in contro ... mi sfugge qualche cosa

  5. #5
    Utente di HTML.it L'avatar di chris
    Registrato dal
    Sep 1999
    Messaggi
    1,568
    Se la classe si chiama HTML2FPDF è inutile che cerchi di istanziarla come PDF
    "Nei prossimi tre anni col mio governo vogliamo vincere anche il cancro, che colpisce ogni anno 250.000 italiani e riguarda quasi due milioni di nostri concittadini"

  6. #6
    credo che chi mette un codice sul proprio sito come esempio del corretto utilizzo di una classe abbia fatto tutti i dovuti controlli per far si che tale esempio funzioni correttamente, io mi aspetto che funzioni.

    pensare che ho trovato un esempio della stessa classe su un altro sito, e che mi ha funzionato senza fare alcun controllo.

    vabbè, grazie per l'aiuto cmq.

  7. #7

    Errore con la classe html2fpdf

    Ho fatto una semplice prova e mi dà quest' errore.
    Fatal error: Cannot redeclare class html2fpdf in c:\apache\htdocs\carta\html2fpdf.php on line 65

    Il codice che utilizzo è il seguente :
    codice:
    <? 
    require('html2fpdf.php'); 
    // activate Output-Buffer: 
    ob_start(); 
    //START-OF-PHP code 
    ?> 
    PROVA XXXXXX 
    
    <? 
    // PHP code here 
    //END-OF-PHP code 
    // Output-Buffer in variable: 
    $htmlbuffer=ob_get_contents(); 
    // delete Output-Buffer : 
    ob_end_clean(); 
    require('html2fpdf.php'); 
    $pdf=new HTML2FPDF(); 
    $pdf->AddPage(); 
    $pdf->WriteHTML($htmlbuffer); 
    $pdf->Output(); //Outputs on browser screen 
    ?>
    Qualcuno può aiutarmi please ???
    Forse ho sbagliato l' installazione della classe ?

  8. #8
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    591
    forse ti è sfuggito qcosa di quanto sopra, usa require_once e togli il secondo require e poi verifica dove hai insallato la classe.

  9. #9
    grazie per la risposta, ho fatto quello che hai detto, ma il non mi genera il file pdf... mi stampa a browser questa scritta :
    codice:
    %PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream 2 J 0.57 w BT /F1 11.00 Tf ET 1.000 g q 0 g BT 28.35 803.15 Td (PROVA XXXXXX ) Tj ET Q BT /F2 9.00 Tf ET BT /F3 9.00 Tf ET q 0.000 g BT 285.88 11.47 Td (1/1) Tj ET Q BT /F1 11.00 Tf ET endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 2 0 obj <> >> endobj 8 0 obj << /Producer (FPDF 1.52) /Creator (HTML2FPDF >> http://html2fpdf.sf.net) /CreationDate (D:20051121100121) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 10 0000000000 65535 f 0000000321 00000 n 0000000709 00000 n 0000000009 00000 n 0000000087 00000 n 0000000408 00000 n 0000000504 00000 n 0000000605 00000 n 0000000817 00000 n 0000000941 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 1044 %%EOF
    come mai ?

  10. #10
    il codice ricorretto che mi genera l' output su browser senza creare il file pdf è il seguente :

    <?
    require_once('html2fpdf.php');
    // activate Output-Buffer:
    ob_start();
    //START-OF-PHP code
    ?>
    PROVA XXXXXX

    <?
    // PHP code here
    //END-OF-PHP code
    // Output-Buffer in variable:
    $htmlbuffer=ob_get_contents();
    // delete Output-Buffer :
    ob_end_clean();
    $pdf=new HTML2FPDF();
    $pdf->AddPage();
    $pdf->WriteHTML($htmlbuffer);
    $pdf->Output('doc.pdf','I'); //Outputs on browser screen
    ?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.