psliwa / PHPPdf

Pdf and graphic files generator library written in php
http://ohey.pl
MIT License
339 stars 77 forks source link

Choose endianness for conversion #107

Open aledeg opened 8 years ago

aledeg commented 8 years ago

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

psliwa commented 8 years ago

It looks like this PR breaks bookmarks feature at all (at least on my machines - I've tested this on php 5.3 and 5.5). Are you sure this is the solution? I am not able to reproduce the problem from #102

aledeg commented 8 years ago

I was able to reproduce it on my machine. I am running PHP 7. Here is the code of my test to reproduce #102

<?php

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

set_time_limit(0);

require_once __DIR__.'/../vendor/autoload.php';

$facade = PHPPdf\Core\FacadeBuilder::create()->build();

$doc = <<<DOC
<pdf>
    <dynamic-page>
        <div bookmark="Hêtre">Hêtre</div>
        <div bookmark="Où">Où</div>
        <div bookmark="Trouvère">Trouvère</div>
        <div bookmark="Étendu">Étendu</div>
    </dynamic-page>
</pdf>
DOC;

$content = $facade->render($doc);

header('Content-Type: application/pdf');
echo $content;

And to answer your question, I am really not sure about this being a solution. But it looks like the endianness of the string is the root of the problem.

aledeg commented 8 years ago

I tried again on PHP 5.5. I can reproduce with the code above and I can fix it with the PR.