我在这方面取得了一些进展。从http://koivi.com/fill-pdf-form-fields/的代码开始,我修改了值编码,以输出ascii范围之外的任何字符的数字代码。
与pitulski的特殊字符串
现在:
Poznań Śródmieście Ćwiartka Ósma
输出Pozna ródmiecie wiartka Ósma
一些盒子形状叠加
ęóąśłżźćńĘÓĄŚŁŻŹĆŃ
输出óÓ
有更多的箱的形状。我认为这可能是盒子的形状是我的服务器无法识别的字符。
我试着用一些法文字符:ùûüÿ€’“”«»àâæçéèêëïôœÙÛÜŸÀÂÆÇÉÈÊËÏÎÔ
,他们都出来了,但其中一些重叠。
--edit--我只是尝试手动输入这些表单,并得到相同的结果减去箱形(使用Evince)。然后我用另一种形式(由别人创建)尝试 - 在输入ęóąśłżźćńĘÓĄŚŁŻŹĆŃ
后,显示ółÓŁ
。它看起来像取决于哪些字符包含在文档的嵌入字体中。
/*
KOIVI HTML Form to FDF Parser for PHP (C) 2004 Justin Koivisto
Version 1.2.?
Last Modified: 2013/01/17 - Jon Hulka(jon dot hulka at gmail dot com)
- changed character encoding, all non-ascii characters get encoded as numeric character references
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Full license agreement notice can be found in the LICENSE file contained
within this distribution package.
Justin Koivisto
justin dot koivisto at gmail dot com
http://koivi.com
*/
/**
* createXFDF
*
* Tales values passed via associative array and generates XFDF file format
* with that data for the pdf address sullpiled.
*
* @param string $file The pdf file - url or file path accepted
* @param array $info data to use in key/value pairs no more than 2 dimensions
* @param string $enc default UTF-8, match server output: default_charset in php.ini
* @return string The XFDF data for acrobat reader to use in the pdf form file
*/
function createXFDF($file,$info,$enc='UTF-8'){
$data=
'<?xml version="1.0" encoding="'.$enc.'"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>';
foreach($info as $field => $val){
$data.='
<field name="'.$field.'">';
if(is_array($val)){
foreach($val as $opt)
//2013.01.17 - Jon Hulka - all non-ascii characters get character references
$data.='
<value>'.mb_encode_numericentity(htmlspecialchars($opt),array(0x0080, 0xffff, 0, 0xffff), 'UTF-8').'</value>';
// $data.='<value>'.htmlentities($opt,ENT_COMPAT,$enc).'</value>'."\n";
}else{
$data.='
<value>'.mb_encode_numericentity(htmlspecialchars($val),array(0x0080, 0xffff, 0, 0xffff), 'UTF-8').'</value>';
// $data.='<value>'.htmlentities($val,ENT_COMPAT,$enc).'</value>'."\n";
}
$data.='
</field>';
}
$data.='
</fields>
<ids original="'.md5($file).'" modified="'.time().'" />
<f href="'.$file.'" />
</xfdf>';
return $data;
}
您是否尝试过直接使用iText库来执行此功能? – Merlin 2011-08-03 10:46:31
看看http://stackoverflow.com/questions/6047970/weird-characters-when-filling-pdf-with-pdftk它解决了我的问题 – 2014-03-05 00:36:47