使用pdx的页眉和页脚使用itextsharp但页脚覆盖文档

时间:2014-01-21 09:56:05

标签: java itextsharp

    /**
     * Adds the header and the footer.
     * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
     *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
     */
    public void onEndPage(PdfWriter writer, Document document) {
        //Rectangle rect = writer.getBoxSize("art");
        CalibrateItLogger.publish("Page Number :"+writer.getPageNumber());
        PdfPTable footterPdfPTable = new PdfPTable(1);
        PdfPTable fotterLeftPdfPTable =new PdfPTable(1);
        PdfPTable fotterRightPdfPTable =new PdfPTable(1);

         //document.newPage();
         document.add(Chunk.NEWLINE); 


            footterPdfPTable =  new PdfPTable(3);
            footterPdfPTable.setWidthPercentage(100);

            fotterLeftPdfPTable = new PdfPTable(1);
            fotterLeftPdfPTable.setWidthPercentage(100);

            PdfPCell planBExtendedPdfPCell = new PdfPCell();
            planBExtendedPdfPCell.addElement(new Paragraph("PLAN B EXTENDED"));
            planBExtendedPdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterLeftPdfPTable.addCell(planBExtendedPdfPCell);

            //Calibration Company Name
            PdfPCell comapnyNameLablePdfPCell=new PdfPCell (new Paragraph (companyname(),font4));
            comapnyNameLablePdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterLeftPdfPTable.addCell(comapnyNameLablePdfPCell);

            //Address
            PdfPCell addressPdfPCell=new PdfPCell (new Paragraph ("Address data",font3));
            addressPdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterLeftPdfPTable.addCell(addressPdfPCell);

            //Zipcode
            PdfPCell zipPdfPCell=new PdfPCell (new Paragraph ("Postal code",font3));
            zipPdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterLeftPdfPTable.addCell(zipPdfPCell);

            //Certificate and Serial Number
            PdfPCell cityStateAndZipPdfPCell=new PdfPCell (new Paragraph ("Serial No ",font3));
            cityStateAndZipPdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterLeftPdfPTable.addCell(cityStateAndZipPdfPCell);

            //Model Name and Asset No
            PdfPCell pipetteModelNamePdfPCell=new PdfPCell (new Paragraph ("Asset No",font3));
            pipetteModelNamePdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterLeftPdfPTable.addCell(pipetteModelNamePdfPCell);

            PdfPCell footerLeftPdfPCell = new PdfPCell(fotterLeftPdfPTable); 
            footerLeftPdfPCell.setBorder(Rectangle.NO_BORDER);
            footterPdfPTable.addCell(footerLeftPdfPCell);

            PdfPCell emptyPdfPCell = getEmptyPdfPCell();
            emptyPdfPCell.addElement(getEmptyParagraph());

            PdfPTable pageNumberPdfPTable = new PdfPTable(1);
            pageNumberPdfPTable.addCell(emptyPdfPCell);
            pageNumberPdfPTable.addCell(emptyPdfPCell);
            pageNumberPdfPTable.addCell(emptyPdfPCell);
            pageNumberPdfPTable.addCell(emptyPdfPCell);
            pageNumberPdfPTable.addCell(emptyPdfPCell);

            Paragraph pageNumberParagraph = new Paragraph("Page "+pagenumber,font3);
            pageNumberParagraph.setAlignment(Element.ALIGN_CENTER);
            //pageNumberPdfPTable.addCell(pageNumberParagraph);

            PdfPCell pegeNumberPdfPCell = new PdfPCell(pageNumberParagraph);
            pegeNumberPdfPCell.setBorder(Rectangle.NO_BORDER);

            footterPdfPTable.addCell(pegeNumberPdfPCell);

            fotterRightPdfPTable = new PdfPTable(2);
            fotterRightPdfPTable.setWidthPercentage(100);

            //Date 
            Paragraph dateParagraph = new Paragraph(new Phrase("Date :"+CurrentDate.getDateFormat(Date,"dd/MM/yyyy"),font3));
            dateParagraph.setAlignment(Element.ALIGN_LEFT);
            PdfPCell datePdfPCell = new PdfPCell(dateParagraph);
            datePdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterRightPdfPTable.addCell(datePdfPCell);

            //Next Due Data
            Paragraph nextDueParagraph = new Paragraph(new Phrase("Next Due :"+CurrentDate.getDateFormat(Date,"dd/MM/yyyy"),font3));
            dateParagraph.setAlignment(Element.ALIGN_LEFT);
            PdfPCell nextDuePdfPCell = new PdfPCell(nextDueParagraph);
            nextDuePdfPCell.setBorder(Rectangle.NO_BORDER);
            fotterRightPdfPTable.addCell(nextDuePdfPCell);

            fotterRightPdfPTable.addCell(getEmptyPdfPCell());
            fotterRightPdfPTable.addCell(getEmptyPdfPCell());
            fotterRightPdfPTable.addCell(getEmptyPdfPCell());
            fotterRightPdfPTable.addCell(getEmptyPdfPCell());

            emptyPdfPCell = getEmptyPdfPCell();
            emptyPdfPCell.setColspan(2);
            fotterRightPdfPTable.addCell(emptyPdfPCell);

            PdfPCell underlinePdfPCell = new PdfPCell(new Phrase(new Chunk("Sign :").setUnderline(+1f, -2f)));
            underlinePdfPCell.setBorder(Rectangle.NO_BORDER);
            underlinePdfPCell.setColspan(2);
            fotterRightPdfPTable.addCell(underlinePdfPCell);

            Paragraph employeeParagraph = new Paragraph("Govardhan Rao",font3);
            employeeParagraph .setAlignment(Element.ALIGN_CENTER);
            PdfPCell employeePdfPCell = new PdfPCell(employeePdfPCell );
            employeePdfPCell .setBorder(Rectangle.NO_BORDER);
            calibrationEmployeePdfPCell.setColspan(2);
            fotterRightPdfPTable.addCell(employeePdfPCell );


            PdfPCell footerRightPdfPCell = new PdfPCell(fotterRightPdfPTable);
            footerRightPdfPCell.setBorder(Rectangle.NO_BORDER);

            footterPdfPTable.addCell(footerRightPdfPCell);




        //footterPdfPTable.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
        document.add(footterPdfPTable);

0 个答案:

没有答案
相关问题