Skip to content

Commit a02d971

Browse files
committed
When no page is set, full document is merged.
1 parent 593ca09 commit a02d971

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

src/PHPGhostscript/Ghostscript.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ class Ghostscript
102102

103103
/**
104104
* Page start
105-
*
106-
* @var int
105+
*
106+
* @var ?int
107107
*/
108-
private $pageStart = 1;
108+
private $pageStart = null;
109109

110110
/**
111111
* Page end
112112
*
113-
* @var int
113+
* @var ?int
114114
*/
115-
private $pageEnd = 1;
115+
private $pageEnd = null;
116116

117117
/**
118118
* Box mode used for rendering
@@ -390,7 +390,7 @@ public function getOutputFile() : string
390390
*
391391
* @return self
392392
*/
393-
public function setPageStart(int $page) : Ghostscript
393+
public function setPageStart(?int $page): Ghostscript
394394
{
395395
$this->pageStart = $page;
396396
return $this;
@@ -402,7 +402,7 @@ public function setPageStart(int $page) : Ghostscript
402402
*
403403
* @return int $pageStart
404404
*/
405-
public function getPageStart() : int
405+
public function getPageStart(): ?int
406406
{
407407
return $this->pageStart;
408408
}
@@ -415,7 +415,7 @@ public function getPageStart() : int
415415
*
416416
* @return self
417417
*/
418-
public function setPageEnd(int $page) : Ghostscript
418+
public function setPageEnd(?int $page): Ghostscript
419419
{
420420
$this->pageEnd = $page;
421421
return $this;
@@ -427,7 +427,7 @@ public function setPageEnd(int $page) : Ghostscript
427427
*
428428
* @return int $pageEnd
429429
*/
430-
public function getPageEnd() : int
430+
public function getPageEnd(): ?int
431431
{
432432
return $this->pageEnd;
433433
}
@@ -515,8 +515,14 @@ public function render()
515515
$command->addArg('-dSAFER');
516516
$command->addArg('-dNOPLATFONTS');
517517
$command->addArg('-sOutputFile=' . $this->outputFile);
518-
$command->addArg('-dFirstPage=' . $this->pageStart);
519-
$command->addArg('-dLastPage=' . $this->pageEnd);
518+
519+
if ($this->pageStart !== null) {
520+
$command->addArg('-dFirstPage=' . $this->pageStart);
521+
}
522+
523+
if ($this->pageEnd !== null) {
524+
$command->addArg('-dLastPage=' . $this->pageEnd);
525+
}
520526

521527
if (!$this->isVectorDevice()) {
522528
$command->addArg('-dTextAlphaBits=' . $this->getTextAntiAliasing());

tests/PHPGhostscript/PHPGhostscriptTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ public function testSettingPages()
110110
{
111111
$ghostscript = new Ghostscript();
112112

113-
$this->assertEquals(1, $ghostscript->getPageStart());
113+
$this->assertEquals(null, $ghostscript->getPageStart());
114114
$ghostscript->setPageStart(20);
115115
$this->assertEquals(20, $ghostscript->getPageStart());
116116

117-
$this->assertEquals(1, $ghostscript->getPageEnd());
117+
$this->assertEquals(null, $ghostscript->getPageEnd());
118118
$ghostscript->setPageEnd(99);
119119
$this->assertEquals(99, $ghostscript->getPageEnd());
120120

@@ -171,6 +171,22 @@ public function testMerging()
171171
$this->assertTrue($result);
172172
}
173173

174+
public function testMerging2()
175+
{
176+
$outputFile = __DIR__ . DIRECTORY_SEPARATOR . 'output' . DIRECTORY_SEPARATOR . 'merge2.pdf';
177+
$ghostscript = new Ghostscript();
178+
$ghostscript
179+
->setBinaryPath($this->binaryPath)
180+
->setDevice(DeviceTypes::PDF)
181+
->setInputFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'a2.pdf')
182+
->setInputFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'b1.pdf')
183+
->setOutputFile($outputFile);
184+
$result = $ghostscript->render();
185+
$this->assertTrue(file_exists($outputFile));
186+
$this->assertEquals("application/pdf", mime_content_type($outputFile));
187+
$this->assertTrue($result);
188+
}
189+
174190
public function testClearInputFiles()
175191
{
176192
$ghostscript = new Ghostscript();

tests/PHPGhostscript/assets/a2.pdf

7.63 KB
Binary file not shown.

tests/PHPGhostscript/assets/b1.pdf

6.87 KB
Binary file not shown.

0 commit comments

Comments
 (0)