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
> > > >
> > > > Thanks for the answer - here is clarification:
> > > > I have PdfTemplate object which I add to some
> > > pages in
> > > > onEndPage(...) method. I would like to have
> there
> > > a
> > > > fixed link like http:\\somewebsite. I cannot
> add
> > > > Anchor directly and I don't see how I could
> wrap
> > > an
> > > > Anchor object into some element that I could
> add
> > > to
> > > > the template...
> > > > Thanks,
> > > > -Paul
> > > >
> > > > --- Paulo Soares <[EMAIL PROTECTED]> wrote:
> > > >
> > > > > Links are always relative to the page so,
> > > depending
> > > > > on what you call
> > > > > 'template' it may or may not be doable.
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Paul Krasucki"
> <[EMAIL PROTECTED]>
> > > > > To: <[email protected]>
> > > > > Sent: Saturday, January 08, 2005 2:24 AM
> > > > > Subject: [iText-questions] anchor in a
> template
> > > > >
> > > > >
> > > > > > I need to add an anchor (external link) to
> a
> > > > > template
> > > > > > and I could not find it in any of the
> > > examples.
> > > > > Help
> > > > > > will be greatly appreciated.
> > > > > > Thanks,
> > > > > > -Paul
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > __________________________________
> > > > > > Do you Yahoo!?
> > > > > > The all-new My Yahoo! - What will yours
> do?
> > > > > > 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
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > Take Yahoo! Mail with you! Get it on your
> mobile
> > > phone.
> > > > http://mobile.yahoo.com/maildemo
> > > >
> > > >
> > > >
> > >
> >
>
-------------------------------------------------------
> > > > 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
> > > >
> > >
> >
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > The all-new My Yahoo! - What will yours do?
> > 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
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
-------------------------------------------------------
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