Create a template and add the two images to that template. Load that template as an image with Image.getInstance(template) and use it as any other image.
Paulo > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Sverre Moe > Sent: Tuesday, March 27, 2007 9:29 AM > To: [email protected] > Subject: Re: [iText-questions] Overlay a transparent gif on > another image > > I found the solution to my problem. > > First I get current vertical position just after last > document.add() and inserted the images at absolute position > from that value. > Then I constructed a ColumnText rectangle just below the image. > > float currentVerticalPosition = writer.getVerticalPosition(false); > image.setAbsolutePosition(0, currentVerticalPosition - > image.scaledHeight() - 2); > document.add(image); > ... > PdfContentByte cb = writer.getDirectContent(); > ColumnText ct = new ColumnText(cb); > currentVerticalPosition -= image.scaledHeight() - 2; > ct.setSimpleColumn(0f, 0f, PageSize.A4.width() - 5, > currentVerticalPosition - 20, 18, Element.ALIGN_JUSTIFIED); > ct.addElement(table2); > int status = ct.go(); > > Just one thing. I see no reason for the status variable. > There should be a go() that did not return a integer. I can > see the purpose for it though, if you have multiple pages, > but for my document I know for certain that the document will > not span more than one page. > > > > 2007/3/23, Paulo Soares <[EMAIL PROTECTED]>: > > Don't send a big image. This is just to be able to > reproduce the problem and find a solution, you don't have to > sent what you use in production. You can also post a link to > the file somewhere. > > Paulo > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto: > [EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> ] On > > Behalf Of Sverre Moe > > Sent: Friday, March 23, 2007 12:49 PM > > To: Post all your questions about iText here > > Subject: Re: [iText-questions] Overlay a transparent gif on > > another image > > > > Tried to send a working java file with the images. But the > > image is to big to send, as I got a feilure to send > message back. > > > > > > 2007/3/23, Paulo Soares < [EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]> >: > > > > That's not a standalone example and you didn't attach > > any images. I want something that can be run directly from a > > main() in console mode. You may have to modify your code to > > work this way. > > > > Paulo > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] > > > [mailto: > [EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> ] On > > > Behalf Of Sverre Moe > > > Sent: Friday, March 23, 2007 11:41 AM > > > To: Post all your questions about iText here > > > Subject: Re: [iText-questions] Overlay a > transparent gif on > > > another image > > > > > > > > > Here it goes: some meaningless code omitted. > > > > > > PdfWriter writer = PdfWriter.getInstance(document, > > > response.getOutputStream()); > > > document.open(); > > > > > > Paragraph title = new Paragraph ("Some Text", > new Font( > > > Font.TIMES_ROMAN , 40, Font.BOLD)); > > > tittel.setAlignment (Element.ALIGN_CENTER); > > > document.add(title); > > > > > > String infotextString = "Some text Some text Some > > text Some text"; > > > Paragraph infotext = new > Paragraph(infotextString, new Font( > > > Font.TIMES_ROMAN, 18, Font.NORMAL, new Color > (255, 0, 0))); > > > document.add(infotext); > > > > > > float[] widths1 = { 0.4f, 0.4f, 0.7f }; > > > PdfPTable table = new PdfPTable(widths1); > > > table.setSpacingBefore (30f); > > > table.setSpacingAfter(15f); > > > table.setWidthPercentage(70); > > > table.getDefaultCell().setBorderWidth(0.5f); > > > table.getDefaultCell().setBorderColor(Color.red); > > > table.getDefaultCell ().setPaddingBottom(2); > > > table.getDefaultCell().setPaddingTop(2); > > > table.getDefaultCell().setUseDescender(true); > > > Paragraph brann = new Paragraph("text: 110", new Font > > > ( Font.TIMES_ROMAN, 18, Font.NORMAL)); > > > Paragraph politi = new Paragraph("text: 112", new Font > > > (Font.TIMES_ROMAN, 18, Font.NORMAL)); > > > Paragraph ambulanse = new Paragraph("text: > 113", new Font > > > (Font.TIMES_ROMAN , 18, Font.NORMAL)); > > > table.addCell(brann); > > > table.addCell(politi); > > > table.addCell(ambulanse); > > > document.add(table); > > > > > > //Main image > > > Paragraph imagetitle = new Paragraph("Image > text", new Font( > > > Font.TIMES_ROMAN, 14, Font.BOLD)); > > > document.add (imagetitle); > > > String URL = > > (String)request.getSession().getAttribute("getMapURL"); > > > Image image = Image.getInstance(new URL(URL)); > > > image.scaleToFit (PageSize.A4.width(), > PageSize.A4.height()); > > > image.setAlignment(Image.MIDDLE | Image.TEXTWRAP); > > > image.setAbsolutePosition(0, 335); > > > document.add(image); > > > > > > //transparent Image overlay > > > String imageURL = request.getRequestURL().substring(0, > > > request.getRequestURL().lastIndexOf("/")); > > > Image image2 = > Image.getInstance(imageURL+"/img/overlay.png"); > > > image2.scaleToFit (PageSize.A4.width(), > PageSize.A4.height()); > > > image2.setAlignment(Image.MIDDLE | Image.TEXTWRAP); > > > image2.setAbsolutePosition(0, 335); > > > document.add(image2); > > > > > > String sname = > > > > > > ((String)request.getSession().getAttribute("stedsnavn")).trim(); > > > float userdefinedWidth = new Chunk(sname, new > > > Font(Font.HELVETICA, 22, > Font.NORMAL)).getWidthPoint(); > > > float fixedWidth = new Chunk("Textname:", new > > > Font( Font.HELVETICA, 22, Font.NORMAL > )).getWidthPoint(); > > > float padding = 20; > > > float[] widths2 = { fixedWidth + padding, > > userdefinedWidth + padding}; > > > PdfPTable table2 = new PdfPTable(widths2); > > > table2.getDefaultCell().setBorderWidth(0f); > > > table2.setTotalWidth(widths2); > > > table2.setLockedWidth(true); > > > table2.setSpacingBefore(40f); > > > table2.setSpacingAfter(10f); > > > Paragraph stitle = new > Paragraph("Stedsnavn:", new Font( > > > Font.HELVETICA, 22, Font.BOLD)); > > > Paragraph snameP = new Paragraph(sname, new > > > Font(Font.HELVETICA, 22, Font.NORMAL)); > > > table2.addCell(stitle); > > > table2.addCell(snameP); > > > document.add (table2); > > > > > > > > > 2007/3/23, Paulo Soares <[EMAIL PROTECTED]>: > > > > > > Prepare a small but complete standalone > example that > > > includes the image, > > > don't bother about the gif for now. > Attach the code, > > > the image and the > > > gif to the message. I'll tell you how > to put the gif in > > > the right place. > > > > > > Paulo > > > > > > > -----Original Message----- > > > > From: > [EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> > > > > [mailto: > > > [EMAIL PROTECTED] > > > > <mailto:[EMAIL PROTECTED] > ] On > > > > Behalf Of Sverre Moe > > > > Sent: Friday, March 23, 2007 10:10 AM > > > > To: [email protected] > > > > Subject: Re: [iText-questions] Overlay a > > transparent gif on > > > > another image > > > > > > > > Whatever I do I can't seem to get it right. > > I'm now using > > > > ColumnText to add both the text, > tables and images. > > > > But I still get the previous problem when > > adding the images > > > > as absolute positions. > > > > > > > > PdfContentByte cb = writer.getDirectContent(); > > > > ColumnText ct = new ColumnText(cb); > > > > ct.setSimpleColumn (0f, 0f, > PageSize.A4.width() - 5, > > > > PageSize.A4.height () - 5, 18, > > Element.ALIGN_JUSTIFIED ); > > > > > > > > First I add some text, a table and > some text to the > > > > ct.addElement(). Then I add two images at the > > same absolute > > > > position 330 with cb.addImage() > > > > For last I add two tables with > > ct.addElement(), but these two > > > > are still aligned inside the image. > How do I get the > > > > ColumnText to insert them after the image? > > > > > > > > I have found a temporary solution to this > > problem, but it is > > > > a ugly hack, 14 document.add(Chunk.NEWLINE) > > after adding the > > > > images. I would like to find a better solution ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
