Filling PDF fields with distorted Chinese characters

I am trying to fill a PDF field with Chinese characters from fdf or xfdf.

So far I have tried pdftk, mcpdf, pdfbox and fpdm.

All of them can receive characters in the field, but they are not displayed. When I click on an editable field, the characters are displayed as expected, but when I exit the field again, they disappear. If I enter English, they do not display correctly, for example, β€œhello” becomes β€œIFMMP”.

All this led me to the fact that I suspect that this is a problem with font and character cards, I tried to embed the full font in pdf, and it did not matter. I installed fonts on the machine to no avail.

If I edit the pdf and fill in the field in Acrobat, it will accept Chinese characters without any problems, and I can view the PDF file in the reader. I tried using pdftk from the command line on the same windows machine and I have the same problem.

I need this to work in a Linux environment, and preferably in python or through a command line script, but in fact at this point I just want it to work at all! I have enclosed an example pdf, fdf, xfdf and the conclusion that it creates, any help would be greatly appreciated since I ran out of ideas. I used the command:

"pdftk test_form.pdf fill_form test.xfdf output output.pdf verbose"

https://drive.google.com/folderview?id=0B6ExNaWGFzvnfnJHSC1ZdXhSU2RQVENjYW56UkZyYWJMdWhZTkpQYkZBcUs0Tjhjb0NITVE&usp=sharing

+4
source share
1

, () , . , , , , , .

PDFBox 1.8, PDFBox 2.0, , .

, , , , . PDFBox 2.0 ,

Warning: Using fallback font 'TimesNewRomanPSMT' for 'MingLiU'
Exception in thread "main" java.lang.IllegalArgumentException: No glyph for U+5185 in font MingLiU

MingLiU , TimesNewRomanPSMT, .

Adobe Reader ,

PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
form.setNeedAppearances(true);

PDFBox 2.0

, PDFBox 2, , ,

// create a new PDF document
PDDocument doc = new PDDocument();
PDPage page = new PDPage();

// add a new AcroForm and add that to the document
PDAcroForm form = new PDAcroForm(doc);
doc.getDocumentCatalog().setAcroForm(form);

// Add and set the resources and default appearance at the form level
PDFont font = PDType0Font.load(doc, new File("/Library/Fonts/Arial Unicode.ttf"));
PDResources res = new PDResources();
COSName fontName = res.add(font);
form.setDefaultResources(res);
String da = "/" + fontName.getName() + " 12 Tf 0 g";
form.setDefaultAppearance(da);

// add a page to the document 
doc.addPage(page);

// add a form field to the form
PDTextField textBox = new PDTextField(form);
textBox.setPartialName("Chinese");
form.getFields().add(textBox);

// specify the annotation associated with the field
// and add it to the page
PDAnnotationWidget widget = textBox.getWidget();
PDRectangle rect = new PDRectangle(100f,300f,120f,350f);
widget.setRectangle(rect);
page.getAnnotations().add(widget);

// set the field value
textBox.setValue("ζœ¨ε…°θΎž");
doc.save("ChineseOut.pdf");

. , , , , MingLiU - TrueType, PDFBox .

+4

All Articles