`
penghao122
  • 浏览: 362634 次
  • 性别: Icon_minigender_1
  • 来自: 广东珠海
社区版块
存档分类
最新评论

求能够在pdf最后一页加上统计所有本页合计的数量

    博客分类:
  • java
pdf 
阅读更多

请教各们同仁.怎么能够控制到itext 生成最后一页的时候.加入一个汇总本页合计.

源码和生成的pdf在附件中.

package pdf;

import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.TreeSet;

import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfGState;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfTable;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;

public class PDFTestUtil  extends  PdfPageEventHelper {
	


    private static PdfTemplate template ; 
    private static BaseFont bfChinese;
    public static BaseFont arial;
    private static Font fontChinese;
    private static Font fontCN;
    private static PdfContentByte cb;
    private static Font normalFont = new Font(arial, 20, Font.BOLD);
    Paragraph paragraph = null;
    private int temp =0;
	/** An Image that goes in the header. */
    public Image headerImage;
    /** The headertable. */

    /** The Graphic state */
    public PdfGState gstate;
    /** A template that will hold the total number of pages. */
    public PdfTemplate tpl;
    /** The font that will be used. */
    public BaseFont helv;
    
    public static Table getEmptyTable()
    {
        Table emptyTable = null;
        try
        {       
            emptyTable = new Table(1);
            emptyTable.setWidth(100);
            emptyTable.setBorder(Rectangle.NO_BORDER);
            
            Cell c = new Cell(new Phrase("\n", normalFont));
            c.setBorder(Rectangle.NO_BORDER);
            emptyTable.addCell(c);
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }       
        return emptyTable;
    }   
    
//  Override iText's class to handle total page number.
	  /**
   * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
   */
  public void onOpenDocument(PdfWriter writer, Document document) {

          try {
              // initialization of the template
            tpl = writer.getDirectContent().createTemplate(100, 100);
            tpl.setBoundingBox(new Rectangle(-20, -20, 100, 100));
		} catch (Exception e) {
			e.printStackTrace();
		}
  }    
  
  /**
   * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
   */
  public void onEndPage(PdfWriter writer, Document document) {

      // write the headertable    
      try {
    	  
    	  temp = writer.getPageNumber();
	
    	  PdfPTable table = new PdfPTable(4);//fourth columns

          int headerwidths[] =  {40, 30, 10,20}; // percentage
          table.setWidths(headerwidths);
          table.setWidthPercentage(100);
          table.getDefaultCell().setBorder(0);
          table.getDefaultCell().setHorizontalAlignment(0);
          
          //first Row
          PdfPCell newCell = new PdfPCell();
          newCell.addElement(new Paragraph(" "));
          newCell.setBorder(Rectangle.NO_BORDER);
          table.addCell(newCell);
          
          table.getDefaultCell().setHorizontalAlignment(2);
          newCell = new PdfPCell();
  		  newCell.setBorder(Rectangle.NO_BORDER);
  		  Paragraph paragraph = new Paragraph("本页合计",fontCN);
  		  paragraph.setAlignment(Rectangle.ALIGN_CENTER);
  		  newCell.addElement(paragraph);
          table.addCell(newCell);
          
          table.getDefaultCell().setHorizontalAlignment(2);
          newCell = new PdfPCell();
  		  newCell.setBorder(Rectangle.NO_BORDER);
  		  paragraph = new Paragraph("2,771");
  		  paragraph.setAlignment("right");
  		  newCell.addElement(paragraph);
          table.addCell(newCell);
          
          newCell = new PdfPCell();
  		 newCell.setBorder(Rectangle.NO_BORDER);
 		  paragraph = new Paragraph("267,362,55");
  		  paragraph.setAlignment("right");
  		  newCell.addElement(paragraph);
          table.addCell(newCell);
       
          //2nd Row
          table.getDefaultCell().setBorder(1);
          PdfPCell second = new PdfPCell();
          second.setColspan(4);
          second.setBorder(Rectangle.BOTTOM);
          table.addCell(second);
      

      
          //fourth Row
        PdfPCell fourth = new PdfPCell();
  	    fourth.setBorder(Rectangle.NO_BORDER);
  	    fourth.addElement(new Paragraph(" "));
      	table.addCell(fourth);
      	
      	table.getDefaultCell().setHorizontalAlignment(Rectangle.RIGHT);
  		fourth.setBorder(Rectangle.NO_BORDER);
  		paragraph = new Paragraph("订购方签名及戳章:",fontCN);
  		paragraph.setAlignment(Rectangle.ALIGN_RIGHT);
  		fourth.addElement(paragraph);
  		table.addCell(fourth);
  		
          table.getDefaultCell().setBorder(1);
          fourth = new PdfPCell();
          fourth.setBorder(Rectangle.BOTTOM);
          fourth.setColspan(2);
          table.addCell(fourth);
 
      //five Row
        PdfPCell five = new PdfPCell();
        five.addElement(new Paragraph(" "));
        five.setBorder(Rectangle.NO_BORDER);
  	    table.addCell(five);
        five = new PdfPCell();
        five.setColspan(3);
  		five.setBorder(Rectangle.NO_BORDER);
  		paragraph = new Paragraph("日期             :                   年                            月                     日",fontCN);
  		paragraph.setAlignment(Rectangle.ALIGN_RIGHT);
  		five.addElement(paragraph);
  		table.addCell(five);

          document.add(table);
       
	      PdfContentByte cb = writer.getDirectContent();
	      cb.saveState();
	      
	     String text = "**注意:此报表内容含本公司机密资料,严根禁向无关人透露!**  Page " + writer.getPageNumber() + " of ";
	      float textSize = bfChinese.getWidthPoint(text, 12);
	      float textBase = document.bottom() - 20;
	      cb.beginText();
	      cb.setFontAndSize(bfChinese, 12);
	      float adjust = bfChinese.getWidthPoint("0", 12);
	      
	      cb.setTextMatrix(document.right() - textSize - adjust, textBase);
	      cb.showText(text);
	      cb.endText();
	      cb.addTemplate(tpl, document.right() - adjust, textBase);
	      cb.saveState();
	  } catch (Exception e) {

		e.printStackTrace();
	 } 

  }
  
  /**
   * @see com.lowagie.text.pdf.PdfPageEventHelper#onStartPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
   */
  public void onStartPage(PdfWriter writer, Document document) {

	   Paragraph paragraph = new Paragraph("许可经销商品合同",fontCN);
	   paragraph.setAlignment("center");
	   try {
		document.add(paragraph);
		document.add(getEmptyTable());
		document.add(createHeader(fontCN));   
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}


  }
  
  /**
   * @see com.lowagie.text.pdf.PdfPageEventHelper#onCloseDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
   */
  public void onCloseDocument(PdfWriter writer, Document document) {
	  
	 if((temp) == (writer.getPageNumber()-1)){

	 }
     tpl.beginText();
     tpl.setFontAndSize(bfChinese, 12);
     tpl.setTextMatrix(0, 0);
     tpl.showText(Integer.toString(writer.getPageNumber() - 1));
     tpl.endText();
  }




	public static void main(String[] args) throws Exception {
	
		bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
		fontCN = new com.lowagie.text.Font(bfChinese, 12,com.lowagie.text.Font.NORMAL);

		

        // step 1
		Document document =  new Document(PageSize.A4, 30, 30, 30, 100);  //定义纸张类型及方向,页边距
	    //step2    
		PdfWriter  writer = PdfWriter.getInstance(document,new FileOutputStream("Contract.pdf"));
        writer.setPageEvent(new PDFTestUtil());	
        // step3
		document.open();
	    //step 4	   

        for(int i =0 ;i<10; i++){
        	document.add(createBody(fontCN));//body
        }
        
        // step 5: we close the document (the outputstream is also closed internally)
        document.close();


	}
	public static PdfPTable createBody(Font fontCN) throws DocumentException{
	    Paragraph paragraph =null;
		PdfPTable table = new PdfPTable(4);//fourth columns
        int headerwidths[] = {20 ,50, 10,20}; // percentage
        table.setWidths(headerwidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(0);
        
        table.getDefaultCell().setHorizontalAlignment(0);
      
        PdfPTable headerTable = new PdfPTable(2);
        headerTable.setWidthPercentage(20);
        headerTable.getDefaultCell().setBorder(0);
        headerTable.getDefaultCell().setHorizontalAlignment(1);
        PdfPCell newCell = new PdfPCell();
        //first row
		newCell.setBorder(Rectangle.NO_BORDER);
		newCell.setColspan(2);
		Paragraph prargraph = new Paragraph("310094030");
		prargraph.setAlignment("center");
		newCell.addElement(prargraph);
		headerTable.getDefaultCell().setHorizontalAlignment(1);
		headerTable.addCell(newCell);
		//2nd row
		newCell = new PdfPCell();
		newCell.setBorder(Rectangle.NO_BORDER);
		newCell.setColspan(2);
		prargraph = new Paragraph("第3期",fontCN);
		prargraph.setAlignment("center");
		newCell.addElement(prargraph);
		headerTable.addCell(newCell);
		//three row
		newCell = new PdfPCell();
		newCell.setBorder(Rectangle.NO_BORDER);
		newCell.addElement(new Paragraph("进货价",fontCN));
		headerTable.addCell(newCell);
		newCell = new PdfPCell();
		newCell.setBorder(Rectangle.NO_BORDER);
		newCell.addElement(new Paragraph("零售价",fontCN));
		headerTable.addCell(newCell);
		newCell = new PdfPCell();
		//forth row
		newCell.setBorder(Rectangle.NO_BORDER);
		prargraph = new Paragraph("53.55");
		prargraph.setAlignment("left");
		newCell.addElement(prargraph);
		headerTable.addCell(newCell);
		newCell = new PdfPCell();
		newCell.setBorder(Rectangle.NO_BORDER);
		prargraph = new Paragraph("119.00");
		prargraph.setAlignment("left");
		newCell.addElement(prargraph);
		headerTable.addCell(newCell);
        table.addCell(headerTable);//first column
        
        PdfPTable sizeTable = new PdfPTable(6);
        //first row
        
        PdfPCell sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeTable.addCell(sizeCell);
        
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("-S-",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("-M-",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("-L-",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("-XL-",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("-XXL-",fontCN));
        sizeTable.addCell(sizeCell);
        //2nd row
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("01",fontCN));
        sizeTable.addCell(sizeCell);

        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("34",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("43",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("54",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("5",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeTable.addCell(sizeCell);
        //three row
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("33",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("43",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("43",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("54",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("54",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeTable.addCell(sizeCell);
        //fourth row
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("52",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("43",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("4",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("4",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("45",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeTable.addCell(sizeCell);
        //five row
        sizeTable.getDefaultCell().setBorder(1);
        sizeCell = new PdfPCell();
        sizeCell.setColspan(6);
        sizeCell.setBorder(Rectangle.BOTTOM);
        sizeTable.addCell(sizeCell);
        
        //six row
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("120",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("90",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("112",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeCell.addElement(new Paragraph("104",fontCN));
        sizeTable.addCell(sizeCell);
        sizeCell = new PdfPCell();
        sizeCell.setBorder(Rectangle.NO_BORDER);
        sizeTable.addCell(sizeCell);
        table.addCell(sizeTable);//2nd column
        
        PdfPTable numTable = new PdfPTable(1);
        numTable.setWidthPercentage(100);
        numTable.getDefaultCell().setBorder(0);
        numTable.getDefaultCell().setHorizontalAlignment(0);
        
        PdfPCell numCell = new PdfPCell();
        numCell.setBorder(Rectangle.NO_BORDER);
        numCell.addElement(new Paragraph("       "));
        numTable.addCell(numCell);
        
        numCell = new PdfPCell();
        numCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("136");
        paragraph.setAlignment("right");
        numCell.addElement(paragraph);
        numTable.addCell(numCell);
        
        numCell = new PdfPCell();
        numCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("194");
        paragraph.setAlignment("right");
        numCell.addElement(paragraph);
        numTable.addCell(numCell);
        
        numCell = new PdfPCell();
        numCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("96");
        paragraph.setAlignment("right");
        numCell.addElement(paragraph);
        numTable.addCell(numCell);
        
        numTable.getDefaultCell().setBorder(1);
        numCell = new PdfPCell();
        numCell.setColspan(1);
        numCell.setBorder(Rectangle.BOTTOM);
        numTable.addCell(numCell);
        numTable.getDefaultCell().setHorizontalAlignment(2);
        numCell = new PdfPCell();
        numCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("426");
        paragraph.setAlignment("right");
        numCell.addElement(paragraph);
        numTable.addCell(numCell);
        table.addCell(numTable);//three column
        
        PdfPTable orderTable = new PdfPTable(1);
        orderTable.setWidthPercentage(100);
        orderTable.getDefaultCell().setBorder(0);
        orderTable.getDefaultCell().setHorizontalAlignment(2);
        PdfPCell orderCell = new PdfPCell();
        orderCell.addElement(new Paragraph("    "));
        orderCell.setBorder(Rectangle.NO_BORDER);
        orderTable.addCell(orderCell);

        
        orderCell = new PdfPCell();
        orderCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("7.282.80");
        paragraph.setAlignment("right");
        orderCell.addElement(paragraph);
        orderTable.addCell(orderCell);
        
        orderCell = new PdfPCell();
        orderCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("10.388.70");
        paragraph.setAlignment("right");
        orderCell.addElement(paragraph);

        orderTable.addCell(orderCell);
        
        orderCell = new PdfPCell();
        orderCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("5.140.80");
        paragraph.setAlignment("right");
        orderCell.addElement(paragraph);

        orderTable.addCell(orderCell);
        
        orderTable.getDefaultCell().setBorder(1);
        orderCell = new PdfPCell();
        orderCell.setColspan(1);
        orderCell.setBorder(Rectangle.BOTTOM);
        orderTable.addCell(orderCell);
        
        orderCell = new PdfPCell();
        orderCell.setBorder(Rectangle.NO_BORDER);
        paragraph = new Paragraph("22.812.30");
        paragraph.setAlignment("right");
        orderCell.addElement(paragraph);
        orderTable.addCell(orderCell);
        table.addCell(orderTable);//fourth column
		return table;
	}
	

	
    private   PdfPTable createHeader(Font fontCN ) throws Exception{

		
    	PdfPTable table = new PdfPTable(1);
   	   table.setWidthPercentage(100);
   	   table.setSpacingBefore(3f);  //设置标题和第一个表格间的距离.不然会粘在一起
   	   table.getDefaultCell().setBorder(0);
   	   
          //frist row
          PdfPTable headerTable = new PdfPTable(4);
          int headerwidths[] = {20, 30, 30,20}; // percentage
          headerTable.setWidths(headerwidths);
          headerTable.setWidthPercentage(100);
          headerTable.setSpacingBefore(3f);  //设置标题和第一个表格间的距离.不然会粘在一起
          headerTable.getDefaultCell().setBorder(0);
          headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	   	   PdfPCell cell = new PdfPCell();
	   	   paragraph =new Paragraph("订单地区: 厦门",fontCN);
	   	   paragraph.setAlignment("left");
	   	   cell.addElement(paragraph);
	   	   cell.setBorder(Rectangle.NO_BORDER);
   	     headerTable.addCell(cell);
   	   
   	   headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
   	   cell = new PdfPCell();
   	   paragraph =new Paragraph("出货店号: 169",fontCN);
   	   paragraph.setAlignment("left");
   	   cell.addElement(paragraph);
   	   cell.setBorder(Rectangle.NO_BORDER);
   	   headerTable.addCell(cell);
   	   
   	   headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
   	   cell = new PdfPCell();
   	   paragraph =new Paragraph("订货店号:207,209,211,219,261,275,276,277,281,408",fontCN);
   	   paragraph.setAlignment("right");
   	   cell.addElement(paragraph);
   	   cell.setColspan(2);
   	   cell.setBorder(Rectangle.NO_BORDER);
   	   headerTable.addCell(cell);
   	   table.addCell(headerTable);
   	   //2nd row
   		   
       table.getDefaultCell().setBorder(1);
       PdfPCell newCell = new PdfPCell();
       newCell.setBorder(Rectangle.BOTTOM);
       newCell.setColspan(4);
       table.addCell(newCell);
     
        //three row
        PdfPTable newTable = new PdfPTable(4);
   	    float widths[] = {20, 50, 10,20}; // percentage
   	    //newTable.setWidths();
   	    newTable.setTotalWidth(widths);
   	    newTable.setWidthPercentage(100);
   	    newTable.setSpacingBefore(3f);  //设置标题和第一个表格间的距离.不然会粘在一起
   	    newTable.getDefaultCell().setBorder(0);
   	    
   	    newTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
   		newCell = new PdfPCell();
   		newCell.setBorder(Rectangle.NO_BORDER);
    	paragraph =new Paragraph("款号",fontCN);
       	paragraph.setAlignment("left");
       	newCell.addElement(paragraph);
   		newTable.addCell(newCell);
   		
   		newCell = new PdfPCell();
   		newCell.setBorder(Rectangle.NO_BORDER);
    	paragraph =new Paragraph("颜色",fontCN);
       	paragraph.setAlignment("left");
       	newCell.addElement(paragraph);
   		newTable.addCell(newCell);
   		
   		newTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
   		newCell = new PdfPCell();
   		newCell.setBorder(Rectangle.NO_BORDER);
   		paragraph =new Paragraph("数量总数",fontCN);
   		paragraph.setAlignment("right");
   		newCell.addElement(paragraph);
   		newTable.addCell(newCell);
   		
   		newCell = new PdfPCell();
   		newCell.setBorder(Rectangle.NO_BORDER);
   		paragraph =new Paragraph("订单总金额",fontCN);
   		paragraph.setAlignment("right");
   		newCell.addElement(paragraph);
   		newTable.addCell(newCell);
   		table.addCell(newTable);
   		//forth row
        table.getDefaultCell().setBorder(1);
        newCell = new PdfPCell();
        newCell.setBorder(Rectangle.BOTTOM);
        newCell.setColspan(4);
        table.addCell(newCell);
    
		return table;
}
    

}
  • pdf.rar (8.9 KB)
  • 下载次数: 51
分享到:
评论

相关推荐

    批量提取PDF第一页工具、批量统计PDF页数

    本话题将深入探讨如何批量提取PDF的第一页以及如何批量统计PDF的页数。 批量提取PDF第一页是一项常见的需求,特别是在需要整理或归档PDF文档时。这通常通过编程脚本或特定的软件工具实现。工具能够自动遍历指定目录...

    PDF页面合并器 - 合并多页PDF成一页

    PDF页面合并器是一款Windows系统下的PDF多页面合并成一页的工具软件,它可将2个或多个PDF页面合并在一页PDF页面上。 它允许您在合并页面上设置页面数量,因此您可以将每2、4或更多页面合并成一页。 这个出色的实用...

    快速批量统计PDF页数

    在IT行业中,PDF(Portable Document Format)是一种广泛使用的文件格式,它能保持文档的原始布局和格式,方便阅读和分享。然而,对于大量PDF文件,手动统计每份文档的页数是一项耗时的工作。"快速批量统计PDF页数...

    批量删除PDF指定页面

    6. **保存新PDF**:最后,软件将重构后的PDF保存为一个新的文件,这个新文件就是没有指定页面的PDF。 在这个过程中,软件可能会使用一些开源库,如PyPDF2(Python语言)或iText(Java语言),它们提供了处理PDF文档...

    贝叶斯统计推断 PDF

    它在数学上表述为:后验概率(在给定新证据后某一假设的概率)等于先验概率(在考虑新证据前的假设概率)乘以似然函数(新证据出现的概率),再除以边缘概率(所有可能假设下出现该新证据的概率)。贝叶斯统计推断...

    pdf与文本文档字数统计

    在IT行业中,字数统计是一项基础但至关重要的任务,尤其对于文档处理和内容分析而言。本文将详细探讨如何对PDF和文本文档进行字数、单词及符号统计,并提供相关工具和技术的介绍。 首先,我们要了解PDF(Portable ...

    Spire.Pdf 去水印+超10页+用例,Spire.Pdf.dll、Spire.License.dll。

    Spire.Pdf是一款由E-iceblue公司开发的.NET PDF处理库,专为.NET开发者设计,用于创建、编辑、阅读和转换PDF文档。在提供的压缩包中,我们有两个关键的DLL文件:`Spire.Pdf.dll`和`Spire.License.dll`,以及一个示例...

    概率论与数理统计(浙江大学第四版)教程和答案pdf版本-带目录

    《概率论与数理统计》是数学领域的重要分支,它在科研、工程、经济和许多其他领域都有着广泛的应用。浙江大学出版的第四版教程是该学科的经典教材之一,为学生提供了全面而深入的学习材料。这份资源包含了教程正文和...

    在页脚显示PDF的总页数

    本篇文章将深入探讨如何在PDF中实现这一功能,主要使用iText库,这是一个强大的Java和.NET PDF处理库。 首先,我们需要了解iText库的基本概念。iText是一个开源项目,它提供了创建、修改和操作PDF文档的能力。通过...

    spire.pdf 5.12.15 去水印可超10页

    在版本5.12.15中,它引入了一个重要的功能更新,即“去水印可超10页”,这为用户提供了更强大的PDF文档编辑能力。 在PDF文档中,水印通常被用来标识文档的所有权或敏感性,但有时可能需要移除这些水印以方便使用或...

    Minitab-培训教程大全-568页.pdf

    Minitab是一款广泛使用的统计分析软件,因其用户友好和功能全面而备受青睐,尤其在质量管理领域中应用广泛。Minitab不仅提供了基础的统计计算和数据分析,还支持复杂的图形绘制,是实施六西格玛(6 Sigma)质量管理...

    统计陷阱 How to Lie With Statistics 中文版 清晰 PDF

    - **统计学的应用与滥用**:哈夫通过一系列实际案例揭示了如何利用统计手段来误导公众,强调正确的统计方法在决策过程中的重要性。 - **关键概念解析**:书中详细解释了诸如“平均数”、“中位数”、“众数”等基本...

    茆诗松 概率论与数理统计

    《茆诗松的概率论与数理统计》是一本系统介绍概率论与数理统计基本理论与方法的专业教材,由高等教育出版社出版。本书第二版在第一版的基础上进行了修订和补充,使之更适合教学和自学。书中内容涵盖了概率论与数理...

    李政道的统计力学(北师大出版社)

    在这个基础上,进一步假设系统在所有可能的本征态上的概率是相等的,这是统计力学平衡态的唯一基本假设,这个假设同样适用于其他统计问题,如掷骰子游戏。 书中还讨论了正则系综的概念,正则系综是由大量相同的粒子...

    金融数量分析:基于MATLAB编程.pdf

    MATLAB(Matrix Laboratory的缩写),作为一款强大的数学计算软件,它拥有广泛的数学函数库,以及丰富的算法工具箱,能够有效地支持金融数量分析的各种计算需求。 本书《金融数量分析:基于MATLAB编程》共分为六章...

    免费PDF控件Spire.PDF

    它能够使用户在不用Adobe Acrobat和其他外部控件的情况下,运用.NET 应用程序阅读,编写和操纵PDF 文档。Spire.PDF for .NET不仅可以运用在服端比如:ASP.NET 或者其他环境,还可以应用在Windows Forms 应用程序中。...

    Pdfium实现PDF转JPG

    Pdfium是一种开源的PDF阅读器库,源自Google的Chromium项目,用于在各种应用程序中查看PDF文档。在Delphi开发环境中,Pdfium可以被利用来实现PDF文档转换为图像的功能,比如将PDF转换为JPG格式。这个项目是针对...

    概率论与数理统计(浙大四版).pdf

    概率论与数理统计(浙大四版)

    环境与生态统计 R语言的应用.pdf

    生态类书籍,仅供学习参考

Global site tag (gtag.js) - Google Analytics