This class is a wrapper around pdftk. The class was developed for pdftk 2.x but should also work with older versions, but you may have to use slightly different page rotation options (e.g 'E' instead 'east').
Author: Michael Härtl (haertl.mike@gmail.com)
Exemplo n.º 1
1
 public function dosplit(Request $request)
 {
     $print_element = Element::where('subject_lesson_id', $request->subject_lesson_id)->where('title', 'نسخة للطباعة')->first();
     if (!$print_element) {
         $print_element = new Element();
         $print_element->title = 'نسخة للطباعة';
         $print_element->element_order = 10;
         $print_element->state = 'نشط';
         $print_element->type = 'pdf';
         $print_element->subject_lesson_id = $request->subject_lesson_id;
         $print_element->file = $request->file('file');
         $print_element->save();
     }
     foreach ($request->subject_element_title as $key => $value) {
         if ($request->element_start_page[$key]) {
             $elelment = new Element();
             $fonly = uniqid() . time() . '.pdf';
             $filename = public_path() . '/temp/' . $fonly;
             $elelment->title = $value;
             $elelment->element_order = $request->element_order[$key];
             $elelment->state = 'نشط';
             $elelment->type = 'pdf';
             $elelment->subject_lesson_id = $request->subject_lesson_id;
             $pdf = new Pdf($print_element->file->path());
             $pdf->cat($request->element_start_page[$key], $request->element_end_page[$key]);
             $pdf->saveAs($filename);
             // sleep(8);
             $elelment->file = $filename;
             // $elelment->file = 'https://el-css.edu.om/admin/public/temp/'.$fonly;
             $elelment->save();
         }
     }
     $message = 'تم اضافة العناصر بنجاح';
     return redirect()->route('s.elements.index', array('id' => $request->subject_lesson_id))->with('success', $message);
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // this is where we will initiate the generation process
     // which we'll eventually do by calling an appropriate class to
     // integrate the data received into a PDF and then passing it back to the manager
     // or even more likely, by firing an event and then having a series of listeners respond to it
     // for now ...
     $view = view('documents.chase-letter')->with('document', $this->document)->render();
     $dataPDF = storage_path('app/tmp-' . $this->document['reference'] . '.pdf');
     $finalPDF = storage_path('app/' . $this->document['reference'] . '.pdf');
     // create PDF
     try {
         $pdf = new Pdf(['binary' => '/usr/bin/wkhtmltopdf', 'margin-top' => 0, 'margin-right' => 0, 'margin-bottom' => 0, 'margin-left' => 0, 'commandOptions' => ['enableXvfb' => true]]);
         $pdf->addPage($view);
         $pdf->saveAs($dataPDF);
     } catch (Exception $e) {
         Log::error('Could not create PDF: ' . $pdf->getError());
     }
     // stamp it
     try {
         $pdftk = new Pdftk(base_path('resources/assets/docs/cluster-template.pdf'));
         $pdftk->stamp($dataPDF);
         $pdftk->saveAs($finalPDF);
     } catch (Exception $e) {
         Log::error('Could not stamp or save PDF: ' . $pdf->getError());
     }
     $data = ['multipart' => [['name' => $this->document['reference'] . '.pdf', 'contents' => fopen($finalPDF, 'r')]]];
     $httpClient = new HttpClient();
     $httpClient->post(env('CLUSTER_MANAGER') . '/receive-pdf', $data);
     // @todo, use proper Laravel helpers for removing finished-with files
     unlink($dataPDF);
     unlink($finalPDF);
 }
Exemplo n.º 3
0
 public function testCanGetDataFields()
 {
     $form = $this->getForm();
     $pdf = new Pdf($form);
     $data = $pdf->getDataFields();
     $this->assertInternalType('string', $data);
     $this->assertEquals($this->formDataFields, $data);
 }
Exemplo n.º 4
0
 /**
  * @param string|Pdf $name the PDF filename or Pdf instance to add for processing
  * @param string|null $handle one or more uppercase letters A..Z to reference this file later.
  * If no handle is provided, an internal handle is autocreated, consuming the range Z..A
  * @param string|null $password the owner (or user) password if any
  * @return Pdf the pdf instance for method chaining
  */
 public function addFile($name, $handle = null, $password = null)
 {
     if ($handle === null) {
         $handle = $this->nextHandle();
     }
     if ($name instanceof Pdf) {
         // Keep a reference to the object to prevent unlinking
         $this->_pdf = $name;
         if (!$name->getCommand()->getExecuted()) {
             // @todo: Catch errors!
             $name->execute();
         }
         $name = (string) $name->getTmpFile();
     }
     $this->getCommand()->addFile($name, $handle, $password);
     return $this;
 }
