File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -518,6 +518,19 @@ public function send($filename=null,$inline=false)
518
518
return true ;
519
519
}
520
520
521
+ /**
522
+ * Get the raw PDF contents (triggers PDF creation).
523
+ * @return string|bool the PDF content as a string or `false` if the PDF
524
+ * wasn't created successfully.
525
+ */
526
+ public function toString ()
527
+ {
528
+ if (!$ this ->getCommand ()->getExecuted () && !$ this ->execute ()) {
529
+ return false ;
530
+ }
531
+ return file_get_contents ($ this ->getTmpFile ()->getFileName ());
532
+ }
533
+
521
534
/**
522
535
* @return Command the command instance that executes pdftk
523
536
*/
Original file line number Diff line number Diff line change @@ -552,6 +552,17 @@ public function testCanGetDataFields()
552
552
$ this ->assertEquals ($ this ->formDataFieldsArray , $ data ->__toArray ());
553
553
}
554
554
555
+ public function testCanGetPdfContentAsString ()
556
+ {
557
+ $ document = $ this ->getDocument1 ();
558
+ $ file = $ this ->getOutFile ();
559
+
560
+ $ pdf = new Pdf ($ document );
561
+ $ this ->assertTrue ($ pdf ->saveAs ($ file ));
562
+ $ this ->assertFileExists ($ file );
563
+ $ this ->assertEquals (file_get_contents ($ file ), $ pdf ->toString ());
564
+ }
565
+
555
566
protected function getDocument1 ()
556
567
{
557
568
return __DIR__ .'/files/document1.pdf ' ;
You can’t perform that action at this time.
0 commit comments