Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
-none-

-none-

2007-10-03       - By John Zeitler

 Back

Right, I'm a complete and total idiot.  I figured out the problem...  my
margins were set to 0!  The header and footer were printing to the document,
all right, but were rendering OUTSIDE of the page's bounds.  Therefore it
looked like nothing was happening.  Sorry to waste your time.

Incidentally, is this information made clearer in the book rather than the
tutorials?  The API documentation at http://itext.ugent.be/library/api/ is
sketchy at best and misleading at worst (it still has the HeaderFooter
functionality as non-deprecated, which has been decried as 'old' here).


John Zeitler wrote:
>
> As I'd said, it's a direct copy/paste from the linked tutorial.  I'll
> reproduce it here anyway:
>
>     /**
>      * @(protected)
> com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf
.PdfWriter,
> com.lowagie.text.Document)
>      */
>     public void onEndPage(PdfWriter writer, Document document) {
>         try {
>             Rectangle page = document.getPageSize();
>             PdfPTable head = new PdfPTable(3);
>             for (int k = 1; k <= 6; ++k)
>                 head.addCell("head " + k);
>             head.setTotalWidth(page.getWidth() - document.leftMargin() -
> document.rightMargin());
>             head.writeSelectedRows(0, -1, document.leftMargin(),
> page.getHeight() - document.topMargin() + head.getTotalHeight(),
>                 writer.getDirectContent());
>             PdfPTable foot = new PdfPTable(3);
>             for (int k = 1; k <= 6; ++k)
>                 foot.addCell("foot " + k);
>             foot.setTotalWidth(page.getWidth() - document.leftMargin() -
> document.rightMargin());
>             foot.writeSelectedRows(0, -1, document.leftMargin(),
> document.bottomMargin(),
>                 writer.getDirectContent());
>         }
>         catch (Exception e) {
>             throw new ExceptionConverter(e);
>         }
>     }
>
>
> Paulo Soares wrote:
>>
>> Where's the onEndPage method code?
>>
>> Paulo
>>
>> -- -- Original Message -- --
>> From: "John Zeitler" <john.s.zeitler@(protected)>
>> To: <itext-questions@(protected)>
>> Sent: Tuesday, October 02, 2007 7:33 PM
>> Subject: [iText-questions] Questions On Headers/Footers with PageEvents
>>
>>
>>>
>>> Hi,
>>>
>>> I've run into a bit of trouble with headers and footers.  I started off
>>> using setHeader(HeaderFooter), then saw that that was apparently 'old
>>> functionality' and that I should be using page events.  So, I created a
>>> bare-bones event class based explicitly on the example from EndPage.java
>>> in
>>> the iText tutorial (here:
>>> http://itextdocs.lowagie.com/tutorial/directcontent/pageevents/index.html  
>>> ).
>>> I literally just copied the onEndPage method from that one and put it
>>> into
>>> my new class; it's the only method in the class.  My problem is that the
>>> event is being called and handled by the class, but no output is being
>>> written by that method (the rest of the output is OK).  Here's what I'm
>>> doing (abstracting out unimportant stuff):
>>> Java code-ish:
>>> /* assuming OutputStream out is passed in to this, the document
>>> generator;
>>> * out is the OutputStream from the HttpServletResponse */
>>>
>>> Document document = new Document([page size], [margins all set to 0]);
>>> PdfWriter writer = PdfWriter.getInstance(document, out);
>>> writer.setPageEvent(new myPageEventHandler()); //this has the onEndPage
>>> from
>>> EndPage.java
>>> document.open();
>>>
>>> /* from here is contained in a bean which renders its data as a table;
>>> document is passed in */
>>>
>>> document.newPage();
>>>
>>> Phrase titleText = new Phrase("This is a bold title that is NOT to be a
>>> header");
>>> document.add(titleText);
>>>
>>> PdfPTable table = new PdfPTable(3);
>>> table.setTotalWidth([page size.width * a margin ratio]);
>>> table.setLockedWidth(true);
>>>
>>> PdfPCell cell = null;
>>> /* assume that this could be hundreds or thousands of rows long */
>>> for(int i = 0; i<9999; i++) {
>>> cell = new PdfPCell(new Phrase("celldata " + i));
>>> /* cell modifications, like border width, rowspan, etc. */
>>> table.addCell(cell);
>>> }
>>>
>>> document.add(table);
>>>
>>> /* now this is performed by the class which calls the bean's method
>>> (above)
>>> */
>>>
>>> if(document != null) document.close();
>>> if(out != null) out.close();
>>>
>>> //end Java code
>>>
>>> I suspect there's something going on with the mixing of the
>>> writeSelectedRows in the onEndPage method; if I replace that line with
>>> document.add(head) etc. I can write to the page, but the problem is that
>>> those don't show up on the first page, just the second page and
>>> thereafter.
>>> More to the point, just using document.add doesn't allow me to set the
>>> positioning of the headers and footers.  As a final bit of information,
>>> I'm
>>> using iText 2.0.5 after upgrading from 1.1.4; I've quashed all other
>>> bugs,
>>> but this one is the last one (headers and footers didn't work for me in
>>> the
>>> old version either).  This is driving me crazy and I'm looking for any
>>> help
>>> or advice that can be offered.  Thanks!
>>>
>>> John Z.
>>
>>
>> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
>> This SF.net email is sponsored by: Microsoft
>> Defy all challenges. Microsoft(R) Visual Studio 2005.
>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>> __ ____ ____ ____ ____ ____ ____ ____ ____ ____
>> iText-questions mailing list
>> iText-questions@(protected)
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>> Buy the iText book: http://itext.ugent.be/itext-in-action/
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Questions-On-Headers
-Footers-with-PageEvents-tf4556782.html#a13018153
Sent from the iText - General mailing list archive at Nabble.com.


-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
__ ____ ____ ____ ____ ____ ____ ____ ____ ____
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

©2008 junlu.com - Jax Systems, LLC, U.S.A.