PDFtk的字体问题 [英] Font issue with PDFtk

查看:217
本文介绍了PDFtk的字体问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用pdftk填写带有真型字体的文本字段时遇到困难.

I'm having difficulties filling in a form using pdftk with text fields with true type fonts.

  • 字体文件(.ttf)已添加到/Library/Fonts(OSX Mavericks)
  • 该表单是使用Adobe Acrobat Pro创建的
  • 该表单包括使用这些字体的普通(非表单)文本
  • 表单文本字段也使用这些字体
  • 可以使用Adobe Acrobat Pro甚至预览版成功填写和打印表格

但是,pdftk在尝试使用以下命令填充时抛出错误:

However, pdftk throws an error when trying to fill it using the command:

pdftk ./my_form.pdf fill_form my_data.fdf output ./the_output.pdf

输出为:

Unhandled Java Exception in create_output():
java.lang.ArrayIndexOutOfBoundsException: 0
   at pdftk.com.lowagie.text.pdf.DocumentFont.fillEncoding(pdftk)
   at pdftk.com.lowagie.text.pdf.DocumentFont.doType1TT(pdftk)
   at pdftk.com.lowagie.text.pdf.DocumentFont.<init>(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.getAppearance(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.setField(pdftk)
   at pdftk.com.lowagie.text.pdf.AcroFields.setFields(pdftk)

如果我将文本输入的字体更改为Helvetica,Times Roman或Courier,则pdftk将成功创建PDF.奇怪的是,Arial和Georgia也抛出了相同的错误.

If I change the font of the text inputs to Helvetica, Times Roman or Courier, pdftk will successfully create a PDF. Oddly though, Arial and Georgia also throw the same error.

我已尝试按照此问题的建议使用Ghostscript将字体嵌入PDF中,如何修复PDF文件和嵌入缺少的字体. gs可能已经嵌入了字体,但是它删除了表单字段,因此生成的PDF无法反馈到pdftk.

I have tried to no avail to embed the fonts in the PDF using Ghostscript as suggested in this question How to repair a PDF file and embed missing fonts. gs may have embedded the fonts, but it removes the form fields so the resulting PDF can't feed back into pdftk.

一个工作的决议将不胜感激.

A working resolution would be greatly appreciated.

推荐答案

我在使用pdftk填充Adobe Acrobat生成的PDF表单时遇到了相同的java.lang.ArrayIndexOutOfBoundsException: 0错误.这个问题太老了,但是我在stackoverflow或其他地方找不到一致的答案,所以我想我会发布修复程序.

I was getting the same java.lang.ArrayIndexOutOfBoundsException: 0 error using pdftk to fill forms on an Adobe Acrobat generated PDF. This question is super old, but I couldn't find a consistent answer on stackoverflow or elsewhere so I figured I'd post my fix.

最终对我有用的东西:

  1. 在OS X应用程序预览中打开PDF
  2. 点击进入表单字段,添加文本,然后删除该文本(因此实际上没有任何更改)
  3. 保存

  1. Opening the PDF in the OS X app Preview
  2. Clicking into a form field, adding text then deleting that text (so nothing is actually changed)
  3. Saving it

再次通过pdftk运行PDF

我通常对编码或PDF不太熟悉,但是用Preview保存PDF似乎可以解决编码问题,或者至少可以将其保存到pdftk可以使用的地方.祝你好运.

I'm not that familiar with encoding or PDFs in general, but saving the PDF with Preview seems to fix the encoding or at least get it to a place where pdftk can work with it. Good luck.

这篇关于PDFtk的字体问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