- 浏览: 954604 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
package test; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import test.CheckboxCell2.CheckboxCellEvent; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.ExceptionConverter; import com.itextpdf.text.Font; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Phrase; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfAnnotation; import com.itextpdf.text.pdf.PdfAppearance; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfFormField; 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; public class TestCheckBox { public static final String DEST = "E:\\testCheck.pdf"; public static void main(String[] args) throws IOException, DocumentException { File file = new File(DEST); file.getParentFile().mkdirs(); new TestCheckBox().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 fNormal = new Font(bfChinese, 11, Font.NORMAL); //新建Table1列 PdfPTable table = new PdfPTable(1); //定义每列的宽度 table.setWidths(new int[]{240}); //新建table t1 5 列 PdfPTable t1 = new PdfPTable(5); t1.setWidths(new int[]{60,30,60,30,60}); t1.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPCell head = new PdfPCell(new Phrase("状态:",fNormal)); head.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); head.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); head.setBorder(PdfPCell.NO_BORDER); head.setMinimumHeight(30); t1.addCell(head); /* head.setBorderWidthRight(0f); head.setBorderColorRight(BaseColor.WHITE); head.setBorder(Rectangle.BOTTOM | Rectangle.LEFT | Rectangle.TOP );*/ // head.setCellEvent(new BorderCell(3)); // table.addCell(head); PdfPCell c0 = new PdfPCell(); c0.setCellEvent(new CheckboxCellEvent("1", true)); c0.setFixedHeight(10); c0.setBorder(PdfPCell.NO_BORDER); c0.setPadding(10); PdfPCell c1 = new PdfPCell(c0); // c1.setIndent(15); // c1.setPadding(10); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); c1.setBorder(PdfPCell.NO_BORDER); t1.addCell(c1); PdfPCell c11 = new PdfPCell(new Phrase("是",fNormal)); c11.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c11.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); c11.setMinimumHeight(30); c11.setBorder(PdfPCell.NO_BORDER); t1.addCell(c11); PdfPCell c2 = new PdfPCell(); c2.setCellEvent(new CheckboxCellEvent("0", false)); c2.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); c2.setBorder(PdfPCell.NO_BORDER); c2.setFixedHeight(10); c2.setMinimumHeight(30); t1.addCell(c2); PdfPCell c21 = new PdfPCell(new Phrase("否",fNormal)); c21.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c21.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); c21.setBorder(PdfPCell.NO_BORDER); c21.setMinimumHeight(30); t1.addCell(c21); //将t1嵌入到 列中 PdfPCell checkbox = new PdfPCell(t1); table.addCell(checkbox); document.add(table); document.close(); System.out.println("===========:end"); } class CheckboxCellEvent implements PdfPCellEvent { // The name of the check box field protected String name; protected boolean flag ; // We create a cell event public CheckboxCellEvent(String name, boolean flag) { this.name = name; this.flag = flag; } // 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 - 5, y - 5, x + 5, y + 5); 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 - 10, y - 10, 20,20); canvas.stroke(); try { writer.addAnnotation(checkbox.getCheckField()); } catch (Exception e) { throw new ExceptionConverter(e); } } } class BorderCell implements PdfPCellEvent { private int border = 0; public BorderCell(int border) { this.border = border; } public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; canvas.saveState(); canvas.setLineDash(0, 4, 2); if ((border & PdfPCell.TOP) == PdfPCell.TOP) { canvas.moveTo(position.getRight(), position.getTop()); canvas.lineTo(position.getLeft(), position.getTop()); } if ((border & PdfPCell.BOTTOM) == PdfPCell.BOTTOM) { canvas.moveTo(position.getRight(), position.getBottom()); canvas.lineTo(position.getLeft(), position.getBottom()); } if ((border & PdfPCell.RIGHT) == PdfPCell.RIGHT) { canvas.moveTo(position.getRight(), position.getTop()); canvas.lineTo(position.getRight(), position.getBottom()); } if ((border & PdfPCell.LEFT) == PdfPCell.LEFT) { canvas.moveTo(position.getLeft(), position.getTop()); canvas.lineTo(position.getLeft(), position.getBottom()); } canvas.stroke(); canvas.restoreState(); } } }
结果如下:
发表评论
-
iText,PDF,Checkbox工具类升级版
2016-06-20 11:38 34501.cell事件类 package event; imp ... -
iText,PDF,Checkbox工具类
2016-06-18 11:03 19831.Cell事件类 package event; imp ... -
iText制作PDFCheckbox实例
2016-06-18 11:02 1844package test; import java.io ... -
iText制作PDF,ComboBox
2016-06-18 11:01 817package test; import java.io ... -
iText制作PDF,RaidoGroup
2016-06-17 11:04 828package test; import java.io.F ... -
iText制作PDF,radio
2016-06-17 10:52 926package test; import java.io ... -
iText制作PDFCheckbox-1
2016-06-17 10:48 755package test; import java.io ... -
iText制作PDF,Table
2016-06-17 10:48 1062package test; import java.io ... -
iText制作PDFCheckbox-2
2016-06-17 10:13 969PDF中checkBox的制作,需要依赖于PdfPCellEv ... -
JasperReport浏览器输出PDF为空白页的解决方案
2016-05-27 15:46 3802当我们在用IReport制作好 ...
相关推荐
NULL 博文链接:https://ilove2009.iteye.com/blog/655973
iText7 原生方法制作带斜线表格
一段经典的处理iText打印pdf表格代码。
itext pdf word 中文 表格 图片,看了这个你就能用java生成word,pdf并插入图片,中文,表格。里面还有itext的API包括中文英文。
包含 itext-asian-5.2.0.jar itextpdf-5.5.5.jar
通过SQL及JDBC模式导出各类业务数据,以PDF文件格式存放,要求该文件只能...4、PDF表格列数可能很多,比如1-50列信息,导出时需判断A4纸格式或其他格式宽度。 5、PDF表格行数量可能超大,比如10万以上,甚至100万以上。
资源包含iTextSharp7(net40及netstandard1.6下的库文件),iText.kernel源码和读取表格数据源码,运行TableExtractionFromPDF项目可查看效果。 iText.kernel版本7.1.3.0 iText.io版本7.1.3.0 原文网址:...
用iText生成比较简单的表格形式Word
NULL 博文链接:https://x125858805.iteye.com/blog/2239773
java 使用iText生成word文档,包中带有源码与所用jar包,生成文档格式标准。可分页,可带页眉,可生成表格、图片和文字等word元素内容,文字带字号,字体,颜色等。
用Itext操作word,可以在word里画表格,也可以往word里插入图片
iText创建表格pdf的教程,使用pdfptable创建表单!
iText页码、页眉、页脚,itext 的复杂表格实现、保留表头、表尾、根据需求生成不同的iText表格
itext生成带图片的,带表格的复杂样式的word文档范例代码,代码中包含需要的jar包,现在侯可以直接使用。
java 使用IText导出PDF(包含图片、表格、文字等等Demo和依赖包),最全IText使用Demo,下载即可用
主要介绍了Java使用itext5实现PDF表格文档导出,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
资源包含iText.kernel源码和读取表格数据源码,运行TableExtractionFromPDF项目可查看效果。 iText.kernel版本7.1.3.0 iText.io版本7.1.3.0 原文网址:...
文档POI只支持往生成的中填入文本,对于图片根本就不支持。使用itext 生成rtf格式的直接保存为word
因为项目需要用到pdf模板生成pdf,其中模板中有图片,找了好久没有资料,无奈之下翻看api和源码,给大家分享下
NULL 博文链接:https://lucifer-li6.iteye.com/blog/1637687