2013-03-06 61 views
0

我的問題傢伙是如何添加多行使用iText的頁腳1.5.4 我知道我的問題類似於one但這個問題直到現在還沒有回答。另外我不需要解決方案在頁腳中使用表格。如何使用iText 1.5.4添加多行的頁腳?

基本上我想達到的目標是這樣的 footer with multiple lines

+1

您是否看到OP很少進入SO,並且只有3個問題中的1個有真正的答案?你不能信任他,但也許在發佈的答案中。 – 2013-03-06 06:00:43

回答

0

我實現了我想要的佈局,類似於使用下面的代碼發佈我的問題的圖像。 我不熟悉itext,所以如果有人有這樣做的更好的方式您的意見和建議將非常感激。 謝謝!

public static void main(String[] args) throws DocumentException, IOException{ 
    Document document = new Document(PageSize.A4, 50, 50, 70, 70); 

     PdfWriter writer = PdfWriter.getInstance(document, 
       new FileOutputStream("C:/pdfwithfooter.pdf")); 
     document.open(); 

     document.add(new Paragraph(
       "Hello Body of the PDF")); 

     /** Format Font **/ 
     Font fontFooter = new Font(FontFactory.getFont(
       FontFactory.HELVETICA, 6)); 

     /** 
     * Format Table Cell Borders 
     */ 
     // cell.disableBorderSide(Rectangle.BOX); 
     Rectangle page = document.getPageSize(); 
     PdfPTable foot = new PdfPTable(4); 
     PdfPCell footCell = new PdfPCell(new Phrase(
       "OUR DOCUMENT'S LEGEND", FontFactory.getFont(
         FontFactory.HELVETICA, 6, Font.BOLDITALIC))); 
     footCell.setColspan(2); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("")); 
     footCell.setColspan(2); 
     foot.addCell(footCell); 

     // 1st row 
     footCell = new PdfPCell(new Phrase("COX - COX", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("EQ - Equipment", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("OUT-XYZ - Out XXXXXXXXXXXXX", 
       fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase(
       "ADJ-XX - Adjustment on XXXXXX XXXX", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     // 2nd row 
     footCell = new PdfPCell(new Phrase("EB - Electric Bills", 
       fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("T-BB - Transfer to Big Boat", 
       fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("T-XXXX - Transfer to XXXX", 
       fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("GX - Get XXXXXX", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     // 3rd row 
     footCell = new PdfPCell(new Phrase(
       "EXCEPTIONS - Invalid X Y VALUES", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("R XX - Removal of XX", 
       fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase("T-X - Transfer of XXXX", 
       fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase(
       "T-LX - Transfer of Leased XXXX", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     // 4th row 
     footCell = new PdfPCell(new Phrase("LX - Leased XXXX", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase(
       "T-TX - Transfer to TREE XXXXXXX", fontFooter)); 
     footCell.setPaddingLeft(15); 
     foot.addCell(footCell); 
     footCell = new PdfPCell(new Phrase(
       "Adj-XXX - Adjustment Some Value", 
       fontFooter)); 
     footCell.setPaddingLeft(15); 
     footCell.setColspan(2); 
     foot.addCell(footCell); 

     foot.setTotalWidth(page.width() - document.leftMargin() 
       - document.rightMargin()); 
     foot.writeSelectedRows(0, -1, document.leftMargin(), 
       document.bottomMargin(), writer.getDirectContent()); 

     document.close(); 

} 
2

我建議你遵循這個例子:

http://itextpdf.com/examples/iia.php?id=103

您可以到任何你想要添加的頁眉和頁腳。我過去一直在使用它,並且能夠在頁腳中放置一個表格。

在他們的示例中注意這個class HeaderFooter extends PdfPageEventHelperpublic void onEndPage(PdfWriter writer, Document document)

希望這會有所幫助!

+0

我已經閱讀了這個鏈接的例子,這就是爲什麼我在這裏問,因爲這個例子太複雜了,並沒有真正回答我的問題,我正在尋找一些非常簡單的事情來實現我已經發布的圖像佈局題。 – royjavelosa 2013-05-07 07:39:36

+0

確定這對一個頁面文檔來說很複雜,但對於更多,這是要走的路。 – 2013-05-07 22:05:42