我有一个用户可以填写的网页表单,该内容用FPDF和PHP填充PDF。当用户输入带撇号的单词时,PDF上会出现斜杠。
同样,商标符号等特殊字符编码错误。
FPDF常见问题说明使用:
$str = utf8_decode($str);
但我不确定如何将其应用于整个PDF。我试着把它想象成一个HTML页面,但这没有帮助。
有什么想法吗?
答案 0 :(得分:67)
通过执行以下操作来解决这个问题(pagesubtitle是表单中文本字段的名称):
$reportSubtitle = stripslashes($_POST['pagesubtitle']);
$reportSubtitle = iconv('UTF-8', 'windows-1252', $reportSubtitle);
然后打印出来:
$pdf->Write (6, $reportSubtitle);
这将删除撇号后的任何不需要的斜杠,以及使用'iconv'功能打印特殊字符,如™
答案 1 :(得分:23)
以上所有内容对我都不起作用,但我确实让它发挥作用。
我设法通过将每个奇怪的角色转换为其url值来实现“野蛮方式”。然后简单地解码网址瞧!
function em($word) {
$word = str_replace("@","%40",$word);
$word = str_replace("`","%60",$word);
$word = str_replace("¢","%A2",$word);
$word = str_replace("£","%A3",$word);
$word = str_replace("¥","%A5",$word);
$word = str_replace("|","%A6",$word);
$word = str_replace("«","%AB",$word);
$word = str_replace("¬","%AC",$word);
$word = str_replace("¯","%AD",$word);
$word = str_replace("º","%B0",$word);
$word = str_replace("±","%B1",$word);
$word = str_replace("ª","%B2",$word);
$word = str_replace("µ","%B5",$word);
$word = str_replace("»","%BB",$word);
$word = str_replace("¼","%BC",$word);
$word = str_replace("½","%BD",$word);
$word = str_replace("¿","%BF",$word);
$word = str_replace("À","%C0",$word);
$word = str_replace("Á","%C1",$word);
$word = str_replace("Â","%C2",$word);
$word = str_replace("Ã","%C3",$word);
$word = str_replace("Ä","%C4",$word);
$word = str_replace("Å","%C5",$word);
$word = str_replace("Æ","%C6",$word);
$word = str_replace("Ç","%C7",$word);
$word = str_replace("È","%C8",$word);
$word = str_replace("É","%C9",$word);
$word = str_replace("Ê","%CA",$word);
$word = str_replace("Ë","%CB",$word);
$word = str_replace("Ì","%CC",$word);
$word = str_replace("Í","%CD",$word);
$word = str_replace("Î","%CE",$word);
$word = str_replace("Ï","%CF",$word);
$word = str_replace("Ð","%D0",$word);
$word = str_replace("Ñ","%D1",$word);
$word = str_replace("Ò","%D2",$word);
$word = str_replace("Ó","%D3",$word);
$word = str_replace("Ô","%D4",$word);
$word = str_replace("Õ","%D5",$word);
$word = str_replace("Ö","%D6",$word);
$word = str_replace("Ø","%D8",$word);
$word = str_replace("Ù","%D9",$word);
$word = str_replace("Ú","%DA",$word);
$word = str_replace("Û","%DB",$word);
$word = str_replace("Ü","%DC",$word);
$word = str_replace("Ý","%DD",$word);
$word = str_replace("Þ","%DE",$word);
$word = str_replace("ß","%DF",$word);
$word = str_replace("à","%E0",$word);
$word = str_replace("á","%E1",$word);
$word = str_replace("â","%E2",$word);
$word = str_replace("ã","%E3",$word);
$word = str_replace("ä","%E4",$word);
$word = str_replace("å","%E5",$word);
$word = str_replace("æ","%E6",$word);
$word = str_replace("ç","%E7",$word);
$word = str_replace("è","%E8",$word);
$word = str_replace("é","%E9",$word);
$word = str_replace("ê","%EA",$word);
$word = str_replace("ë","%EB",$word);
$word = str_replace("ì","%EC",$word);
$word = str_replace("í","%ED",$word);
$word = str_replace("î","%EE",$word);
$word = str_replace("ï","%EF",$word);
$word = str_replace("ð","%F0",$word);
$word = str_replace("ñ","%F1",$word);
$word = str_replace("ò","%F2",$word);
$word = str_replace("ó","%F3",$word);
$word = str_replace("ô","%F4",$word);
$word = str_replace("õ","%F5",$word);
$word = str_replace("ö","%F6",$word);
$word = str_replace("÷","%F7",$word);
$word = str_replace("ø","%F8",$word);
$word = str_replace("ù","%F9",$word);
$word = str_replace("ú","%FA",$word);
$word = str_replace("û","%FB",$word);
$word = str_replace("ü","%FC",$word);
$word = str_replace("ý","%FD",$word);
$word = str_replace("þ","%FE",$word);
$word = str_replace("ÿ","%FF",$word);
return $word;
}
当然我要调用函数
$weirdword = "Días, Miércoles, Sábado,miércoles"; //Some spanish days
$weirdword = em($weirdword);
$weirdword = urldecode($weirdword);
echo $weirdword;
给出输出:
Días,Miércoles,Sábado,miércoles
答案 2 :(得分:6)
以上都没有解决我的问题。我通过以下方式解决了它:
setlocale(LC_CTYPE, 'en_US');
$value = iconv('UTF-8', 'ASCII//TRANSLIT', $value);
$fpdf->Cell(140, 6, $value, 1);
希望你会有所帮助。
参考: Link
答案 3 :(得分:4)
以上解决方案都不适合我,所以我解决了这个问题:
$this->AddFont('Arial','','arial.php');
$this->SetFont('Arial','',12);
$this->Cell(0,5,iconv("UTF-8", "CP1250//TRANSLIT", $string),0,1,'L');
在尝试上述行之前,请执行以下操作:
从c:/Windows/Fonts/Arial.ttf复制到FPDF的/ tutorial文件夹。
编辑makefont.php的内容
require('../makefont/makefont.php');
MakeFont('arial.ttf','cp1250');
执行makefont.php
将以下文件复制到FPDF的/ font文件夹: arial.php ARIAL.TTF arial.z
最后,定义“字体文件夹”。打开fpdf.php(主库文件)并添加:
define('FPDF_FONTPATH','font');
PDF对我来说适用于所有特殊字符,我相信它是Arial字体本身的问题,FPDF最初使用它。它应该与其他字体一起使用,如果它们支持你的角色。祝你好运!
答案 4 :(得分:2)
此类是FPDF的修改版本,可添加UTF-8支持。 而且,它只嵌入了字体的必要部分 在文档中使用,使文件大小比如果小得多 嵌入了整个字体。这些功能最初是开发的 为mPDF项目。
答案 5 :(得分:2)
以下为我工作(使用FPDF):
function em_jaz($word) {
$word = str_replace('+', ' ', $word);
$word = str_replace("%C3%A9","%E9",$word); /* é */
$word = str_replace("%C3%A8","%E8",$word); /* è */
$word = str_replace("%C3%AE","%EE",$word); /* î */
$word = str_replace("%26rsquo%3B","%27",$word); /* ' */
$word = str_replace("%C3%89","%C9",$word); /* É */
$word = str_replace("%C3%8A","%CA",$word); /* Ê */
$word = str_replace("%C3%8B","%CB",$word); /* Ë */
$word = str_replace("%C3%8C","%CC",$word); /* Ì */
$word = str_replace("%C3%8D","%CD",$word); /* Í */
$word = str_replace("%C3%8E","%CE",$word); /* Î */
$word = str_replace("%C3%8F","%CF",$word); /* Ï */
$word = str_replace("%C3%90","%D0",$word); /* Ð */
$word = str_replace("%C3%91","%D1",$word); /* Ñ */
$word = str_replace("%C3%92","%D2",$word); /* Ò */
$word = str_replace("%C3%93","%D3",$word); /* Ó */
$word = str_replace("%C3%94","%D4",$word); /* Ô */
$word = str_replace("%C3%95","%D5",$word); /* Õ */
$word = str_replace("%C3%96","%D6",$word); /* Ö */
$word = str_replace("%C3%98","%D8",$word); /* Ø */
$word = str_replace("%C3%99","%D9",$word); /* Ù */
$word = str_replace("%C3%9A","%DA",$word); /* Ú */
$word = str_replace("%C3%9B","%DB",$word); /* Û */
$word = str_replace("%C3%9C","%DC",$word); /* Ü */
$word = str_replace("%C3%9D","%DD",$word); /* Ý */
$word = str_replace("%C3%9E","%DE",$word); /* Þ */
$word = str_replace("%C3%9F","%DF",$word); /* ß */
$word = str_replace("%C3%A0","%E0",$word); /* à */
$word = str_replace("%C3%A1","%E1",$word); /* á */
$word = str_replace("%C3%A2","%E2",$word); /* â */
$word = str_replace("%C3%A3","%E3",$word); /* ã */
$word = str_replace("%C3%A4","%E4",$word); /* ä */
$word = str_replace("%C3%A5","%E5",$word); /* å */
$word = str_replace("%C3%A6","%E6",$word); /* æ */
$word = str_replace("%C3%A7","%E7",$word); /* ç */
$word = str_replace("%C3%AA","%EA",$word); /* ê */
$word = str_replace("%C3%AB","%EB",$word); /* ë */
$word = str_replace("%C3%AC","%EC",$word); /* ì */
$word = str_replace("%C3%AD","%ED",$word); /* í */
$word = str_replace("%C3%AF","%EF",$word); /* ï */
$word = str_replace("%C3%B0","%F0",$word); /* ð */
$word = str_replace("%C3%B1","%F1",$word); /* ñ */
$word = str_replace("%C3%B2","%F2",$word); /* ò */
$word = str_replace("%C3%B3","%F3",$word); /* ó */
$word = str_replace("%C3%B4","%F4",$word); /* ô */
$word = str_replace("%C3%B5","%F5",$word); /* õ */
$word = str_replace("%C3%B6","%F6",$word); /* ö */
$word = str_replace("%C3%B7","%F7",$word); /* ÷ */
$word = str_replace("%C3%B8","%F8",$word); /* ø */
$word = str_replace("%C3%B9","%F9",$word); /* ù */
$word = str_replace("%C3%BA","%FA",$word); /* ú */
$word = str_replace("%C3%BB","%FB",$word); /* û */
$word = str_replace("%C3%BC","%FC",$word); /* ü */
$word = str_replace("%C3%BD","%FD",$word); /* ý */
$word = str_replace("%C3%BE","%FE",$word); /* þ */
$word = str_replace("%C3%BF","%FF",$word); /* ÿ */
$word = str_replace("%40","%40",$word); /* @ */
$word = str_replace("%60","%60",$word); /* ` */
$word = str_replace("%C2%A2","%A2",$word); /* ¢ */
$word = str_replace("%C2%A3","%A3",$word); /* £ */
$word = str_replace("%C2%A5","%A5",$word); /* ¥ */
$word = str_replace("%7C","%A6",$word); /* | */
$word = str_replace("%C2%AB","%AB",$word); /* « */
$word = str_replace("%C2%AC","%AC",$word); /* ¬ */
$word = str_replace("%C2%AF","%AD",$word); /* ¯ */
$word = str_replace("%C2%BA","%B0",$word); /* º */
$word = str_replace("%C2%B1","%B1",$word); /* ± */
$word = str_replace("%C2%AA","%B2",$word); /* ª */
$word = str_replace("%C2%B5","%B5",$word); /* µ */
$word = str_replace("%C2%BB","%BB",$word); /* » */
$word = str_replace("%C2%BC","%BC",$word); /* ¼ */
$word = str_replace("%C2%BD","%BD",$word); /* ½ */
$word = str_replace("%C2%BF","%BF",$word); /* ¿ */
$word = str_replace("%C3%80","%C0",$word); /* À */
$word = str_replace("%C3%81","%C1",$word); /* Á */
$word = str_replace("%C3%82","%C2",$word); /* Â */
$word = str_replace("%C3%83","%C3",$word); /* Ã */
$word = str_replace("%C3%84","%C4",$word); /* Ä */
$word = str_replace("%C3%85","%C5",$word); /* Å */
$word = str_replace("%C3%86","%C6",$word); /* Æ */
$word = str_replace("%C3%87","%C7",$word); /* Ç */
$word = str_replace("%C3%88","%C8",$word); `/`* È */
return $word;
}
$ content = urlencode($ content);
$ content = urldecode($ pdf-> em_jaz($ content));
答案 6 :(得分:1)
我以from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
来使用它已经足够了,我消除了不包含字母数字的字符
答案 7 :(得分:0)
听起来你已启用magic_quotes。请参阅禁用magic_quotes的链接。
答案 8 :(得分:0)
这对我来说是这样的: iconv("UTF-8", "ISO-8859-1//TRANSLIT//IGNORE", your-text-var-here)
答案 9 :(得分:-1)
尝试这个简单的功能:utf8_encode($txt)
。它对我有用。