Created
April 14, 2016 12:35
-
-
Save anonymous/75ec3aeeaed60c19f62bba8fd19792be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Generates a populated Job Card PDF using the data in the supplied array and returns an application file path to the newly generated PDF. | |
Requires the inclusion of the util function: 'generateJobCardFDF($inputData)' | |
*/ | |
function generatePopulatedJobCardPDF($jobCardData){ | |
//Format the form data | |
$formData['Job_Number']=$jobCardData['']; | |
$formData['Customer']=$jobCardData['']; | |
$formData['Description']=$jobCardData['']; | |
$formData['Notes']=$jobCardData['']; | |
$formData['Preparation']=$jobCardData['']; | |
$formData['Undercoat']=$jobCardData['']; | |
$formData['Topcoat']=$jobCardData['']; | |
$formData['Packing']=$jobCardData['']; | |
//Generate FDF content | |
$fdf_content=$this->generateFDF($formData); | |
//Create temp file for FDF | |
$FDFName=$this->generateGUID(); | |
$inputPath='/var/www/html/CSR/template/job_card.pdf'; | |
$outputPath='/var/www/html/CSR/template/'.$FDFName.'.pdf'; | |
$FDFPath='/var/www/html/CSR/template/'.$FDFName.'.fdf'; | |
//$FDFfile = tempnam('var/www/html/CSR/template/', $FDFName); | |
$result=file_put_contents($FDFPath, $fdf_content); | |
if(!$result){ | |
echo "fill_put_contents has failed.<br>"; | |
}else{ | |
echo "file_put_contents finished with byte count: ".$result."<br>"; | |
} | |
//Build the function call | |
$functionCall='pdftk '.$inputPath.' fill_form '.$FDFPath.' output '.$outputPath.' 2>&1'; | |
//Fire the function | |
exec($functionCall, $result); | |
//The below is if you want to run the equivelant from command line | |
//pdftk /var/www/html/CSR/template/job_card.pdf fill_form /var/www/html/CSR/template/wwwwu7mMH.fdf output /var/www/html/CSR/template/filled4.pdf | |
//Process the result | |
if(count($result)>0){ | |
for($i=0;$i<count($result);$i++){ | |
echo $result[$i]; | |
echo "<br>"; | |
} | |
}else{ | |
echo "Result object is empty."; | |
} | |
//Direct the user to the new object | |
redirect(base_url().'template/'.$FDFName.'.pdf', 'refresh'); | |
} | |
private function generateJobCardFDF($inputData){ | |
$FDFText="%FDF-1.2 | |
%‚„œ” | |
1 0 obj | |
<< | |
/FDF | |
<< | |
/Fields [ | |
<< | |
/V (".$inputData['Packing'].") | |
/T (Packing) | |
>> | |
<< | |
/V (".$inputData['Undercoat'].") | |
/T (Undercoat) | |
>> | |
<< | |
/V (".$inputData['Topcoat'].") | |
/T (Topcoat) | |
>> | |
<< | |
/V (".$inputData['Preparation'].") | |
/T (Preparation) | |
>> | |
<< | |
/V (".$inputData['Job_Number'].") | |
/T (Job_Number) | |
>> | |
<< | |
/V (".$inputData['Customer'].") | |
/T (Customer) | |
>> | |
<< | |
/V (".$inputData['Description'].") | |
/T (Description) | |
>> | |
<< | |
/V (".$inputData['Notes'].") | |
/T (Notes) | |
>>] | |
>> | |
>> | |
endobj | |
trailer | |
<< | |
/Root 1 0 R | |
>> | |
%%EOF | |
"; | |
return $FDFText; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment