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 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