Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
bug-fix #8 Single page issue
Browse files Browse the repository at this point in the history
  • Loading branch information
anton.nikolaev committed Apr 3, 2017
1 parent 886a2f8 commit 9d58fa8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getOptions($key=null)
public function setOptions($key, $value=null)
{
if (is_array($key)) {
$this->options = array_merge($this->options, $key);
$this->options = array_replace_recursive($this->options, $key);
} elseif (is_string($key)) {
$this->options[$key] = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Html extends Base

public function __construct($options=[])
{
$this->setOptions(array_merge($this->defaultOptions, $options));
$this->setOptions(array_replace_recursive($this->defaultOptions, $options));
}

/**
Expand Down
44 changes: 37 additions & 7 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Pdf extends Base
private $file = null;
private $info = null;
private $html = null;
private $result = null;

private $defaultOptions = [
'pdftohtml_path' => '/usr/bin/pdftohtml',
Expand All @@ -30,7 +31,7 @@ class Pdf extends Base
'imageJpeg' => false,
'ignoreImages' => false,
'zoom' => 1.5,
'noFrames' => false,
'noFrames' => true,
],

'outputDir' => '',
Expand All @@ -44,7 +45,7 @@ class Pdf extends Base

public function __construct($file, $options=[])
{
$this->setOptions(array_merge($this->defaultOptions, $options));
$this->setOptions(array_replace_recursive($this->defaultOptions, $options));
$this->setFile($file)->setInfoObject()->setHtmlObject();
}

Expand Down Expand Up @@ -146,9 +147,17 @@ private function getContent()
$fileinfo = pathinfo($this->file);
$base_path = $this->getOutputDir() . '/' . $fileinfo['filename'];

for ($i = 1; $i <= $this->countPages(); $i++) {
$content = file_get_contents($base_path . '-' . $i . '.html');
$this->html->addPage($i, $content);
$countPages = $this->countPages();
if ($countPages) {
if ($countPages > 1)
for ($i = 1; $i <= $countPages; $i++) {
$content = file_get_contents($base_path . '-' . $i . '.html');
$this->html->addPage($i, $content);
}
else {
$content = file_get_contents($base_path . '.html');
$this->html->addPage(1, $content);
}
}

if ($this->getOptions('clearAfter'))
Expand All @@ -161,11 +170,32 @@ private function getContent()
*/
private function generate()
{
$this->result = null;
$command = $this->getCommand();
$this->result = exec($command);
return $this;
}

/**
* Get command for generate html
* @return string
*/
public function getCommand() {
if ($this->countPages() > 1)
$this->setOptions(['generate'=>['noFrames' => false]]);
$output = $this->getOutputDir() . '/' . preg_replace("/\.pdf$/", '', basename($this->file)) . '.html';
$options = $this->generateOptions();
$command = $this->getOptions('pdftohtml_path') . ' ' . $options . ' ' . $this->file . ' ' . $output;
$result = exec($command);
return $this;
return $command;
}

/**
* Get result of generate html
* @return string|null
*/
public function getResult()
{
return $this->result;
}

/**
Expand Down

0 comments on commit 9d58fa8

Please sign in to comment.