【问题标题】:Missing single quote when using PDFStamper使用 PDFStamper 时缺少单引号
【发布时间】: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


【解决方案1】:

问题最终是被选为输入框字体的 Times 字体没有撇号字符。将字体更改为 Arial 或 Verdana 即可解决问题。

【讨论】:

  • 对我有用的一个技巧是打印 '\u2019' 而不是撇号。这是一个正确的单引号。我的眼睛无法分辨。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-24
  • 2019-03-09
  • 1970-01-01
  • 1970-01-01
  • 2014-10-20
  • 2014-08-02
  • 1970-01-01
相关资源
最近更新 更多