dpr81047 2013-01-30 16:37
浏览 101
已采纳

pdfmark:生成的PDF书签标题中的某些重音字符无法正确显示

I'm inserting bookmarks to existing PDF and have some problem with accented "c". There is the example (charset used in the example is UTF-8):

$name = "Ruční nářadí";

$name = chr(254).chr(255).iconv('UTF-8', 'UTF-16BE', str_replace(array('(',')','/'),array('\\(','\\)','\\/'),$name));

$fh = fopen('pdfmark.txt', 'w');
fputs($fh, "[/Title ({$name}) /Page 1 /OUT pdfmark
");
fclose($fh);

$command = "gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf final.pdf pdfmark.txt; mv out.pdf final.pdf";
exec($command);

The problem is that accented č appears in bookmark of final PDF as Ċ (uppercase letter with different accent). I tried other accented characters used in my language (Czech) and except of this one everything is ok.

Thanks for any clues to solve this issue.

EDIT (2013-02-01):

Version of GhostScript used is 9.06 (2012-08-08). I'm using Adobe Reader 11.0.1 to view the resulting PDF file.

I'm still thinking about it...Does it have to be encoding specified in PDF in some way? Because the source PDF is out of my control and I know quite nothing about it. If it is the case, is there any way to use GS or pdfmark to do so? I thought that if the encoding of the bookmarks is Unicode so it realy doesn't matter, but maybe I'm wrong.

EDIT (2013-02-05):

There seems to be bug in GS's pdfwrite or Acrobat, more info in GS's bug tracking. I will write solution info here, after it will be resolved.

  • 写回答

3条回答 默认 最新

  • duanfeng3879 2013-02-07 08:14
    关注

    According to bug tracking post it works for me to encode the string in different way (also it could help to download newer version 9.08 PRERELEASE):

    $name = "Ruční nářadí";
    
    $name = 'FEFF'.strtoupper(bin2hex(iconv('UTF-8', 'UCS-2BE', str_replace(array('(',')','/'),array('\\(','\\)','\\/'),$name))));
    
    $fh = fopen('pdfmark.txt', 'w');
    fputs($fh, "[/Title <{$name}> /Page 1 /OUT pdfmark
    ");
    fclose($fh);
    
    $command = "gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf final.pdf pdfmark.txt; mv out.pdf final.pdf";
    exec($command);
    

    Note the encoding to hex format and also different parenthesis in title definition.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题