请参考以下示例代码:
// Add text field
try {
Control control = form.addControl(page, "Text Field0", Field.e_TypeTextField, new RectF(50, 600, 90, 640)); DefaultAppearance defaultAppearance = new DefaultAppearance(e_FlagFont|e_FlagFontSize|e_FlagTextColor,new Font(e_StdIDCourier),10,1); control.getField().setDefaultAppearance(defaultAppearance); control.getField().setValue("3测试"); // Update text field's appearance. control.getWidget().resetAppearanceStream(); //这段可注释掉,先执行上面的代码,对比看差异 DefaultAppearance defaultAppearance_New = control.getField().getDefaultAppearance(); // defaultAppearance_New.setText_size(20); defaultAppearance_New.setText_color(16711680); control.getField().setDefaultAppearance(defaultAppearance_New); control.getField().setValue("new 测试"); control.getWidget().resetAppearanceStream(); } catch (PDFException e) { e.printStackTrace();
}
System.out.println("Add text field.");
您需要注意此样例的处理逻辑,并且注意resetAppearanceStream()方法的调用。