Skip to content
This repository was archived by the owner on Sep 28, 2018. It is now read-only.
Open
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "gears/pdf",
"name": "ETSGlobal/pdf",
"description": "A PDF builder using HTML or DOCX templates.",
"homepage": "https://github.com/phpgearbox/pdf",
"keywords": ["pdf", "docx", "template", "builder", "converter"],
Expand All @@ -13,20 +13,20 @@
},
"require":
{
"php": "^7.0",
"gears/di": "*",
"gears/string": "^0.6.0",
"symfony/process": "2.*",
"symfony/filesystem": "2.*",
"symfony/process": "2.*|3.*",
"symfony/filesystem": "2.*|3.*",
"jakoch/phantomjs-installer": "1.9.8"
},
"require-dev":
{
"codegyre/robo": "*",
"phpunit/phpunit": "4.*",
"phpunit/phpunit": "^4.8|^5.6",
"guzzlehttp/guzzle": "4.*",
"sgh/pdfbox": "dev-master",
"google/apiclient": "1.*",
"symfony/finder": "2.*"
"symfony/finder": "2.*|3.*"
},
"scripts":
{
Expand Down
6 changes: 2 additions & 4 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use SplFileInfo;
use RuntimeException;
use Gears\String as Str;
use Gears\Di\Container;
use Gears\Pdf\TempFile;

Expand Down Expand Up @@ -121,7 +120,7 @@ public function __construct($document, $config = [])
}

// Check for a HTML string
elseif (Str::contains($document, 'DOCTYPE'))
elseif (mb_strpos($document, 'DOCTYPE') !== false)
{
// Again lets save a temp file
$this->document = $this->tempFile($document, 'html');
Expand Down Expand Up @@ -198,8 +197,7 @@ public function save($path = null)
}

$ext = $this->originalDocument->getExtension();
$path = Str::s($this->originalDocument->getPathname());
$path = $path->replace('.'.$ext, '.pdf');
$path = str_replace('.'.$ext, '.pdf', $this->originalDocument->getPathname());
}

