web-inf.xml
<servlet>
<servlet-name>pdfcreator</servlet-name>
<servlet-class>mypackage1.Class2</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>pdfcreator</servlet-name>
<url-pattern>abctest</url-pattern>
</servlet-mapping>

Class2.java
package mypackage1;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;

public class Class2 extends PdfPageEventHelper {

    public static void main(String[] args)
    {
        Document document = new Document(PageSize.A4, 50, 50, 70, 70);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("c:\\endpage.pdf"));
            writer.setPageEvent(new Class2());
            document.open();
            String text = "Lots of text. ";
            for (int k = 0; k < 10; ++k)
                text += text;
            document.add(new Paragraph(text));
            document.close();
        }
        catch (Exception de) {
            de.printStackTrace();
        }
    }

    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(100); //head.setTotalWidth(page.getWidth() -
document.leftMargin() - document.rightMargin());
            head.writeSelectedRows(0, -1, document.leftMargin(), 500 -
document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
            PdfPTable foot = new PdfPTable(3);
            for (int k = 1; k <= 6; ++k)
                foot.addCell("foot " + k); 
            foot.setTotalWidth(500 - document.leftMargin() -
document.rightMargin());
            foot.writeSelectedRows(0, -1, document.leftMargin(),
document.bottomMargin(),
                writer.getDirectContent());
        }
        catch (Exception e) {
        e.printStackTrace();
            throw new ExceptionConverter(e);
        }
    }

}
-- 
View this message in context: 
http://www.nabble.com/HTTP-500-Internal-Server-Error-tp15195202p15195202.html
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to