saveAs() public method

Execute the operation and save the output file
public saveAs ( string $name ) : boolean
$name string of output file
return boolean whether the PDF could be processed and saved
Esempio 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);
 }
Esempio n. 3
0
 public function testSet40BitEncryption()
 {
     $document = $this->getDocument1();
     $file = $this->getOutFile();
     $pdf = new Pdf($document);
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->passwordEncryption(40));
     $this->assertTrue($pdf->saveAs($file));
     $this->assertFileExists($file);
     $tmpFile = (string) $pdf->getTmpFile();
     $this->assertEquals("pdftk A='{$document}' output '{$tmpFile}' encrypt_40bit", (string) $pdf->getCommand());
 }