You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when text length is longger, same text can't display ,
such as my text is "这是一段非常长的文字这是一段非常长的文字这是一段非常长的文字",
but pdf may be only show "这是一段非常长的文字这是一段" ,
I don't find api or code how to slove it , in AcroFields#setFieldProperty , can't find "fontsize" .
may I have some other way to slove it ? I hope can display complete ,although the font size may be small.
there is my demo code:
`
// load pdf file
ClassPathResource resource = new ClassPathResource("my.pdf");
InputStream inputStream = resource.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
com.lowagie.text.pdf.PdfReader reader = null;
ByteArrayOutputStream bos = null;
try {
reader = new com.lowagie.text.pdf.PdfReader(bufferedInputStream);
bos = new ByteArrayOutputStream();
com.lowagie.text.pdf.PdfStamper pdfStamper = new com.lowagie.text.pdf.PdfStamper(reader, bos);
com.lowagie.text.pdf.AcroFields acroFields = pdfStamper.getAcroFields();
// chinese font
com.lowagie.text.pdf.BaseFont font = com.lowagie.text.pdf.BaseFont.createFont("simsun.ttc,0", com.lowagie.text.pdf.BaseFont.IDENTITY_H, com.lowagie.text.pdf.BaseFont.EMBEDDED);
for (Map.Entry<String, String> param : params1.entrySet()) {
// set text font
acroFields.setFieldProperty(param.getKey().trim(), "textfont", font, null);
// replace map content to pdf (write content from map value, map defined by self)
// and the problems occur here
acroFields.setField(param.getKey().trim(), param.getValue());
}
// set pdf edit box can't edit after replacing map value
pdfStamper.setFormFlattening(true);
pdfStamper.close();
// return
PdfServiceController.ServletUtils.writeAttachment(response, "简单劳动合同模板.pdf", bos.toByteArray());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
assert bos != null;
bos.close();
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
`
The text was updated successfully, but these errors were encountered:
I find it , acroFields.setFieldProperty(param.getKey().trim(), "textsize",9f, null);
but the pdf may have many different edit box , some text may short ,so needn't 9f (font size) ; and I wonder if it counld auto make the font of long text smaller (don't change global font size) or change line
when text length is longger, same text can't display ,
such as my text is "这是一段非常长的文字这是一段非常长的文字这是一段非常长的文字",
but pdf may be only show "这是一段非常长的文字这是一段" ,
I don't find api or code how to slove it , in AcroFields#setFieldProperty , can't find "fontsize" .
may I have some other way to slove it ? I hope can display complete ,although the font size may be small.
there is my demo code:
`
// load pdf file
ClassPathResource resource = new ClassPathResource("my.pdf");
InputStream inputStream = resource.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
The text was updated successfully, but these errors were encountered: