我正在尝试使用iText更改字体属性,但无法使其正常工作。您对此代码有什么问题有任何意见吗?
public static ByteArrayOutputStream createPersonnelReport(String sablonDir, String g,byte[] fotograf) {
ByteArrayOutputStream baos = null;
try {
baos = new ByteArrayOutputStream();
BaseFont fontTimes = BaseFont.createFont(sablonDir + File.separator + fontName, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
PdfReader reader = new PdfReader(sablonDir + File.separator + tmSablonForSicilKaydiName);
PdfStamper stamper = new PdfStamper(reader, baos);
AcroFields form = stamper.getAcroFields();
PdfContentByte canvas = stamper.getOverContent(1);
form.setField("g", g);
boolean check=form.setFieldProperty("g", "textsize", new Float(26), null);
System.out.println("check: "+ check);
InputStream fotografImage = new ByteArrayInputStream(fotograf);
BufferedImage bImageFromConvert = ImageIO.read(fotografImage);
int type = bImageFromConvert.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : bImageFromConvert.getType();
BufferedImage dimensionedImage = resizeImage(bImageFromConvert, type);
ImageIO.write(dimensionedImage, "jpg", new File("c:/yeniPersonelFoto.jpg"));
Image image1 = Image.getInstance("c:/yeniPersonelFoto.jpg");
image1.setAbsolutePosition(450f, 650f);
canvas.addImage(image1);
stamper.setFormFlattening(true);
stamper.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
return baos;
}
}
编辑:检查:输出中返回true
答案 0 :(得分:1)
答案是缺少一行代码:
form.regenerateField("g");
解决了这个问题。进行更改后,您必须重新生成该字段。