SourceForge has been redesigned. Learn more.

tcpdf is creating damaged pdfs

  • 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:

    $pdf = & new TCPDF("P","mm","A4",true,"UTF-8",false);
    // set image scale factor
    // IMPORTANT: disable font subsetting to allow users editing the document
    $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->Cell(35, 5, 'DC ');
    $pdf->CheckBox('dc1', 5, true, array(), array(), 'OK');
    $pdf->Cell(35, 5, 'Flip ');
    $pdf->CheckBox('flip1', 5, true, array(), array(), 'OK');
    $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');
  • 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:

    $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.