From 3c262366fee393cb868dfe1d32ba329c07154fec Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sun, 6 Mar 2016 15:57:53 +0100 Subject: [PATCH] Choose endianness for conversion According to that message on stackoverflow (http://stackoverflow.com/questions/8923866/convert-utf8-to-utf16-using-iconv#8924403), choosing which endianness we want to use remove the BOM from the string. The BOM was generated in the bookmarks text during the generation. When forcing the endianness, the BOM is no longer rendered. See #102 --- lib/PHPPdf/Core/Engine/ZF/GraphicsContext.php | 2 +- tests/PHPPdf/Test/Core/Engine/ZF/GraphicsContextTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PHPPdf/Core/Engine/ZF/GraphicsContext.php b/lib/PHPPdf/Core/Engine/ZF/GraphicsContext.php index 5a021bf7..acb63d48 100644 --- a/lib/PHPPdf/Core/Engine/ZF/GraphicsContext.php +++ b/lib/PHPPdf/Core/Engine/ZF/GraphicsContext.php @@ -371,7 +371,7 @@ public function addBookmark($identifier, $name, $top, $parentIdentifier = null) $action = \ZendPdf\Action\GoToAction::create($destination); //convert from input encoding to UTF-16 - $name = iconv($this->encoding, 'UTF-16', $name); + $name = iconv($this->encoding, 'UTF-16BE', $name); $outline = \ZendPdf\Outline\AbstractOutline::create($name, $action); diff --git a/tests/PHPPdf/Test/Core/Engine/ZF/GraphicsContextTest.php b/tests/PHPPdf/Test/Core/Engine/ZF/GraphicsContextTest.php index e1266fa2..6c457fae 100644 --- a/tests/PHPPdf/Test/Core/Engine/ZF/GraphicsContextTest.php +++ b/tests/PHPPdf/Test/Core/Engine/ZF/GraphicsContextTest.php @@ -559,7 +559,7 @@ public function attachSingleBookmark() private function assertOutline($expectedName, $expectedPage, $expectedTop, $actualOutline) { - $this->assertEquals(iconv(self::ENCODING, 'UTF-16', $expectedName), $actualOutline->getTitle()); + $this->assertEquals(iconv(self::ENCODING, 'UTF-16BE', $expectedName), $actualOutline->getTitle()); $target = $actualOutline->getTarget();