File tree 3 files changed +32
-2
lines changed 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ A PDF conversion and form utility based on pdftk.
31
31
32
32
> ** Note** If you're on Ubuntu you may want to install the version from ` ppa:malteworld/ppa ` .
33
33
> The default packages seems to use snap an there have been reports about file permission
34
- > issues with this version.
34
+ > issues with this version. See below for a workaround.
35
35
36
36
## Installation
37
37
@@ -321,6 +321,16 @@ $pdf->fillForm(['name' => 'My Name'])
321
321
$content = file_get_contents( (string) $pdf->getTmpFile() );
322
322
```
323
323
324
+ If you have permission issues you may have to set a directory where your
325
+ ` pdftk ` command can write to:
326
+
327
+ ``` php
328
+ use mikehaertl\pdftk\Pdf;
329
+
330
+ $pdf = new Pdf('/path/my.pdf');
331
+ $pdf->tempDir = '/home/john/temp';
332
+ ```
333
+
324
334
## API
325
335
326
336
Please consult the source files for a full documentation of each method.
Original file line number Diff line number Diff line change @@ -26,6 +26,12 @@ class Pdf
26
26
*/
27
27
public $ ignoreWarnings = false ;
28
28
29
+ /**
30
+ * @var null|string an optional directory where temporary files should be
31
+ * created. If left empty the directory is autodetected.
32
+ */
33
+ public $ tempDir ;
34
+
29
35
/**
30
36
* @var File the temporary output file
31
37
*/
@@ -608,7 +614,7 @@ public function getCommand()
608
614
public function getTmpFile ()
609
615
{
610
616
if ($ this ->_tmpFile === null ) {
611
- $ this ->_tmpFile = new File ('' , '.pdf ' , self ::TMP_PREFIX );
617
+ $ this ->_tmpFile = new File ('' , '.pdf ' , self ::TMP_PREFIX , $ this -> tempDir );
612
618
}
613
619
return $ this ->_tmpFile ;
614
620
}
Original file line number Diff line number Diff line change @@ -583,6 +583,20 @@ public function testCanGetPdfContentAsString()
583
583
$ this ->assertEquals (file_get_contents ($ file ), $ pdf ->toString ());
584
584
}
585
585
586
+ public function testCanSetTemporaryDirectory ()
587
+ {
588
+ $ document = $ this ->getDocument1 ();
589
+ $ file = $ this ->getOutFile ();
590
+ $ dir = dirname ($ file );
591
+
592
+ $ pdf = new Pdf ($ document );
593
+ $ pdf ->tempDir = $ dir ;
594
+ $ this ->assertTrue ($ pdf ->saveAs ($ file ));
595
+
596
+ $ tmpFile = (string ) $ pdf ->getTmpFile ();
597
+ $ this ->assertStringStartsWith ($ dir , $ tmpFile );
598
+ }
599
+
586
600
protected function getDocument1 ()
587
601
{
588
602
return __DIR__ . '/files/document1.pdf ' ;
You can’t perform that action at this time.
0 commit comments