// Save the pdf to the output path
Expand Down
24 changes: 13 additions & 11 deletions src/Pdf/Docx/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use ZipArchive;
use RuntimeException;
use Gears\String as Str;
use Gears\String\Str;
use Gears\Di\Container;
use Gears\Pdf\TempFile;
use Gears\Pdf\Docx\SimpleXMLElement;
Expand All @@ -23,7 +23,7 @@
class Backend extends Container implements BackendInterface
{
/**
* @var Gears\Pdf\TempFile DOCX document to use as the template for our PDF.
* @var TempFile DOCX document to use as the template for our PDF.
* Set as the first argument of the constructor of
* this class.
*/
Expand Down Expand Up @@ -293,7 +293,7 @@ public function cloneRow($search, $numberOfClones)

$xml = $this->documentXML->asXml();

if (($tagPos = strpos($xml, $search)) === false)
if (($tagPos = mb_strpos($xml, $search)) === false)
{
throw new RuntimeException
(
Expand All @@ -304,7 +304,7 @@ public function cloneRow($search, $numberOfClones)

$rowStart = $this->findRowStart($xml, $tagPos);
$rowEnd = $this->findRowEnd($xml, $tagPos);
$xmlRow = Str::slice($xml, $rowStart, $rowEnd);
$xmlRow = mb_substr($xml, $rowStart, $rowEnd);

// Check if there's a cell spanning multiple rows.
if (preg_match('#<w:vMerge w:val="restart"/>#', $xmlRow))
Expand All @@ -322,7 +322,7 @@ public function cloneRow($search, $numberOfClones)

// If tmpXmlRow doesn't contain continue,
// this row is no longer part of the spanned row.
$tmpXmlRow = Str::slice($xml, $extraRowStart, $extraRowEnd);
$tmpXmlRow = mb_substr($xml, $extraRowStart, $extraRowEnd);
if
(
!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
Expand All @@ -336,17 +336,17 @@ public function cloneRow($search, $numberOfClones)
$rowEnd = $extraRowEnd;
}

$xmlRow = Str::slice($xml, $rowStart, $rowEnd);
$xmlRow = mb_substr($xml, $rowStart, $rowEnd);
}

$result = Str::slice($xml, 0, $rowStart);
$result = mb_substr($xml, 0, $rowStart);

for ($i = 1; $i <= $numberOfClones; $i++)
{
$result .= preg_replace('/\$\{(.*?)\}/', '\${\\1_' . $i . '}', $xmlRow);
}

$result .= Str::slice($xml, $rowEnd);
$result .= mb_substr($xml, $rowEnd);

$this->documentXML = $this->xml($result);
}
Expand Down Expand Up @@ -584,7 +584,7 @@ protected function setValueForPart($xml, $search, $replace, $limit)
$search = $this->normaliseStartTag($search);

// Make sure the replacement value is encoded correctly.
$replace = htmlspecialchars(Str::toUTF8($replace));
$replace = htmlspecialchars(mb_convert_encoding($replace, 'UTF-8'));

// Do the search and replace
return $this->xml(preg_replace
Expand Down Expand Up @@ -665,13 +665,15 @@ protected function getStartAndEndNodes($xml, $blockname)
// Search for the block start and end tags
foreach ($xml->xpath('//w:t') as $node)
{
if (Str::contains($node, $this->normaliseStartTag($blockname)))


if (mb_strpos($node, $this->normaliseStartTag($blockname)) !== false)
{
$startNode = $node;
continue;
}

if (Str::contains($node, $this->normaliseEndTag($blockname)))
if (mb_strpos($node, $this->normaliseEndTag($blockname)) !== false)
{
$endNode = $node;
break;
Expand Down
1 change: 0 additions & 1 deletion src/Pdf/Docx/Converter/LibreOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use RuntimeException;
use Gears\Di\Container;
use Gears\String as Str;
use Gears\Pdf\TempFile;
use Symfony\Component\Process\Process;
use Gears\Pdf\Contracts\DocxConverter;
Expand Down
3 changes: 1 addition & 2 deletions src/Pdf/Docx/Converter/Unoconv.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use RuntimeException;
use Gears\Di\Container;
use Gears\String as Str;
use Gears\Pdf\TempFile;
use Symfony\Component\Process\Process;
use Gears\Pdf\Contracts\DocxConverter;
Expand Down Expand Up @@ -132,7 +131,7 @@ public function convertDoc(TempFile $docx)
// NOTE: For some really odd reason the first time the command runs
// it does not complete successfully. The second time around it
// works fine. It has something to do with the homedir setup...
if (Str::contains($error, 'Error: Unable to connect'))
if (mb_strpos($error, 'Error: Unable to connect') !== false)
{
$process->run();

Expand Down
12 changes: 4 additions & 8 deletions src/Pdf/Html/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

use RuntimeException;
use Gears\Di\Container;
use Gears\String as Str;
use Gears\String\Str;
use Gears\Pdf\TempFile;
use Symfony\Component\Process\Process;
use Gears\Pdf\Contracts\Backend as BackendInterface;

class Backend extends Container implements BackendInterface
{
/**
* @var Gears\Pdf\TempFile The document we will convert to PDF.
* @var TempFile The document we will convert to PDF.
*/
protected $document;

Expand All @@ -42,7 +42,7 @@ class Backend extends Container implements BackendInterface
protected $injectRunner;

/**
* @var Symfony\Component\Process\Process
* @var Process
*/
protected $injectProcess;

Expand Down Expand Up @@ -133,11 +133,7 @@ public function generate()
{
$this->document->setContents
(
Str::s($this->document->getContents())->replace
(
'</head>',
$this->printFramework.'</head>'
)
str_replace('</head>', $this->printFramework.'</head>', $this->document->getContents())
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PdfGoogleTest.php.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////

use Gears\String as Str;
use Gears\String\Str;
use SGH\PdfBox\PdfBox;

class PdfGoogleTest extends PHPUnit_Framework_TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/PdfLibreOfficeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////

use Gears\String as Str;
use Gears\String\Str;
use SGH\PdfBox\PdfBox;

class PdfLibreOfficeTest extends PHPUnit_Framework_TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/PdfPhantomJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////

use Gears\String as Str;
use Gears\String\Str;
use SGH\PdfBox\PdfBox;

class PdfPhantomJsTest extends PHPUnit_Framework_TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/PdfUnoconvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////

use Gears\String as Str;
use Gears\String\Str;
use SGH\PdfBox\PdfBox;

class PdfUnoconvTest extends PHPUnit_Framework_TestCase
Expand Down