Exemplo n.º 5
0
 public function generate()
 {
     $pdf = new Pdf($this->_pdf);
     // Сложим рубли с копейками
     $num_sum1 = $this->_num_sum1 + $this->_num_sum1_kopeck;
     $num_sum2 = $this->_num_sum2 + $this->_num_sum2_kopeck;
     // echo  $this->_num_sum1_kopeck;exit;
     //Разобьём нужные нам числа
     $fromIndexSplit = Number::getSplitDigits($this->_from_index, 6);
     $toIndexSplit = Number::getSplitDigits($this->_to_index, 6);
     $fromInnSplit = Number::getSplitDigits($this->_from_inn, 12);
     $fromCorpPriceSplit = Number::getSplitDigits($this->_from_corp_price, 20);
     $fromCalcPriceSplit = Number::getSplitDigits($this->_from_calc_price, 20);
     $pdfParams = array('words_sum1' => Number::num2str($num_sum1), 'words_sum2' => Number::num2str($num_sum2), 'num_sum1' => $this->_num_sum1, 'num_sum2' => $this->_num_sum2, 'num_sum2_kopeck' => Number::fract($this->_num_sum2_kopeck), 'to_fio' => $this->_to_fio, 'to_addr' => $this->_to_addr, 'from_fio' => $this->_from_fio, 'from_addr' => $this->_from_addr);
     // Склеим ассоциативные массивы с друг другом
     $pdfParams = array_merge($pdfParams, $this->cookPrefixArray($fromIndexSplit, 'from_index_'), $this->cookPrefixArray($toIndexSplit, 'to_index_'), $this->cookPrefixArray($fromInnSplit, 'inn_'), $this->cookPrefixArray($fromCorpPriceSplit, 'corp_price_'), $this->cookPrefixArray($fromCalcPriceSplit, 'calc_price_'));
     // var_dump($pdfParams);
     $pdf->fillForm($pdfParams)->needAppearances();
     if ($err = $pdf->getError()) {
         return $err;
     }
     $pdf->send();
 }
Exemplo n.º 6
-2
 public function submitForm(Request $request)
 {
     //Get input
     $input = Input::all();
     //Date
     $input["Date"] = date("j/ n/ Y");
     //Bools for Parties
     if ($input["party"] == "Republican") {
         $input["Rep"] = "Yes";
     } else {
         $input["Dem"] = "Yes";
     }
     //concat name
     $input["Voter_Name"] = $input["first_name"] . " " . $input["last_name"];
     $contents = Storage::disk('local');
     $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
     // $contents = Storage::get('reg.pdf');
     //Save as FDF
     $fdf = new FdfFile($input);
     $fdf->saveAs('data.fdf');
     $docId = md5(uniqid(rand(), true));
     //Save as Pdf
     $pdf = new Pdf($storagePath . 'template.pdf');
     $pdf->fillForm($fdf->getFileName())->saveAs($storagePath . "generated/" . $docId . '.pdf');
     //Setting up Lob
     $apiKey = env('LOB_KEY');
     $lob = new \Lob\Lob($apiKey);
     //Send the letter
     $letter = $lob->letters()->create(array('description' => 'Voter Registration', 'to[name]' => 'Town Clerk', 'to[address_line1]' => '230 Main St, Ste 108', 'to[address_city]' => 'Brattleboro', 'to[address_zip]' => '05301', 'to[address_state]' => 'VT', 'to[address_country]' => 'US', 'from[name]' => 'Benjamin Franklin', 'from[address_line1]' => '123 Fake Street', 'from[address_city]' => 'Philadelphia', 'from[address_zip]' => '94041', 'from[address_state]' => 'PA', 'from[address_country]' => 'US', 'file' => '@' . realpath($storagePath . "generated/" . $docId . '.pdf'), 'color' => false));
     $letter['file'] = $storagePath . "generated/" . $docId . '.pdf';
     return View::make('thanks', $letter)->with('data', $letter);
 }