Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new method to the Pdf Class (pdf::buildCommand) so that we can g... #74

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ I also found that some options don't work on Windows (tested with wkhtmltopdf 0.
`user-style-sheet` option used in the example below.


### Warning: proc_open(): CreateProcess failed

In some versions of PHP for Windows, `proc_open()` does not work properly. If you experience this, you can use `exec()`
to run the command as a workaround:

```
$pdf = new Pdf();
$pdf->addPage('http://google.com');
$cmd = $pdf->buildCommand()->getExecCommand();
exec($cmd);
```


## Setup for different wkhtmltopdf versions

As mentioned before the PHP class is just a convenient frontend for the `wkhtmltopdf` command. So you need to
Expand Down
31 changes: 25 additions & 6 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,9 @@ protected function createPdf()
if ($this->_isCreated) {
return false;
}
$command = $this->getCommand();
$fileName = $this->getPdfFilename();
$command = $this->buildCommand($fileName);

$command->addArgs($this->_options);
foreach ($this->_objects as $object) {
$command->addArgs($object);
}
$command->addArg($fileName, null, true); // Always escape filename
if (!$command->execute()) {
$this->_error = $command->getError();
if (!(file_exists($fileName) && filesize($fileName)!==0 && $this->ignoreWarnings)) {
Expand All @@ -254,6 +249,30 @@ protected function createPdf()
return true;
}


/**
* Build the Command with the arguments passed
*
* @param string $fileName The pdf filename
* @return \mikehaertl\wkhtmlto\Command
*/
public function buildCommand($fileName = null)
{
if (is_null($fileName)) {
$fileName = $this->getPdfFilename();
}

$command = $this->getCommand();

$command->addArgs($this->_options);
foreach ($this->_objects as $object) {
$command->addArgs($object);
}
$command->addArg($fileName, null, true); // Always escape filename

return $command;
}

/**
* @param string $input
* @return mikehaertl\tmp\File|string a File object if the input is a html string. The unchanged input otherwhise.
Expand Down