I want to wrap text in a rect which is below (or left or right) of a image as below :
Please see link : http://upanh.in/SLk/
I use ColumnText for wrapping text in my code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/pdf");
try {
// step 1
Document document = new Document(PageSize.A4.rotate());
// step 2
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
// step 3
document.open();
// step 4
ColumnText column = new ColumnText(writer.getDirectContent());
column.setSimpleColumn(new Phrase("text is very long ..."), 10, 10, 20, 20, 18, Element.ALIGN_CENTER);
column.go();
// step 5
document.close();
ServletOutputStream os = response.getOutputStream();
baos.writeTo(os);
os.flush();
os.close();
} catch (DocumentException e) {
throw new IOException(e.getMessage());
}
}
Result:
ExceptionConverter: java.io.IOException: The document has no pages.
Do you have any suggestions how to fix that?
Question 2
I try to display text (center and middle) in the rect with below code but it wasn't success. The text was only center in the rect.
ColumnText column = new ColumnText(writer.getDirectContent());
column.setSimpleColumn(RectImg1[0], RectImg1[1], RectImg1[0] + squareHeight, RectImg1[1] + squareHeight
* 1 / 4);
Paragraph p = new Paragraph(imgr.getText(), fontH);
p.setAlignment(Element.ALIGN_CENTER | Element.ALIGN_MIDDLE);
p.setLeading(18);
column.addElement(p);
column.go();
where was my mistake ?