> -----Original Message-----
> From: Ligius Astratinei [SMTP:[EMAIL PROTECTED]
> Sent: Friday, July 04, 2003 15:51
> To:   [EMAIL PROTECTED]
> Subject:      [iText-questions] PdfGraphics2D and PDFContentByte problem
> 
> Hello,
> I'm trying to define an URL action for a PDF document but it doesn't seem
> to work.
>  
> Here are some code excerpts:
> PdfWriter writer = (PdfWriter)gc.getWorkingObject();
> 
> PdfContentByte cb = writer.getDirectContent();
> 
> PdfTemplate tp = cb.createTemplate(pageWidth, pageHeight);
> 
> Graphics2D g2 = tp.createGraphics(width, height, defaultFontMapper);
> 
> ...do graphics stuff on g2...
> 
> cb.addTemplate(tp, 0, 0);
> 
> g2.dispose();
> 
        You don't need a template. Do it this way:

        PdfWriter writer = (PdfWriter)gc.getWorkingObject();
        PdfContentByte cb = writer.getDirectContent();
        cb.saveState();
        Graphics2D g2 = cb.createGraphics(width, height, defaultFontMapper);

        ...do graphics stuff on g2...

        g2.dispose();
        cb.restoreState();


>  
> 
> The PDF is rendered correctly. However, these actions are also executed
> (after doing graphics stuff, on each page):
> 
> Rectangle r = o.objectRect;
> 
> cb.setAction(new PdfAction(linkURL), r.x, r.y ,r.x + r.width, r.y +
> r.height);
> 
> cb.circle(r.x, r.y, r.width);
> 
        You need a cb.stroke() or a cb.fill() to paint something.

> This should generate links for some objects, but it does nothing. Also,
> the 'circle' line does not output a circle as expected. I removed almost
> all the graphic painting code but the circle or any other object created
> through PDFContentByte does not display. It seems strange however that the
> linkUrl text appears in the PDF file source.
> 
        Are you sure the link is not there? Links are invisible until you
pass the cursor over it. After the circle is created you'll find the link
(the link was always there).

> The link code worked when everything was painted using only contentByte.
> If you have any ideas please give me a hint.
> 
> I am suspecting that you cannot modify both PDFContentByte and its
> Graphics at the same time, but probably I'm wrong.
> 
        You can, if using a template, but you shouldn't. You have enough
problems creating PDF without having to worry with what writes first and so
on.

        Best Regards,
        Paulo Soares
>  
> 
> With thanks,
> 
> Ligius
> 


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to