Great, it works!
Thank you very much, Paulo!
-Paul
--- Paulo Soares <[EMAIL PROTECTED]> wrote:
> Font anchorFont = new Font(5, 9);
> Chunk ck = new
> Chunk("http://www.yahoo.com",anchorFont);
> ck.setAnchor("http://www.yahoo.com");
> ref = new Paragraph("link: ");
> ref.add(ck);
>
>
> ----- Original Message -----
> From: "Paul Krasucki" <[EMAIL PROTECTED]>
> To: "Paulo Soares" <[EMAIL PROTECTED]>;
> <[email protected]>
> Sent: Sunday, January 09, 2005 1:33 PM
> Subject: Re: [iText-questions] anchor in a template
>
>
> > Thanks for your response. If the example were
> working
> > with anchors, it would solve the problem, but it
> > doesn't: the same anchor object when added
> directly to
> > the document creates a correct link, if used in
> the
> > table, it is just a plain text.
> > Here is code example (simplified
> > headers_watermarks.java, I removed image,
> watermark
> > etc to make code shorter).
> >
> > import java.io.*;
> > import com.lowagie.text.*;
> > import com.lowagie.text.pdf.*;
> >
> > public class headers_and_watermarks extends
> > PdfPageEventHelper {
> >
> > public Image headerImage;
> > public PdfPTable table;
> > public PdfTemplate tpl;
> > public BaseFont helv;
> > private static Paragraph ref;
> >
> > {
> > Anchor anchor = new
> > Anchor("http://www.yahoo.com",anchorFont);
> > Font anchorFont = new Font(5, 9);
> >
> anchor.setReference("http://www.yahoo.com");
> > anchor.setName("http://www.yahoo.com");
> > ref = new Paragraph("link: ");
> > ref.add(anchor);
> > }
> >
> > public static void main(String args[]) {
> > try {
> > Document doc = new
> Document(PageSize.A4,
> > 50, 50, 100, 72);
> > PdfWriter writer =
> > PdfWriter.getInstance(doc, new
> >
> FileOutputStream("c:\\headers_and_watermarks.pdf"));
> > PdfPageEvent pageEvent = new
> > headers_and_watermarks();
> > writer.setPageEvent(pageEvent);
> > doc.open();
> > String text = "some padding text ";
> > for (int k = 0; k < 5; ++k)
> > text += text;
> > Paragraph p = new Paragraph(text);
> >
> p.setAlignment(Element.ALIGN_JUSTIFIED);
> > doc.add(p);
> > doc.add(ref);
> > doc.close();
> > System.out.println("Finished.");
> > }
> > catch ( Exception e ) {
> > e.printStackTrace();
> > }
> > }
> >
> > public void onOpenDocument(PdfWriter writer,
> > Document document) {
> > try {
> > table = new PdfPTable(1);
> > table.addCell(ref);
> > tpl =
> > writer.getDirectContent().createTemplate(100,
> 100);
> > tpl.setBoundingBox(new Rectangle(-20,
> -20,
> > 100, 100));
> > helv =
> BaseFont.createFont("Helvetica",
> > BaseFont.WINANSI, false);
> > }
> > catch(Exception e) {
> > throw new ExceptionConverter(e);
> > }
> > }
> >
> > public void onEndPage(PdfWriter writer,
> Document
> > document) {
> > PdfContentByte cb =
> writer.getDirectContent();
> > cb.saveState();
> > table.setTotalWidth(document.right() -
> > document.left());
> > table.writeSelectedRows(0, -1,
> > document.left(), document.getPageSize().height() -
> 50,
> > cb);
> > String text = "Page " +
> writer.getPageNumber()
> > + " of ";
> > float textSize = helv.getWidthPoint(text,
> 12);
> > float textBase = document.bottom() - 20;
> > cb.beginText();
> > cb.setFontAndSize(helv, 12);
> > cb.setTextMatrix(document.left(),
> textBase);
> > cb.showText(text);
> > cb.endText();
> > cb.addTemplate(tpl, document.left() +
> > textSize, textBase);
> > }
> >
> > public void onCloseDocument(PdfWriter writer,
> > Document document) {
> > tpl.beginText();
> > tpl.setFontAndSize(helv, 12);
> > tpl.setTextMatrix(0, 0);
> > tpl.showText("" + (writer.getPageNumber() -
> > 1));
> > tpl.endText();
> > }
> > }
> >
> > --- Paulo Soares <[EMAIL PROTECTED]> wrote:
> >
> > > Have a look at the example
> > > headers_and_watermarks.java at
> > > http://itextpdf.sf.net. Use
> > > ColumnText.showTextAligned() to put the chunks.
> > > Note that if what you are doing is to just stamp
> > > something on an existing
> > > pdf you'll get better results with PdfStamper.
> > >
> > >
> > > ----- Original Message -----
> > > From: "Paul Krasucki" <[EMAIL PROTECTED]>
> > > To: "Paulo Soares" <[EMAIL PROTECTED]>;
> > > <[email protected]>
> > > Sent: Saturday, January 08, 2005 9:04 PM
> > > Subject: RE: [iText-questions] anchor in a
> template
> > >
> > >
> > > > Thanks, information helps, but problem still
> > > > unsolved... Is there any other way around it?
> > > Bottom
> > > > line is I need to create a box with some text,
> > > page
> > > > numbers, and link and put it in a predefined
> place
> > > on
> > > > the page (under the page I copied from another
> > > pdf).
> > > > Regards,
> > > > -Paul
> > > >
> > > > --- Paulo Soares <[EMAIL PROTECTED]> wrote:
> > > >
> > > > > Anchors are done with Chunk.setAnchor() but
> that
> > > > > won't help you in a
> > > > > template as the reference position would be
> > > relative
> > > > > to the template and
> > > > > not the page. Links must always be placed in
> > > > > PdfWriter.getDirectContent() or
> > > > > PdfWriter.getDirectContentUnder().
> > > > >
> > > > > > -----Original Message-----
> > > > > > From:
> > > [EMAIL PROTECTED]
> > > > > >
> > > > >
> > >
> [mailto:[EMAIL PROTECTED]
> > > > > On
> > > > > > Behalf Of Paul Krasucki
> > > > > > Sent: Saturday, January 08, 2005 1:06 PM
> > > > > > To: Paulo Soares;
> > > > > [email protected]
> > > > > > Subject: Re: [iText-questions] anchor in a
> > > > > template
> > > > > >
>
=== message truncated ===
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions