+ String img_title = currentImage.getFieldValue("title");
+ String img_path = currentImage.getFieldValue("publish_path");
+
+ if ((status & ColumnText.NO_MORE_TEXT) == 0) {
+ // there is still text, so add an image which will have text wrapped around it, then add the text which
+ // will be on the left or the right of the image
+
+ float templateMinimumHeight = img_height + 20;
+ float templateWidth = img_width + 10;
+ float templateHeight = templateMinimumHeight + contentLineHeight - (templateMinimumHeight % contentLineHeight);
+
+ PdfTemplate template = cb.createTemplate(templateWidth, templateHeight);
+
+ //here we need a page check
+ if (! enoughY((new Float(templateHeight)).intValue())) {
+ //ok, well just fill text to the bottom then
+ float toYPosition = bottomEdge + footerHeight;
+ float[] leftBottomCols = {leftEdge, currentYPosition, leftEdge, toYPosition};
+ float[] rightBottomCols = {rightEdge, currentYPosition, rightEdge, toYPosition};
+ ct.setColumns(leftBottomCols, rightBottomCols);
+ ct.setYLine(currentYPosition);
+ ct.setAlignment(Element.ALIGN_JUSTIFIED);
+ try {
+ status = ct.go();
+ }
+ catch (DocumentException de) {
+ logger.error(de.getMessage());
+ }
+ newPage();
+ }
+
+ float toYPosition = currentYPosition - templateHeight;
+
+ try {
+ Image theImage = Image.getInstance(localImageDir + img_path);
+ theImage.scaleAbsolute(img_width, img_height);
+ theImage.setAbsolutePosition(5, 13);
+
+ template.addImage(theImage);
+ template.beginText();
+ BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
+ template.setFontAndSize(bf, 8);
+ template.setTextMatrix(5, 3);
+ template.showText(img_title);
+ template.endText();
+ }
+ catch (BadElementException de) {
+ logger.error(de.getMessage());
+ }
+ catch (DocumentException de) {
+ logger.error(de.getMessage());
+ }
+ catch (MalformedURLException de) {
+ logger.error(de.getMessage());
+ }
+ catch (IOException de) {
+ logger.error(de.getMessage());
+ }
+
+
+ float leftImageTextEdge = leftEdge;
+ float rightImageTextEdge = rightEdge;
+
+
+ if (addImageOnLeft) {
+ cb.addTemplate(template, leftEdge, toYPosition);
+ leftImageTextEdge = leftEdge + templateWidth + 5;
+ addImageOnLeft = false;
+ } else {
+ cb.addTemplate(template, rightEdge - templateWidth, toYPosition);
+ rightImageTextEdge = rightEdge - templateWidth - 5;
+ addImageOnLeft = true;
+ }
+
+ logger.debug("adding template at " + leftEdge + "," + toYPosition);
+
+ //and fill some text while we are at it
+
+ float[] leftBottomCols = {leftImageTextEdge, currentYPosition, leftImageTextEdge, toYPosition};
+ float[] rightBottomCols = {rightImageTextEdge, currentYPosition, rightImageTextEdge, toYPosition};
+ ct.setColumns(leftBottomCols, rightBottomCols);
+ ct.setYLine(currentYPosition);
+ ct.setAlignment(Element.ALIGN_JUSTIFIED);
+ try {
+ status = ct.go();
+ currentYPosition = toYPosition;
+ }
+ catch (DocumentException de) {
+ logger.error(de.getMessage());
+ }
+
+
+ } else {
+ //add an image on the left with a big caption to the right
+ currentYPosition = currentYPosition - 10;
+ float templateMinimumHeight = img_height;
+ float templateWidth = img_width;
+ float templateHeight = templateMinimumHeight + contentLineHeight - (templateMinimumHeight % contentLineHeight);
+ PdfTemplate template = cb.createTemplate(templateWidth, templateHeight);
+ if (! enoughY((new Float(templateHeight)).intValue())) {
+ newPage();
+ }
+ float toYPosition = currentYPosition - templateHeight;
+ try {
+ Image theImage = Image.getInstance(localImageDir + img_path);
+ theImage.setAbsolutePosition(0, 13);
+ theImage.scaleAbsolute(img_width, img_height);
+ template.addImage(theImage);
+ }
+ catch (BadElementException de) {
+ logger.error(de.getMessage());
+ }
+ catch (DocumentException de) {
+ logger.error(de.getMessage());
+ }
+ catch (MalformedURLException de) {
+ logger.error(de.getMessage());
+ }
+ catch (IOException de) {
+ logger.error(de.getMessage());
+ }
+
+ cb.addTemplate(template, leftEdge, toYPosition);
+
+ // add a big caption
+ ColumnText cct = new ColumnText(cb);
+ float[] leftCaptionCols = {leftEdge + templateWidth + 5, currentYPosition - 5, leftEdge + templateWidth + 5, toYPosition};
+ float[] rightCaptionCols = {rightEdge, currentYPosition - 5, rightEdge, toYPosition};
+
+ Paragraph captionP = new Paragraph(img_title, new Font(bigImageCaptionFontFamily, bigImageCaptionFontSize, Font.BOLD));
+ cct.addText(captionP);
+ cct.setColumns(leftCaptionCols, rightCaptionCols);
+ cct.setYLine(currentYPosition - 5);
+ cct.setAlignment(Element.ALIGN_LEFT);
+ try {
+ cct.go();
+ currentYPosition = toYPosition;
+ }
+ catch (DocumentException de) {
+ logger.error(de.getMessage());
+ }