|
Following is the code. I manages to get it to add
the Number on the top, but it is still not next to the image. I am very new to
this and am just trying to learn how to properly use the iText libraries, so any
help/advise would be very useful. It's in a JSP by the
way....
<%@ page contentType="application/pdf;
charset=iso-8859-1" language="java"
import="com.lowagie.text.Image,java.awt.Color,java.util.*,java.text.*,com.lowagie.text.*,com.lowagie.text.Chunk,com.lowagie.text.Font,com.lowagie.text.pdf.PdfWriter,com.lowagie.text.pdf.ColumnText,com.lowagie.text.pdf.PdfContentByte,java.util.*,java.io.*"%><%
Document document = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = null; docWriter = PdfWriter.getInstance(document, baosPDF); document.open(); PdfContentByte cb = docWriter.getDirectContent(); com.lowagie.text.pdf.ColumnText ct = new com.lowagie.text.pdf.ColumnText(cb); float[] right = {70, 320}; float[] left = {300, 550}; String[] images = {"0601.01.00-A.gif","0601.01.00.gif","0602.01.00-A.gif","0602.02.00.gif","0603.02.00.gif","0605.01.00-A.gif","0601.01.00- A.gif","0601.01.00.gif","0602.01.00-A.gif","0602.02.00.gif","0603.02.00.gif","0605.01.00-A.gif","0601.01.00- A.gif","0601.01.00.gif","0602.01.00-A.gif","0602.02.00.gif","0603.02.00.gif","0605.01.00-A.gif"}; String pth= "http://myimages.blah/"; Chunk t = new Chunk("Directions: ANSWER The Following Questions to the best of your ability.\n\n",FontFactory.getFont(FontFactory.TIMES, 8, Font.BOLD, new Color(0, 0, 0))); ct.addText(t); for(int i=0;i<images.length;i++){ String s = String.valueOf(i+1) + "."; java.net.URL u = new java.net.URL(pth + images[i]); com.lowagie.text.Image im = com.lowagie.text.Image.getInstance(u); float orgHeight; float iWidth= (document.getPageSize().width())/(float)2.5; orgHeight=(im.plainHeight()*iWidth)/im.plainWidth(); im.scaleAbsolute((float)iWidth,orgHeight); im.setAlignment(Image.RIGHT | Image.TEXTWRAP); Chunk ch = new Chunk(s,FontFactory.getFont(FontFactory.TIMES, 8, Font.BOLD, new Color(0, 0, 0))); ct.addText(ch); Chunk c = new Chunk(im,5,-10,true); ct.addText(c); c = new Chunk("\n\n"); ct.addText(c); } int status = 0; int column = 0; while((status & ColumnText.NO_MORE_TEXT) == 0) { ct.setSimpleColumn(right[column], 50, left[column], 790, 10, Element.ALIGN_UNDEFINED); ct.setLeading(0,1); status = ct.go(); if ((status & ColumnText.NO_MORE_COLUMN) != 0) { column++; if (column > 1) { document.newPage(); column = 0; } } } document.close(); response.setContentLength(baosPDF.size()); baosPDF.writeTo(response.getOutputStream()); response.getOutputStream().flush();%> ~~~~~~~~~~~~~~~~~~~~~~~~~
Timothy Woolley [EMAIL PROTECTED] www.intervisionmedia.com ~~~~~~~~~~~~~~~~~~~~~~~~~
|
- Re: [iText-questions] Image and Text on same line Paulo Soares
- Re: [iText-questions] Image and Text on same line Timothy Woolley
