`
Donald_Draper
  • 浏览: 972229 次
社区版块
存档分类
最新评论

iText,PDF,Checkbox工具类升级版

 
阅读更多
1.cell事件类
package event;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.ExceptionConverter;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPCellEvent;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.RadioCheckField;
/**
 * PCell Event
 * @author donald
 *
 */
public class CheckboxCellEvent implements PdfPCellEvent{
	 // The name of the check box field
    protected String name;
    protected boolean flag ;
    private Integer hookSize = 5;
    private Integer edgeSize = 10;
    // We create a cell event
    public CheckboxCellEvent(String name, boolean flag) {
        this.name = name;
        this.flag = flag;
    }
    public CheckboxCellEvent(String name, boolean flag , Integer hookSize, Integer edgeSize ) {
        this.name = name;
        this.flag = flag;
        this.hookSize = hookSize;
        this.edgeSize = edgeSize;
    }
    // We create and add the check box field
    public void cellLayout(PdfPCell cell, Rectangle position,
        PdfContentByte[] canvases) {
        PdfWriter writer = canvases[0].getPdfWriter(); 
        // define the coordinates of the middle
        float x = (position.getLeft() + position.getRight()) / 2;
        float y = (position.getTop() + position.getBottom()) / 2;
        // define the position of a check box that measures 20 by 20
        //画勾
        Rectangle rect = new Rectangle(x - hookSize, y - hookSize, x + hookSize, y + hookSize);
        RadioCheckField checkbox = new RadioCheckField(writer, rect, name, "On");
        checkbox.setCheckType(RadioCheckField.TYPE_CHECK);
        
        if(flag){
        	//设置为选中状态
        	checkbox.setChecked(true);
        }
        else{
        	checkbox.setChecked(false);
        }
        //画框
        PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
        canvas.setColorStroke(BaseColor.BLACK);
        canvas.setLineDash(1f);
        canvas.rectangle(x - edgeSize, y - edgeSize, edgeSize+edgeSize,edgeSize+edgeSize);
        canvas.stroke();
       
        try {
            writer.addAnnotation(checkbox.getCheckField());
        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    }
}

2.工具类:
package util;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;

import event.CheckboxCellEvent;

/**
 * checkbox tools
 * @author donald
 *
 */
public class PdfPTableUtils {
	private static volatile PdfPTableUtils instance = null;
	public  static synchronized  PdfPTableUtils getInstance(){
		if(null==instance){
			instance = new PdfPTableUtils();
		}
		return instance;
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @return
	 */
	public  PdfPCell getCheckTable(Font font,int[] columnwidth, String[] checkValues, List<Boolean> checkeds, Integer hookSize, Integer edgeSize){
		return getCheckTable(font,columnwidth, null, null, checkValues, checkeds,true, hookSize,  edgeSize);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @return
	 */
	public  PdfPCell getCheckTable(Font font,int[] columnwidth, String[] checkValues, List<Boolean> checkeds,Boolean isBorder, Integer hookSize, Integer edgeSize){
		return getCheckTable(font,columnwidth, null, null, checkValues, checkeds,isBorder, hookSize,  edgeSize);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽
	 * @param minColumnHeight 列最小高度
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @return
	 */
	public  PdfPCell getCheckTable(Font font,int[] columnwidth, Integer minColumnHeight, String[] checkValues, List<Boolean> checkeds,Boolean isBorder){
		return getCheckTable(font,columnwidth, minColumnHeight, null, checkValues, checkeds, isBorder, null, null);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽
	 * @param minColumnHeight 列最小高度
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @return
	 */
	public  PdfPCell getCheckTable(Font font,int[] columnwidth, Integer minColumnHeight, String[] checkValues, List<Boolean> checkeds,Boolean isBorder,Integer hookSize, Integer edgeSize){
		return getCheckTable(font,columnwidth, minColumnHeight, null, checkValues, checkeds, isBorder, hookSize, edgeSize);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽
	 * @param minColumnHeight 列最小高度
	 * @param title 标题
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @return
	 */
	public  PdfPCell getCheckTable(Font font,int[] columnwidth, Integer minColumnHeight, String title, String[] checkValues, List<Boolean> checkeds,Boolean isBorder){
		return getCheckTable(font,columnwidth, minColumnHeight, title, checkValues, checkeds, isBorder, null, null);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and checkbox size
	 * @param minColumnHeight 列最小高度
	 * @param title 标题
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @return
	 */

	public  PdfPCell getCheckTable(Font font,int[] columnwidth, Integer minColumnHeight, String title, String[] checkValues, List<Boolean> checkeds,Boolean isBorder, Integer hookSize, Integer edgeSize){
		PdfPCell checkCell =null;
		PdfPTable table = new PdfPTable(columnwidth.length);
        try {
        	table.setWidths(columnwidth);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
        if(!isBorder){
        	 table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        }
        //设置标题
		if(!StringUtils.isBlank(title)){
			  PdfPCell head = new PdfPCell(new Phrase(title,font));
		        head.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		        head.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
		        if(!isBorder){
		        	 head.setBorder(PdfPCell.NO_BORDER);
		        }
		        if(null != minColumnHeight){
		        	head.setMinimumHeight(minColumnHeight);
		        }
		        table.addCell(head);
		}
		//checkBox
		 int i=0;
		 for(String checkValue: checkValues){
		      //checkBox
		      PdfPCell checkBox = new PdfPCell();
		      if(null != hookSize && null != edgeSize){
		    	  checkBox.setCellEvent(new CheckboxCellEvent(checkValue, checkeds.get(i) , hookSize, edgeSize));
		      }
		      else{
		    	  checkBox.setCellEvent(new CheckboxCellEvent(checkValue, checkeds.get(i)));
		      }
		      checkBox.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		      checkBox.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
		      if(!isBorder){
		    	  checkBox.setBorder(PdfPCell.NO_BORDER);
		        }
		      if(null != minColumnHeight){
		    	  checkBox.setMinimumHeight(minColumnHeight);
		        }
			  table.addCell(checkBox);
			  //checkBox Describle
			  PdfPCell checkDescr = new PdfPCell(new Phrase(checkValue,font));
			  checkDescr.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			  checkDescr.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
			  if(!isBorder){
				  checkDescr.setBorder(PdfPCell.NO_BORDER);
		      }
			  if(null != minColumnHeight){
				  checkDescr.setMinimumHeight(minColumnHeight);
		      }
			  table.addCell(checkDescr);
			  i++;
		 }
		 checkCell = new PdfPCell(table);
		 return checkCell;
				  
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and checkbox values size
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCheckCell(Font font,int[] columnwidth, String[] checkValues, List<Boolean> checkeds, Integer hookSize, Integer edgeSize, List<String> cellDescr, List<String> cellValue){
		return getCheckCell( font,columnwidth,  null, null, checkValues,  checkeds, true, hookSize, edgeSize, cellDescr, cellValue);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and checkbox values size
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCheckCell(Font font,int[] columnwidth, String[] checkValues, List<Boolean> checkeds,Boolean isBorder, Integer hookSize, Integer edgeSize, List<String> cellDescr, List<String> cellValue){
		return getCheckCell( font,columnwidth,  null, null, checkValues,  checkeds, isBorder, hookSize, edgeSize, cellDescr, cellValue);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and checkbox values size
	 * @param minColumnHeight 列最小高度
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCheckCell(Font font,int[] columnwidth, Integer minColumnHeight, String[] checkValues, List<Boolean> checkeds,Boolean isBorder, List<String> cellDescr, List<String> cellValue){
		return getCheckCell( font,columnwidth,  minColumnHeight, null, checkValues,  checkeds, isBorder, null, null, cellDescr, cellValue);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and checkbox values size
	 * @param minColumnHeight 列最小高度
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCheckCell(Font font,int[] columnwidth, Integer minColumnHeight, String[] checkValues, List<Boolean> checkeds,Boolean isBorder, Integer hookSize, Integer edgeSize, List<String> cellDescr, List<String> cellValue){
		return getCheckCell( font,columnwidth,  minColumnHeight, null, checkValues,  checkeds, isBorder, hookSize, edgeSize, cellDescr, cellValue);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and checkbox values size
	 * @param minColumnHeight 列最小高度
	 * @param title 标题
	 * @param checkValues 复选框值
	 * @param checkeds check状态
	 * @param isBorder 是否有边框
	 * @param hookSize √ size
	 * @param edgeSize checkBox size
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCheckCell(Font font,int[] columnwidth, Integer minColumnHeight, String title, String[] checkValues, List<Boolean> checkeds,Boolean isBorder, Integer hookSize, Integer edgeSize, List<String> cellDescr, List<String> cellValue){
		PdfPCell checkCell =null;
		PdfPTable table = new PdfPTable(columnwidth.length);
        try {
        	table.setWidths(columnwidth);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
        if(!isBorder){
        	 table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        }
        //设置标题
		if(!StringUtils.isBlank(title)){
			  PdfPCell head = new PdfPCell(new Phrase(title,font));
		        head.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		        head.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
		        if(!isBorder){
		        	 head.setBorder(PdfPCell.NO_BORDER);
		        }
		        if(null != minColumnHeight){
		        	head.setMinimumHeight(minColumnHeight);
		        }
		        table.addCell(head);
		}
		//checkBox
		 int i=0;
		 for(String checkValue: checkValues){
		      //checkBox
		      PdfPCell checkBox = new PdfPCell();
		      if(null != hookSize && null != edgeSize){
		    	  checkBox.setCellEvent(new CheckboxCellEvent(checkValue, checkeds.get(i) , hookSize, edgeSize));
		      }
		      else{
		    	  checkBox.setCellEvent(new CheckboxCellEvent(checkValue, checkeds.get(i)));
		      }
		      checkBox.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		      checkBox.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
		      if(!isBorder){
		    	  checkBox.setBorder(PdfPCell.NO_BORDER);
		        }
		      if(null != minColumnHeight){
		    	  checkBox.setMinimumHeight(minColumnHeight);
		        }
			  table.addCell(checkBox);
			  //checkBox Describle
			  PdfPCell checkDescr = new PdfPCell(new Phrase(checkValue,font));
			  checkDescr.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			  checkDescr.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
			  if(!isBorder){
				  checkDescr.setBorder(PdfPCell.NO_BORDER);
		      }
			  if(null != minColumnHeight){
				  checkDescr.setMinimumHeight(minColumnHeight);
		      }
			  table.addCell(checkDescr);
			  i++;
		 }
		 //values
		 i=0;
		 for(String desc : cellDescr){
			 PdfPCell dcell = new PdfPCell(new Phrase(desc,font));
			 dcell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			 dcell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
			  if(!isBorder){
				  dcell.setBorder(PdfPCell.NO_BORDER);
		      }
			  if(null != minColumnHeight){
				  dcell.setMinimumHeight(minColumnHeight);
		      }
			  table.addCell(dcell);
			  PdfPCell vcell = new PdfPCell(new Phrase(cellValue.get(i),font));
			  vcell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			  vcell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
			 if(!isBorder){
				 vcell.setBorder(PdfPCell.NO_BORDER);
			 }
			 if(null != minColumnHeight){
				 vcell.setMinimumHeight(minColumnHeight);
			 }
			 table.addCell(vcell);
			  i++;
		 }
		 checkCell = new PdfPCell(table);
		 return checkCell;
				  
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and  values size
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCells(Font font,int[] columnwidth, List<String> cellDescr, List<String> cellValue){
		 return getCells( font,columnwidth, null, null, true, cellDescr, cellValue);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and  values size
	 * @param minColumnHeight 列最小高度
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCells(Font font,int[] columnwidth, Integer minColumnHeigh,List<String> cellDescr, List<String> cellValue){
		 return getCells( font,columnwidth,  minColumnHeigh, null, true, cellDescr, cellValue);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and  values size
	 * @param minColumnHeight 列最小高度
	 * @param isBorder 是否有边框
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCells(Font font,int[] columnwidth, Integer minColumnHeight,Boolean isBorder, List<String> cellDescr, List<String> cellValue){
		 return getCells( font,columnwidth,  minColumnHeight, null, isBorder, cellDescr, cellValue);
	}
	/**
	 * 
	 * @param font 字体
	 * @param columnwidth 列宽 title and  values size
	 * @param minColumnHeight 列最小高度
	 * @param title 标题
	 * @param isBorder 是否有边框
	 * @param cellDescr List cell
	 * @param cellValue List cell value
	 * @return
	 */
	public  PdfPCell getCells(Font font,int[] columnwidth, Integer minColumnHeight, String title,Boolean isBorder, List<String> cellDescr, List<String> cellValue){
		PdfPCell checkCell =null;
		PdfPTable table = new PdfPTable(columnwidth.length);
        try {
        	table.setWidths(columnwidth);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
        if(!isBorder){
        	 table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        }
        //设置标题
		if(!StringUtils.isBlank(title)){
			  PdfPCell head = new PdfPCell(new Phrase(title,font));
		        head.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		        head.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
		        if(!isBorder){
		        	 head.setBorder(PdfPCell.NO_BORDER);
		        }
		        if(null != minColumnHeight){
		        	head.setMinimumHeight(minColumnHeight);
		        }
		        table.addCell(head);
		}
		 //values
		 int i=0;
		 for(String desc : cellDescr){
			 PdfPCell dcell = new PdfPCell(new Phrase(desc,font));
			 dcell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			 dcell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
			  if(!isBorder){
				  dcell.setBorder(PdfPCell.NO_BORDER);
		      }
			  if(null != minColumnHeight){
				  dcell.setMinimumHeight(minColumnHeight);
		      }
			  table.addCell(dcell);
			  PdfPCell vcell = new PdfPCell(new Phrase(cellValue.get(i),font));
			  vcell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			  vcell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
			 if(!isBorder){
				 vcell.setBorder(PdfPCell.NO_BORDER);
			 }
			 if(null != minColumnHeight){
				 vcell.setMinimumHeight(minColumnHeight);
			 }
			 table.addCell(vcell);
			  i++;
		 }
		 checkCell = new PdfPCell(table);
		 return checkCell;
				  
	}
}

3.测试类
package test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import util.PdfPTableUtils;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class TestpdfPCellUtils {
	public static final String DEST = "E:\\Check.pdf";
	 
    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new TestpdfPCellUtils().createPdf(DEST);
    }
    public void createPdf(String dest) throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.open();
  	  //定义字体
        BaseFont bfChinese = BaseFont.createFont( "STSong-Light", "UniGB-UCS2-H", false );
        Font font = new Font(bfChinese, 11, Font.NORMAL);
        PdfPTable table = new PdfPTable(1);
        //定义每列的宽度
        table.setWidths(new int[]{240});
        int[] columnWidth = new int[]{60,30,60,30,60};
        int[] columnWidthx = new int[]{30,60,30,60};
        int[] columnWidthxx = new int[]{60,30,60,30,60,30,60,30,60};
        int[] columnWidthxxx = new int[]{30,60,30,60,30,60,30,60};
        int columnHeight = 30;
        String title = "状态";
        String[] checkValues = new String[]{"是","否"};
        List<Boolean> checkeds = new ArrayList<Boolean>();
        checkeds.add(true);
        checkeds.add(false);
        List<String> cellDescr = new ArrayList<String>();
        cellDescr.add("金额:");
        cellDescr.add("日期:");
        List<String> cellValue = new ArrayList<String>();
        cellValue.add("2000.00");
        cellValue.add("2016-06-20");
        //有title
//      PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckTable(font,columnWidth,columnHeight,title,checkValues,checkeds,false,6,11);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckTable(font,columnWidth,columnHeight,title,checkValues,checkeds,false);
		//无title
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckTable(font,columnWidthx,columnHeight,null,checkValues,checkeds,false);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckTable(font,columnWidthx,checkValues,checkeds,3,6);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckTable(font,columnWidthx,checkValues,checkeds,false,3,6);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckCell(font,columnWidthxx,columnHeight,title,checkValues,checkeds,false,6,11,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckCell(font,columnWidthxxx,columnHeight,checkValues,checkeds,false,6,11,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckCell(font,columnWidthxxx,columnHeight,checkValues,checkeds,false,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckCell(font,columnWidthxxx,columnHeight,checkValues,checkeds,false,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckCell(font,columnWidthxxx,checkValues,checkeds,false,3,6,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCheckCell(font,columnWidthxxx,checkValues,checkeds,3,6,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCells(font,columnWidth,columnHeight,title,false,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCells(font,columnWidthx,columnHeight,false,cellDescr,cellValue);
//		PdfPCell checkbox = PdfPTableUtils.getInstance().getCells(font,columnWidthx,columnHeight,cellDescr,cellValue);
        PdfPCell checkbox = PdfPTableUtils.getInstance().getCells(font,columnWidthx,cellDescr,cellValue);
		table.addCell(checkbox);
        document.add(table);
        document.close();
        System.out.println("===========:end");
    }
}

1
0
分享到:
评论

相关推荐

    itextpdf实现对pdf操作的工具类

    * 7、生成pdf目录(未具体形成工具类,待定制) * 8、批量pdf合成一份pdf * 9、批量pdf合成一份pdf并生成目录 pom引入 &lt;groupId&gt;com.itextpdf&lt;/groupId&gt; &lt;artifactId&gt;itextpdf &lt;version&gt;5.5.12 &lt;/dependency&gt;

    itextpdf不同版本的jar包

    总的来说,iTextPDF是Java开发中一个不可或缺的工具,特别是在Web项目中生成PDF文档时。理解并选择合适的版本是成功应用的关键,同时也要注意许可证问题和API的更新。在实际使用中,应根据项目需求和资源限制来做出...

    itextpdf-5.4.3.jar java 转pdf 工具类 jar

    这时,iTextPDF库成为了一个强大的工具。本文将深入探讨如何使用iTextPDF 5.4.3版本的jar包来实现Java程序中的PDF生成和操作。 首先,`itextpdf-5.4.3.jar`是iText库的一个特定版本,它提供了Java程序员用来创建、...

    使用itextpdf将excel转化为pdf + pdf加水印

    1. **导入itextpdf库**:在项目中添加itextpdf的依赖,这通常通过Maven或Gradle等构建工具完成。 2. **读取Excel**:使用Apache POI等库读取Excel文件,获取其内容和样式信息。 3. **创建PDF文档**:初始化一个...

    itextpdf.jar

    总结来说,iTextPDF是Java开发中不可或缺的PDF处理工具,它通过强大的HTML、XML和Web表单转换能力,以及丰富的PDF操作接口,极大地拓展了PDF的应用领域。无论是简单的数据输出,还是复杂的报表生成,甚至是安全的...

    itextpdf jar包

    iTextPDF是一个强大的Java类库,专为生成和编辑PDF文档而...总之,iTextPDF是一个功能强大且灵活的PDF处理工具,无论是在Web应用、桌面应用还是移动应用中,都能发挥关键作用,帮助开发者高效地生成高质量的PDF文档。

    itextpdf-5.5.13

    《iTextPDF 5.5.13:创建PDF文件的高效工具》 iTextPDF是一款功能强大的Java库,主要用于创建、编辑以及处理PDF文档。版本5.5.13是其历史版本之一,提供了丰富的API和功能,使得开发者能够方便地在Android平台上...

    itextpdf-5.5.5.jar

    《深入解析iTextPDF 5.5.5:构建PDF文档的强大工具》 在信息化高度发展的今天,PDF作为一种跨平台、格式稳定的文档格式,被广泛应用于各行各业。iTextPDF作为一个强大的PDF操作工具包,为开发者提供了丰富的API,...

    iText_pdf.rar_iText pdf_itext PDF类

    总之,iText是一个强大的Java PDF处理工具,无论你是要创建简单的单页文档还是复杂的多栏表格,或者是带有交互式表单和数字签名的高级PDF,它都能提供全面的支持。通过学习和使用iText,开发者可以高效地在Java应用...

    itextpdf中文帮助文档.pdf

    配合压缩包内的`itext-2.1.7-javadoc`,用户可以查阅详细的API文档,了解每个类和方法的具体用法,进一步加深对iTextPDF库的理解和使用。在开发过程中,结合这两个资源,开发者能有效地解决各种PDF操作问题,提升...

    java使用itextpdf、itext-asian对pdf文件加水印

    在这种情况下,可以使用iTextPDF库以及其针对亚洲字符集的扩展iText-Asian。这两个库提供了强大的功能,让我们能够方便地处理PDF文档,包括添加中文文字水印。以下是对这两个库以及如何在Java中实现这一功能的详细...

    itextpdf的相关jar包

    总之,iTextPDF是一个强大的PDF处理工具,通过它的扩展包,我们不仅可以创建和编辑标准文本和图像的PDF,还能将动态的SWF文件集成到文档中,提升PDF的交互性和多媒体体验。对于任何需要在PDF中整合富媒体内容的Java...

    itextpdf.zip

    - **XML到PDF转换**:iTextPDF支持将XML数据转换成PDF,通过XMLWorker类实现。 - **PDF安全和权限管理**:设置密码保护,限制复制、编辑等操作。 在实际开发中,你需要根据项目需求,参考"使用说明.txt"中的指导,...

    JAVA使用itextpdf实现HTML转PDF

    iTextPDF提供了`HtmlConverter`类,可以方便地将HTML字符串或URL转换为PDF。以下是一个简单的示例: ```java import com.itextpdf.html2pdf.HtmlConverter; import com.itextpdf.html2pdf.attach.ProcessorContext;...

    com.itextpdf.itextpdf.5.5.13.3 相关jar包和源码jar包

    com.itextpdf.itextpdf.5.5.13.3 相关jar包和包含源码jar包 &lt;groupId&gt;com.itextpdf&lt;/groupId&gt; &lt;artifactId&gt;itextpdf &lt;version&gt;5.5.13.3 下载地址为: ...

    使用iText生成PDF.doc

    总的来说,iText为开发者提供了一个全面的工具集,使得在Java中生成PDF变得简单高效。通过理解和熟练运用上述知识点,你可以创建满足各种需求的PDF文档。在实际开发中,还可以结合iText的其他高级特性,如书签、...

    itextpdf 导出pdf 表格 自动分页中文 目录

    在IT行业中,PDF(Portable Document Format)是一种广泛用于文档共享的标准格式,因为它能保持文档的原始布局和格式不受...总之,iTextPDF库提供了强大的工具,使得在Java环境中生成高质量的PDF文档变得简单而高效。

    iTextpdf支持中文

    iTextpdf是一款强大的Java库,专门用于生成和编辑PDF文档,同时也支持在Android平台上使用。...总的来说,iTextpdf是一个强大而全面的PDF处理工具,尤其在处理中文内容方面表现出色,是Android开发者的得力助手。

    itextpdf+itext-asian+xmlworker 导出pdf 表格 自动分页中文 目录.rar

    要实现自动分页的表格,你需要利用iTextPDF的Table类。Table对象可以设置自动分页属性,当表格内容超出当前页面时,iText会自动将其分割到下一页。你还需要定义一个事件处理器,监听Table事件,以便在每页末尾添加...

    itextpdf-5.5.10 源码、jar包、doc文档

    **正文** ITextPDF是一个广泛使用的Java库,...总的来说,这个资源包为开发者提供了全面的工具,以便于利用iTextPDF库高效地处理PDF文档。无论是初学者还是经验丰富的开发者,都可以从中获益,提升PDF相关的开发能力。

Global site tag (gtag.js) - Google Analytics