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();
}