PDF file not downloading or being saved to folder

假装没事ソ 提交于 2019-12-25 01:14:34

问题


I posted about this issue not that long ago, and I thought I had figured it out but nothing is happening. Issue: I am trying to generate a PDF file that captures the signature of a client. Essentially they type in their name in a box and that name gets displayed in the pdf.php file along with all the other information(e.g. date, terms & conditions etc..). I created a class that extends from FPDF and though JavaScript I am sending the name that gets filled and it gets processed through that pdf.php file and should return a "signed" pdf file. However my pdf file is not downloading, saving or any of the options (I, D, F, S). Below is a snippet of that section in my code.

pdf.php

$tempDir = "C:/PHP/temp/";
$thisaction = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING);
$answers = filter_input(INPUT_POST, 'encFormData');
$decFD = json_decode($answers);

$pdf = new WaiverFPDF();
// Pull values from array
$returnVals = array();
$returnVals['result'];
$returnVals['html'] = '';
$returnVals['errorMsg'] = '';

//the name of the person who signed the waiver
$name = $decFD->signWaiver;
$today = date('m/d/Y');

if($thisaction == 'waiverName'){
        // Generate a new PDF
        $pdf = new WaiverFPDF();
        $pdf->AddPage()
        $pdfFile = "Waiver". $name . ".pdf";
        ....
        // Output form
        $pdf->Write(8, 'I HEREBY ASSUME ALL OF THE RISKS...');
        // Line Break
        $pdf-> all other info...
        $outFile  = $tempDir . $pdfFile;
       //output pdf
        $pdf->Output('D', $pdfFile);

        $returnVals['result'] = true;
}
else{
    $returnVals['errorMsg'] = "There was an error in waiver.php";
    $returnVals['result'] = false;
}

echo json_encode($returnVals);
?>

.js file (JSON)

function sendWaiver(){
    var formHash = new Hash();
    formHash.signWaiver = $('signWaiver').get('value');
    console.log ("name being encoded");
    waiverNameRequest.setOptions({
        data : {
            'encFormData' : JSON.encode(formHash)
        }
    }).send();
return true;
}
waiverNameRequest = new Request.JSON({
        method : 'post',
        async : false,
        url : 'pdf.php',
        data : {
            'action' : 'waiverName',
            'encFormData' : ''
        },
        onRequest : function() {
        //  $('messageDiv').set('html', 'processing...');
            console.log("waiver onRequest");
        },
        onSuccess : function(response) {
            $('messageDiv').set('html', 'PDF has been downloaded');
            if (response.result == true) {
                console.log('OnSuccess PDF created');
            } else {
                $('messageDiv').set('html', response.errorMsg);
                console.log('PDF error');
            }
        }
    });

I know my error handling is very simple, but all I am getting is success messages, but no generated pdf file... I'm not sure what i am doing wrong. I also made sure the file (when i save to a file) is writable. class_WaiverFPDF.php

class WaiverFPDF extends FPDF
{
    // Page header
    function Header()
    {
        // Arial bold 15
        $this->SetFont('Arial','B',12);
        // Position XY X=20, Y=25
        $this->SetXY(15,25);
        // Title
        $this->Cell(179,10, 'Accident Waiver ','B','C');
        // Line break
        $this->Ln(11);
    }

    // Page footer
    function Footer()
    {
        // Position from bottom
        $this->SetY(-21);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        $this->Ln();
        // Current date
        $this->SetFont('Arial','I',8);
        // $this->Cell(179,10,$today,0,1,'R',false);
        // $today= date('m/d/Y');

        $this->Cell(115,10,' Participant Name',0,0,'C');
        $this->Cell(150,10,'Date',0,'C',false);
        // Page number
        //$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

    }
}

来源:https://stackoverflow.com/questions/56639214/pdf-file-not-downloading-or-being-saved-to-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!