itext生成pdf文件---图片插入
2018-01-31 14:54
746 查看
1,导入jar包
2,参考代码
protected static void creatPDF() throws DocumentException, FileNotFoundException, Exception, IOException, BadElementException, MalformedURLException {
// Document document = new Document(PageSize.A4);
Rectangle r = new Rectangle(0, 0, 600, 600);
Document document = new Document(PageSize.A4, 15, 15, 15, 15);
PdfWriter.getInstance(document, new FileOutputStream(new File("D:\\test.pdf")));
document.open();
document.newPage();
PdfPTable ptable = new PdfPTable(6);
System.out.println(document.getPageSize().getWidth() + "," + document.getPageSize().getWidth() / 8);
String imagetemp = "D:\\temp.jpg";
for (int j = 0; j < 100; j++) {
OutputStream stream = new FileOutputStream(imagetemp);
BufferedImage bufimage = QRCodeUtil.createImage("1018043486", "http://localhost/images/tb_top_logo.png", 270, 300, 4, true, "1018043486");
ImageIO.write(bufimage, QRCodeUtil.FORMAT_NAME, stream);
Image jpeg = Image.getInstance(imagetemp);
jpeg.scaleAbsolute(100, 100);
jpeg.setAlignment(Image.ALIGN_CENTER);
PdfPCell cell = new PdfPCell(jpeg);
ptable.addCell(cell);
stream.flush();
stream.close();
}
ptable.setWidthPercentage(100);//去掉table边距全屏操作
document.add(ptable);
document.close();
}
3,参照:https://www.cnblogs.com/linjiqin/p/3539283.html
2,参考代码
protected static void creatPDF() throws DocumentException, FileNotFoundException, Exception, IOException, BadElementException, MalformedURLException {
// Document document = new Document(PageSize.A4);
Rectangle r = new Rectangle(0, 0, 600, 600);
Document document = new Document(PageSize.A4, 15, 15, 15, 15);
PdfWriter.getInstance(document, new FileOutputStream(new File("D:\\test.pdf")));
document.open();
document.newPage();
PdfPTable ptable = new PdfPTable(6);
System.out.println(document.getPageSize().getWidth() + "," + document.getPageSize().getWidth() / 8);
String imagetemp = "D:\\temp.jpg";
for (int j = 0; j < 100; j++) {
OutputStream stream = new FileOutputStream(imagetemp);
BufferedImage bufimage = QRCodeUtil.createImage("1018043486", "http://localhost/images/tb_top_logo.png", 270, 300, 4, true, "1018043486");
ImageIO.write(bufimage, QRCodeUtil.FORMAT_NAME, stream);
Image jpeg = Image.getInstance(imagetemp);
jpeg.scaleAbsolute(100, 100);
jpeg.setAlignment(Image.ALIGN_CENTER);
PdfPCell cell = new PdfPCell(jpeg);
ptable.addCell(cell);
stream.flush();
stream.close();
}
ptable.setWidthPercentage(100);//去掉table边距全屏操作
document.add(ptable);
document.close();
}
3,参照:https://www.cnblogs.com/linjiqin/p/3539283.html
相关文章推荐
- 滴水穿石--Java 生成PDF文件--iText使用之插入图片和中文乱码
- iText整合图片和自带表格生成PDF文件(很好用的框架)
- js生成pdf文件,支持中文字体,插入图片
- iText7 生成 PDF 文件,解决各种操作系统中文问题,控制指定位置显示图片、文字、图文混排
- Java使用Freemarker和iText生成带有图片的PDF文件
- 使用iText7----生成纯文本、图片、表格内容的pdf文件
- java 通过 itext生成pdf添加,插入文字,图片
- javaWeb项目springMVC框架下利用ITextpdf 工具打印PDF文件的方法(打印表单、插入图片)
- 【使用Itext处理PDF文档(新建PDF文件、修改PDF文件、PDF中插入图片、将PDF文件转换为图片)】
- 滴水穿石--Java 生成PDF文件--iText使用之入门
- java 生成pdf文件,添加图片
- (例)Java生成PDF图片 iText
- 如何利用iText在java程序中生成PDF文件
- 使用POI生成Excel文件及使用POI在EXCEL文件中插入图片的方法
- itext 5.3.0实现对pdf文件添加(文字和图片)水印
- Itext 生成 pdf文件使用方法:
- itext使用模板生成pdf文件
- Java生成PDF文件(依赖于iText-2.1.0.jar)
- 【Java】maven工程使用iText生成PDF文件
- java导出pdf文件(插入图片及信息)