2012-04-22 74 views
3

我想用iTextSharp填寫AcroForm的textfield。該Acroform文本框也被創造了由iTextSharp的通過這一段代碼:iTextSharp - acroform字段編碼

TextField Field = new TextField(OutputWriter, FieldPos, "MyField"); 
OutputWriter.AddAnnotation(Field.GetTextField()); // OutputWriter is writing to form.pdf 

我使用此代碼填寫表格:

PdfReader reader = new PdfReader("form.pdf"); 
PdfStamper filledOutForm = new PdfStamper(reader, new FileStream("filled_form.pdf", FileMode.Create)); 

AcroFields form = filledOutForm.AcroFields; 
form.SetField("MyField", "some unicode data"); 

然而,當我在Acrobat Reader,Unicode字符打開filled_form.pdf除非我手動編輯字段(例如,我用手將字符附加到字段),否則不可見。

我也試圖通過設置字段的字體:

BaseFont fieldFontRoman = BaseFont.CreateFont(@"C:\Windows\Fonts\times.ttf", 
           BaseFont.IDENTITY_H, 
           BaseFont.EMBEDDED); 
form.SetFieldProperty("MyField", "textfont", fieldFontRoman, null); 

然後,當我在Acrobat Reader中打開filled_form.pdf,一切都看起來不錯,除非我手動編輯的字段。之後,非Unicode字符消失(它們變成空格)。他們在這個領域,因爲如果我通過CTRL + C複製整個字段的內容並粘貼到記事本中,我可以看到所有字符。

請指教。我希望看到字段中的所有字符,而不需要手動編輯字段,當然在手動編輯之後,我不希望字符消失。

謝謝

回答

5

設置SubstitutionFont創建PdfStamper後:

stamper.AcroFields.AddSubstitutionFont(myFont.BaseFont); 
+0

Reader軟件是能夠在同一個文檔設置的Unicode字段值,而不訴諸替代字體。沒有更好的方法來解決這個問題嗎? – 2012-12-06 13:09:00

+0

同時設置替換字體在拼合文檔時似乎不起作用。 – 2012-12-08 14:21:06

相關問題