load->library('pdf'); foreach ($tpl as $value) { $ci->load->view($value, $data); $html = $ci->output->get_output(); $ci->dompdf->loadHtml($html); // setup size $ci->dompdf->setPaper('A4', 'portrait'); // Render the HTML as PDF } // _die($html); // Get output html // add external css library // $html .= ''; // Load pdf library $ci->dompdf->render(); // echo $output = $ci->dompdf->output(); // Output PDF (1 = download and 0 = preview) $ci->dompdf->stream($name, array("Attachment" => 0)); } if (!function_exists('generate_pdf_file')){ function generate_pdf_file($name, $tpl, $data){ $ci = &get_instance(); $data['data'] = $data; // _die($data); $html = ''; $ci->load->library('pdf'); foreach ($tpl as $value) { $ci->load->view($value, $data); $html = $ci->output->get_output(); $ci->dompdf->loadHtml($html); $ci->dompdf->setPaper('A4', 'portrait'); } $ci->dompdf->render(); // $ci->dompdf->stream($name, array("Attachment" => 0)); if(!file_exists($data['file_name'])){ $output=$ci->dompdf->output(); // $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; file_put_contents($data['file_name'], $output); // echo $data['file_name']; } return $data['file_name']; // _die($data['file_name']); } } function generate_html($name, $tpl, $data) { $ci = &get_instance(); $data['data'] = $data; $html = ''; $ci->load->library('pdf'); $html = $ci->load->view($tpl, $data, true); return $html; } /* | filling Editable pdf forms | and creating new one is started from here | used libraries are pdftk and fpdf */ function pdfGenerate($data,$id,$slug,$pages) { $CI = & get_instance(); $CI->load->library('Generatepdf'); $CI->load->library('Generatefpdf'); // return $data; foreach($data as $d){ $filepath=$d['filepath']; $imgpath=$d['imgpath']; $imageFile=$d['imageFile']; $x=$d['x']; $y=$d['y']; $w=$d['w']; $h=$d['h']; $pdfFile=$d['pdfFile']; $dataInfo=$d['dataInfo']; if($pages>1){ $finalPage=$pages-1; /* | extracting files */ $pdftk=new Pdf($pdfFile); $filename="pdf_".rand(9999,99999999)."_".$id.".pdf"; $pdftk->cat([$pages]); $pdftk->saveAs($filepath."/temps/".$filename); $extractedPdfFile1=$filepath."/temps/".$filename; $pdftk=new Pdf($pdfFile); $filename="pdf_".rand(9999,99999999)."_".$id.".pdf"; $pdftk->cat(1,$finalPage); $pdftk->saveAs($filepath."/temps/".$filename); $extractedPdfFile2=$filepath."/temps/".$filename; /* | signature image file pdf create using fpdf */ $fpdf = new fpdf(); $filename = "pdf_".rand(9999,99999999)."_".$id.".pdf"; $fpdf->AddPage(); $fpdf->Image($imageFile,$x,$y,$w,$h); $fpdf->Output($filepath."/temps/".$filename,'F'); $imagePdf=$imgpath."\\temps\\".$filename; /* | editable form fill up using pdftk */ $pdftk = new Pdf(); $filename = "pdf_".rand(9999,99999999)."_".$id.".pdf"; $pdftk->addFile($extractedPdfFile1,'A'); $pdftk->fillForm($dataInfo) ->flatten() ->saveAs($filepath."/temps/".$filename); $editedPdf=$filepath."/temps/".$filename; /* | stamping of those above two pdf's using pdftk */ $pdftk = new Pdf(); $filename = "stamp_".rand(9999,99999999)."_".$id.".pdf"; $pdftk->addFile($editedPdf,'B'); $pdftk->stamp($imagePdf) ->saveAs($filepath."/temps/".$filename); $stampedfile=$filepath."/temps/".$filename; $pdftk = new Pdf(); $filename = "stamp_".rand(9999,99999999)."_".$id.".pdf"; $pdftk->addFile($extractedPdfFile2, 'A'); $pdftk->cat('A'); $pdftk->addFile($stampedfile, 'B'); $pdftk->cat('B'); $pdftk->saveAs($filepath."/temps/".$filename); $files[]=$filepath."/temps/".$filename; /* | unlinking $imagePdf & $editedPdf files */ unlink($imagePdf); unlink($editedPdf); unlink($extractedPdfFile1); unlink($extractedPdfFile2); unlink($stampedfile); }else{ /* | signature image file pdf create using fpdf */ $fpdf = new fpdf(); $filename = "pdf_".rand(9999,99999999)."_".$id.".pdf"; $fpdf->AddPage(); $fpdf->Image($imageFile,$x,$y,$w,$h); $fpdf->Output($filepath."/temps/".$filename,'F'); $imagePdf=$imgpath."\\temps\\".$filename; /* | editable form fill up using pdftk */ $pdftk = new Pdf(); $filename = "pdf_".rand(9999,99999999)."_".$id.".pdf"; $pdftk->addFile($pdfFile,'A'); $pdftk->fillForm($dataInfo) ->flatten() ->saveAs($filepath."/temps/".$filename); $editedPdf=$filepath."/temps/".$filename; /* | stamping of those above two pdf's using pdftk */ $pdftk = new Pdf(); $filename = "stamp_".rand(9999,99999999)."_".$id.".pdf"; $pdftk->addFile($editedPdf,'B'); $pdftk->stamp($imagePdf) ->saveAs($filepath."/temps/".$filename); $files[]=$filepath."/temps/".$filename; /* | unlinking $imagePdf & $editedPdf files */ unlink($imagePdf); unlink($editedPdf); } } /* | catenation of $files */ $pdftk = new Pdf(); $filename = $slug."_".$id.".pdf"; $char="A"; foreach($files as $f){ $pdftk->addFile($f, $char); $pdftk->cat($char); $char++; } $pdftk->saveAs($filepath."/pdfs/".$filename); /* | unlinking $files */ foreach($files as $f){ unlink($f); } return $filename; } function generate_pdf_and_save($tpl,$data,$path,$cred) { $CI = & get_instance(); $CI->load->library('Generatepdf'); $CI->load->library('Generatefpdf'); $CI->load->library('pdf'); $dompdf = new Dompdf(); $data['data']=$data; $html = ''; $output=""; foreach($tpl as $value){ $CI->load->view($value, $data); $html=$CI->output->get_output(); $dompdf->load_html($html); $dompdf->setPaper('A4', 'portrait'); } $dompdf->render(); $output=$dompdf->output(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; file_put_contents($path['filePath'].$filename, $output); $bigPdfFile=$path['filePath'].$filename; #spliting big file into components files foreach($cred as $d){ $pdftk = new Pdf(); $pdftk->addFile($bigPdfFile, 'A'); $pdftk->cat($d['start'],$d['end'],'A'); $pdftk->saveAs($path['filePath'].$d['slug'].$path['fileName']); } #spliting big file into components files #unlinking big file unlink($bigPdfFile); #unlinking big file } function mypdf2($datas,$ion_id,$mainslug) { // pre($datas);exit; $CI = & get_instance(); $CI->load->library('Generatepdf'); $CI->load->library('Generatefpdf'); foreach($datas as $data){ #extracting all datas $pdfFile=$data['pdfFile']; $pages=$data['pages']; $break_page=$data['break_page']; $slug=$data['slug']; $filePath=$data['filePath']; $imagePath=$data['imagePath']; $imagePath=str_replace("\\","/",$imagePath); $imageFile=$data['imageFile']; $imageFile=str_replace("\\","/",$imageFile); $x=$data['x']; $y=$data['y']; $w=$data['w']; $h=$data['h']; $imageFile1=$data['imageFile1']; $imageFile1=str_replace("\\","/",$imageFile1); $x1=$data['x1']; $y1=$data['y1']; $w1=$data['w1']; $h1=$data['h1']; $imageFile2=$data['imageFile2']; $imageFile2=str_replace("\\","/",$imageFile2); $x2=$data['x2']; $y2=$data['y2']; $w2=$data['w2']; $h2=$data['h2']; $filePath=$data['filePath']; $dataInfo=$data['dataInfo']; // pre($data); #extracting all datas #filling up form $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($pdfFile,'A'); $pdftk->fillForm($dataInfo) ->flatten() ->saveAs($filePath.$filename); $filledPdfFile=$filePath.$filename; #filling up form if($pages>1){ #splitting the pdf files according to $break_page $pdftk = new Pdf($filledPdfFile); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->cat([$break_page]); $pdftk->saveAs($filePath.$filename); $breakedPdfFile=$filePath.$filename; #splitting the pdf files according to $break_page #creating image pdf file $fpdf = new fpdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $fpdf->AddPage(); $fpdf->Image($imageFile,$x,$y,$w,$h); $fpdf->Image($imageFile1,$x1,$y1,$w1,$h1); $fpdf->Image($imageFile2,$x2,$y2,$w2,$h2); $fpdf->Output($filePath.$filename,'F'); $imagePdf=$imagePath.$filename; $imagePdf2=$filePath.$filename; #creating image pdf file #stamping $imagePdf on $breakedPdfFile $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($breakedPdfFile,'B'); $pdftk->stamp($imagePdf) ->saveAs($filePath.$filename); $stampedPdfFile=$filePath.$filename; #stamping $imagePdf on $breakedPdfFile #relative concatenation of $filledPdfFile && $stampedPdfFile if($break_page==1){ $p1=null; $p2=null; }if($break_page==2){ $p1=1; $p2=null; }if($break_page>2){ $p1=1; $p2=$break_page-1; }if($break_page==$pages){ $p3=null; $p4=null; }if($break_page==($pages-1)){ $p3=$pages; $p4=null; }if($break_page<($pages-1)){ $p3=$break_page+1; $p4=$pages; } $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; if($p1!=null){ $pdftk->addFile($filledPdfFile, 'A'); $pdftk->cat($p1,$p2,'A'); } $pdftk->addFile($stampedPdfFile, 'B'); $pdftk->cat('B'); if($p3!=null){ $pdftk->addFile($filledPdfFile, 'C'); $pdftk->cat($p3,$p4,'C'); } $pdftk->saveAs($filePath.$filename); $files[]=$filePath.$filename; #relative concatenation of $filledPdfFile && $stampedPdfFile #unlinking files unlink($breakedPdfFile); unlink($imagePdf2); unlink($stampedPdfFile); #unlinking files }else{ #creating image pdf file $fpdf = new fpdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $fpdf->AddPage(); $fpdf->Image($imageFile,$x,$y,$w,$h); $fpdf->Image($imageFile1,$x1,$y1,$w1,$h1); $fpdf->Image($imageFile2,$x2,$y2,$w2,$h2); $fpdf->Output($filePath.$filename,'F'); $imagePdf=$imagePath.$filename; $imagePdf2=$filePath.$filename; #creating image pdf file #stamping $imagePdf on $filledPdfFile $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($filledPdfFile,'B'); $pdftk->stamp($imagePdf) ->saveAs($filePath.$filename); $files[]=$filePath.$filename; #stamping $imagePdf on $filledPdfFile #unlinking files unlink($imagePdf2); #unlinking files } #unlinking files unlink($filledPdfFile); #unlinking files } // pre($datas);exit; /* | catenation of $files */ $pdftk = new Pdf(); IF($mainslug!=""){ $slug=$mainslug; } $filename = $slug.str_pad($ion_id, 6,"0",STR_PAD_LEFT).".pdf"; $char = "A"; foreach($files as $f){ $pdftk->addFile($f, $char); $pdftk->cat($char); $char++; } $pdftk->saveAs($filePath.$filename); /* | unlinking $files */ foreach($files as $f){ unlink($f); } return $filename; } function ci_create_single_page_html_to_pdf($data){ try{ $CI=&get_instance(); $CI->load->library('pdf'); $CI->load->view($data->html_page,$data->html_page_data); $html=$CI->output->get_output(); $dompdf=new Dompdf(); $newpath=$data->upload_path.$data->slug.$data->unique_id.".pdf"; $dompdf->loadHtml($html); $dompdf->setPaper('A4','portrait'); $dompdf->render(); $output=$dompdf->output(); $file_put_contents=file_put_contents($newpath,$output); return $newpath; } catch(Exception $e){ $getMsg="generatepdf_helper - ci_create_single_page_html_to_pdf: ".$e->getMessage(); echo $getMsg; } } function ci_single_page_pdf_creation($datas,$merge=false){ try{ $CI=&get_instance(); $CI->load->library('Generatepdf'); $CI->load->library('Generatefpdf'); $temporary_files=[]; $main_files=[]; foreach($datas->pdf_datas as $data){ $temp_main_files=[]; if(!is_dir($data->basic_data['pdf_upload_path'])){ mkdir($data->basic_data['pdf_upload_path'],0777,TRUE); } #filling up form $pdftk=new Pdf(); $filename="temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($data->basic_data['pdf_file'],'A'); $pdftk->fillForm($data->form_data)->flatten()->saveAs($data->basic_data['pdf_upload_path'].$filename); $filled_pdf_file=$data->basic_data['pdf_upload_path'].$filename; #filling up form if(count($data->image_data)>0){ #creating image pdf file $fpdf=new fpdf(); $filename="temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $fpdf->AddPage(); foreach($data->image_data as $image_data){ $fpdf->Image($image_data->image_file,$image_data->x,$image_data->y,$image_data->w,$image_data->h); } $fpdf->Output($data->basic_data['pdf_upload_path'].$filename,'F'); $image_pdf_file=$data->basic_data['pdf_upload_path'].$filename; #creating image pdf file #stamping $image pdf on editable pdf $pdftk=new Pdf(); $filename="temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($filled_pdf_file,'B'); $pdftk->stamp($image_pdf_file)->saveAs($data->basic_data['pdf_upload_path'].$filename); $temp_main_files[]=$data->basic_data['pdf_upload_path'].$filename; #stamping $image pdf on editable pdf $temporary_files[]=$filled_pdf_file; $temporary_files[]=$image_pdf_file; }else{ $temp_main_files[]=$filled_pdf_file; } foreach($temp_main_files as $file){ $rename=$data->basic_data['pdf_upload_path'].$data->basic_data['slug'].$data->basic_data['unique_id'].".pdf"; rename($file,$rename); $main_files[]=$rename; $temporary_files[]=$file; } } foreach($temporary_files as $file){ unlink($file); } if($merge===true){ $response=ci_merge_pdfs($main_files,$datas->common,FALSE); }else{ $response=$main_files; } return $response; }catch(Exception $e){ echo $e->getMessage(); } } function ci_merge_pdfs($files,$asset,$stat=FALSE){ try{ $CI=&get_instance(); $CI->load->library('Generatepdf'); $pdftk=new Pdf(); $slug=isset($asset->slug)&&$asset->slug!=""?$asset->slug:"we_curo_"; $filename=$slug.$asset->unique_id.".pdf"; $char="A"; foreach($files as $f){ $pdftk->addFile($f,$char); $pdftk->cat($char); $char++; } $pdftk->saveAs($asset->upload_path.$filename); if($stat===TRUE){ foreach($files as $file){ unlink($file); } } return $asset->upload_path.$filename; }catch(Exception $e){ echo $e->getMessage(); } } function mypdf($datas,$ion_id,$mainslug) { // pre($datas);exit; $CI = & get_instance(); $CI->load->library('Generatepdf'); $CI->load->library('Generatefpdf'); foreach($datas as $data){ #extracting all datas $pdfFile=$data['pdfFile']; $pages=$data['pages']; $break_page=$data['break_page']; $slug=$data['slug']; $filePath=$data['filePath']; $imagePath=$data['imagePath']; $imagePath=str_replace("\\","/",$imagePath); $imageFile=$data['imageFile']; $imageFile=str_replace("\\","/",$imageFile); $x=$data['x']; $y=$data['y']; $w=$data['w']; $h=$data['h']; $filePath=$data['filePath']; $dataInfo=$data['dataInfo']; // pre($data); #extracting all datas #filling up form $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($pdfFile,'A'); $pdftk->fillForm($dataInfo) ->flatten() ->saveAs($filePath.$filename); $filledPdfFile=$filePath.$filename; #filling up form if($pages>1){ #splitting the pdf files according to $break_page $pdftk = new Pdf($filledPdfFile); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->cat([$break_page]); $pdftk->saveAs($filePath.$filename); $breakedPdfFile=$filePath.$filename; #splitting the pdf files according to $break_page #creating image pdf file $fpdf = new fpdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $fpdf->AddPage(); $fpdf->Image($imageFile,$x,$y,$w,$h); $fpdf->Output($filePath.$filename,'F'); $imagePdf=$imagePath.$filename; $imagePdf2=$filePath.$filename; #creating image pdf file #stamping $imagePdf on $breakedPdfFile $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($breakedPdfFile,'B'); $pdftk->stamp($imagePdf) ->saveAs($filePath.$filename); $stampedPdfFile=$filePath.$filename; #stamping $imagePdf on $breakedPdfFile #relative concatenation of $filledPdfFile && $stampedPdfFile if($break_page==1){ $p1=null; $p2=null; }if($break_page==2){ $p1=1; $p2=null; }if($break_page>2){ $p1=1; $p2=$break_page-1; }if($break_page==$pages){ $p3=null; $p4=null; }if($break_page==($pages-1)){ $p3=$pages; $p4=null; }if($break_page<($pages-1)){ $p3=$break_page+1; $p4=$pages; } $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; if($p1!=null){ $pdftk->addFile($filledPdfFile, 'A'); $pdftk->cat($p1,$p2,'A'); } $pdftk->addFile($stampedPdfFile, 'B'); $pdftk->cat('B'); if($p3!=null){ $pdftk->addFile($filledPdfFile, 'C'); $pdftk->cat($p3,$p4,'C'); } $pdftk->saveAs($filePath.$filename); $files[]=$filePath.$filename; #relative concatenation of $filledPdfFile && $stampedPdfFile #unlinking files unlink($breakedPdfFile); unlink($imagePdf2); unlink($stampedPdfFile); #unlinking files }else{ #creating image pdf file $fpdf = new fpdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $fpdf->AddPage(); $fpdf->Image($imageFile,$x,$y,$w,$h); $fpdf->Output($filePath.$filename,'F'); $imagePdf=$imagePath.$filename; $imagePdf2=$filePath.$filename; #creating image pdf file #stamping $imagePdf on $filledPdfFile $pdftk = new Pdf(); $filename = "temp_".rand(9999,99999999)."_".rand(9999,99999999).".pdf"; $pdftk->addFile($filledPdfFile,'B'); $pdftk->stamp($imagePdf) ->saveAs($filePath.$filename); $files[]=$filePath.$filename; #stamping $imagePdf on $filledPdfFile #unlinking files unlink($imagePdf2); #unlinking files } #unlinking files unlink($filledPdfFile); #unlinking files } // pre($datas);exit; /* | catenation of $files */ $pdftk = new Pdf(); IF($mainslug!=""){ $slug=$mainslug; } $filename = $slug.str_pad($ion_id, 6,"0",STR_PAD_LEFT).".pdf"; $char = "A"; foreach($files as $f){ $pdftk->addFile($f, $char); $pdftk->cat($char); $char++; } $pdftk->saveAs($filePath.$filename); /* | unlinking $files */ foreach($files as $f){ unlink($f); } return $filename; } function testpdf() { $CI = & get_instance(); $CI->load->library('Generatepdf'); $CI->load->library('Generatefpdf'); $pdfFile="systemfiles/pdf/secondary/end_application/direct_deposit.pdf"; $dataInfo=[ 'printed_name'=>'ujjwal', 'date'=>"15/11/2021" ]; $pdftk = new Pdf(); $filename = "test_file.pdf"; $pdftk->addFile($pdfFile,'A'); $response=$pdftk->fillForm($dataInfo) ->flatten() ->saveAs("systemfiles/".$filename); $createdPdf="systemfiles/".$filename.'
Response:'.$response; return $createdPdf; } // function testpdf() // { // // echo "1";die; // $CI = & get_instance(); // $CI->load->library('Generatepdf'); // $CI->load->library('Generatefpdf'); // $pdfFile="systemfiles/pdf/secondary/end_application/direct_deposit.pdf"; // $dataInfo=[ // 'printed_name'=>'ujjwal', // 'date'=>"15/11/2021" // ]; // $pdftk = new Pdf(); // $filename = "test_file.pdf"; // $pdftk->addFile($pdfFile,'A'); // $pdftk->fillForm($dataInfo) // ->flatten() // ->saveAs("systemfiles/".$filename); // $createdPdf="systemfiles/".$filename; // return $createdPdf; // } // function mergePdf() // { // $CI = & get_instance(); // $CI->load->library('Generatepdf'); // $CI->load->library('Generatefpdf'); // $slug="AUTH_RELEASE_"; // $files=[ // "systemfiles/pdf/primary/start_application/information_release.pdf", // "systemfiles/pdf/primary/start_application/general_disclosure.pdf", // "systemfiles/pdf/primary/start_application/privacy_policy.pdf", // "systemfiles/pdf/primary/start_application/terms_of_use.pdf", // "systemfiles/pdf/primary/start_application/arbitration_agreement.pdf", // "systemfiles/pdf/primary/start_application/e_signature.pdf", // ]; // $pdftk = new Pdf(); // $filename = $slug.str_pad($ion_id, 6,"0",STR_PAD_LEFT).".pdf"; // $char = "A"; // foreach($files as $f){ // $pdftk->addFile($f, $char); // $pdftk->cat($char); // $char++; // } // $pdftk->saveAs("systemfiles/pdf/primary/start_application/".$filename); // } function merge_pdfs($files,$slug,$ion_id,$location) { $CI = & get_instance(); $CI->load->library('Generatepdf'); $pdftk = new Pdf(); $filename = $slug.str_pad($ion_id, 6,"0",STR_PAD_LEFT).".pdf"; $char = "A"; foreach($files as $f){ $pdftk->addFile($f, $char); $pdftk->cat($char); $char++; } $pdftk->saveAs($location.$filename); return $location.$filename; } function testfpdf() { $CI = & get_instance(); $CI->load->library('Generatepdf'); $CI->load->library('Generatefpdf'); $pdfFile="systemfiles/pdf/secondary/end_application/direct_deposit.pdf"; $dataInfo=[ 'printed_name'=>'ujjwal', 'date'=>"15/11/2021" ]; #creating image pdf file $fpdf = new fpdf(); // echo '
'; print_r($fpdf);exit;
     $filename = "fpdf_".rand(9999,99999999)."_".rand(9999,99999999).".pdf";
     $fpdf->AddPage();
     $fpdf->Image('https://png.pngtree.com/png-clipart/20190925/original/pngtree-computer-online-shopping-png-image_4986603.jpg',60,175,50,35);
     $abc=$fpdf->Output("systemfiles/".$filename,'F');
    return "systemfiles/".$filename;
     //  $imagePdf=$imagePath.$filename;
    //  $imagePdf2=$filePath.$filename;
     #creating image pdf file
}


?>