【发布时间】:2015-04-16 05:02:14
【问题描述】:
我正在使用 ColdFusion 11 和 Java (com.lowagie.text.pdf.PdfStamper) 来填写 pdf,但是当我输入带有单个撇号的值时,例如 32',它只会在 pdf 中保存为 32 而不是 32' .该值将进入 PDF 中的多行文本区域。我尝试过启用和不启用富文本。
我尝试将' 替换为&#39&#59;、''、&apos&#59; 和\u0027;,但它们都消失了。我也试过xmlFormat,但它显示为&apos&#59;。
从 MS Word 复制和粘贴 ’ 也不能作为替换值。
这是我正在使用的代码
this.pdfFile = this.pdfService.read( source=infile );
this.pdfReader = createObject("java","com.lowagie.text.pdf.PdfReader").init( tobinary( this.pdffile ) );
this.pdfWriter = createObject( "java", "java.io.FileOutputStream").init( CreateObject( "java", "java.io.File" ).init( this.outfile ));
this.pdfStamper = createObject( "java", "com.lowagie.text.pdf.PdfStamper").init( this.pdfReader, this.PdfWriter );
this.acroForm = this.pdfStamper.getAcroFields();
//this.misc.text = replace( this.misc.text, "'", "&##39;", "all");
//this.misc.text = replace( this.misc.text, "'", "\u0027;", "all");
//this.misc.text = replace( this.misc.text, "'", "’", "all");
//this.misc.text = replace( this.misc.text, "'", "'", "all");
//this.misc.text = PreserveSingleQuotes( this.misc.text );
this.acroForm.setField("text", this.misc.text );
【问题讨论】:
-
你能做一个手册
convertToString (this.misc.text, PdfObject.TEXT_PDFDOCENCODING)并检查那个时候引用是否消失了吗? -
@Jongware 我尝试了以下方法,但没有成功。 this.misc.text = this.PdfEncodings.convertToBytes(this.misc.text, this.PdfObject.TEXT_PDFDOCENCODING); this.misc.text = this.PdfEncodings.convertToString(this.misc.text, this.PdfObject.TEXT_PDFDOCENCODING);
-
convertToString 需要一个 byte[] 而不是字符串。
标签: java pdf coldfusion