package test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.ExceptionConverter;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
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 CreateRadioInTable {
public static final String DEST = "E:\\radio.pdf";
public static void main(String[] args) throws IOException,
DocumentException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new CreateRadioInTable().createPdf(DEST);
}
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
radiogroup.setFieldName("Language");
PdfPTable table = new PdfPTable(2);
PdfPCell cell;
cell = new PdfPCell(new Phrase("English:"));
table.addCell(cell);
cell = new PdfPCell();
cell.setCellEvent(new MyCellField(radiogroup, "english"));
table.addCell(cell);
cell = new PdfPCell(new Phrase("French:"));
table.addCell(cell);
cell = new PdfPCell();
cell.setCellEvent(new MyCellField(radiogroup, "french"));
table.addCell(cell);
cell = new PdfPCell(new Phrase("Dutch:"));
table.addCell(cell);
cell = new PdfPCell();
cell.setCellEvent(new MyCellField(radiogroup, "dutch"));
table.addCell(cell);
document.add(table);
writer.addAnnotation(radiogroup);
document.close();
System.out.println("===========:end");
}
class MyCellField implements PdfPCellEvent {
protected PdfFormField radiogroup;
protected String value;
public MyCellField(PdfFormField radiogroup, String value) {
this.radiogroup = radiogroup;
this.value = value;
}
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
final PdfWriter writer = canvases[0].getPdfWriter();
RadioCheckField radio = new RadioCheckField(writer, rectangle, null, value);
try {
radiogroup.addKid(radio.getRadioField());
} catch (final IOException ioe) {
throw new ExceptionConverter(ioe);
} catch (final DocumentException de) {
throw new ExceptionConverter(de);
}
}
}
}
分享到:
相关推荐
itext 生成pdf 目录,itext 生成pdf 目录,itext 生成pdf 目录
Android使用iText生成pdf并读取pdf内容,iText是著名的开放源码的站点sourceforge的一个项目,可用来生成Pdf文件和读取Pdf文件内容.
iText生成pdf解决中文不显示字库,pdf凉字不显示,由于生成iText插件生成pdf的时候中文会显示不出来,遇到过的是"凉"字,查到是字体库的原因,网上下载字体库msyh.ttc,生成的时候指定字体库,就可以解决了,小bug一...
使用IText生成PDF和WORD文档 包括源码和IText所需jar包
itext对pdf进行编辑.使用Adobe对pdf创建表单,itext对表单填充,下拉选,单选,文本框.复选框.itext对pdf进行编辑.使用Adobe对pdf创建表单,itext对表单填充,下拉选,单选,文本框.复选框
此文档主要讲述了使用Java组件iText来生成PDF,操作PDF
在Java代码中使用itext生成PDF文档,实现PDF文档的导出。
com.itextpdf.itextpdf.5.5.13.3 相关jar包和包含源码jar包 <groupId>com.itextpdf</groupId> <artifactId>itextpdf <version>5.5.13.3 下载地址为: ...
iText是著名的开放源码的站点sourceforge的一个项目,它是一个用于生成PDF文档的一个java开源库。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。如果PDF是标记的且包含一个结构树,...
iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。
java解决Itext生成PDF中文不换行的问题
利用itext读取PDF后使用pdfbox将PDF转为图片。压缩包内附有相应JAR文件
iText7 用于html转换pdf核心包-html2pdf-1.0.1.jar。。。。
itext生成PDF图片文档
一段经典的处理iText打印pdf表格代码。
包含 itext-asian-5.2.0.jar itextpdf-5.5.5.jar
iText是一个JAVA中快速制作PDF文件的类库,如果你想用JAVA制作PDF文档,这个源码包可不要错过哟。
这是在github上面下载的,用于PDF图层,修改积分
Itext生成PDF所需要的最全Jar包,里面包含了所需要生成itext的所有jar包。一次导入
包括itext的jar包,以及对pdf进行签章所需要的jar包,