SourceForge has been redesigned. Learn more.
Close

tcpdf is creating damaged pdfs

Help
2014-02-11
2014-02-11
  • bennyboy0789

    bennyboy0789 - 2014-02-11

    TCPDF keeps creating a damaged pdf that I an unable to open. any solutions? I am posting from an html form. I am unsure if my code is wrong but I tested tcpdf's examples and they work fine.

    This is my php:

    ob_start();
    
    require_once('tcpdf.php');
    
    $pdf = & new TCPDF("P","mm","A4",true,"UTF-8",false);
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
    $pdf->SetAutoPageBreak(false);
    $pdf->SetMargins(15,20,15);
    $pdf->AddPage();
    $pdf->SetFont('helvetica','B',12);
    $pdf->SetFillColor(255,255,255);
    
    // set image scale factor
    
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    
    // IMPORTANT: disable font subsetting to allow users editing the document
    
    $pdf->setFontSubsetting(false);
    
    //data
    
    $pdf->writeHTMLCell(0,0,0,0, "Job Number ". $_POST["jobnum"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,5, "Program ". $_POST["program"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,10, "Ship Date ". $_POST["shipdate"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,15, "Description ". $_POST["description"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,20, "Proto Verified By ". $_POST["name"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,25, "Additional Notes ". $_POST["notes"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,30, "File Name". $_POST["filename1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,35, "Doc Siize ". $_POST["Docsize1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->Cell(35, 5, 'FC ');
    $pdf->CheckBox('fc1', 5, true, array(), array(), 'OK');
    $pdf->Ln(40);
    $pdf->Cell(35, 5, 'DC ');
    $pdf->CheckBox('dc1', 5, true, array(), array(), 'OK');
    $pdf->Ln(45);
    $pdf->Cell(35, 5, 'Flip ');
    $pdf->CheckBox('flip1', 5, true, array(), array(), 'OK');
    $pdf->Ln(50);
    $pdf->writeHTMLCell(0,0,0,55, "Quantity ". $_POST["quantity1"], $border=0, $ln=0, $fill=false, $reseth=true, $align='', $autopadding=true);
    $pdf->writeHTMLCell(0,0,0,60, "Flip Quantity ". $_POST["flipqty1"], $border=0, $ln=0,   $fill=false, $reseth=true, $align='', $autopadding=true);
    
    //Close and output PDF document
    
    $pdf->Output('job.pdf', 'D');
    
    ob_clean();
    
     
  • bennyboy0789

    bennyboy0789 - 2014-02-11

    I also tested a basic "hello world" function and it created a damaged pdf.

     
  • Lubos Dz

    Lubos Dz - 2014-02-11

    try switching lines like so:

    ob_get_clean();
    $pdf->Output('job.pdf', 'D');

    otherwise you may corrupt output buffer.
    download headers are set inside TCPDF and they work OK.
    And OMG - please filter those inputs from global $_POST :-)

     

Log in to post a comment.