/**
* 用于itext生成pdf
* @author rgy
*/
public class ItextOutPdfDemo {
Document document;
PdfWriter writer;
public static void main(String[] args) {
String username = "admin";
String password = "admin";
String outPdfLoc = "D:/Test.pdf";
ItextOutPdfDemo t = new ItextOutPdfDemo();
t.outPdf(username,password,outPdfLoc);
}
public void outPdf(String username,String password,String outPdfLoc){
try (
OutputStream file = new FileOutputStream(outPdfLoc);
){
document = new Document();
writer = PdfWriter.getInstance(document, file);
writer.setEncryption
(
username.getBytes(),
password.getBytes(),
PdfWriter.ALLOW_PRINTING,
PdfWriter.ENCRYPTION_AES_128
);
document.open();
document.add(new Paragraph("Hello World, iText"));
document.add(new Paragraph(new Timestamp(System.currentTimeMillis()).toString()));
Image jpg = Image.getInstance("d:/helloworld.png");
jpg.setAlignment(Image.ALIGN_CENTER);
document.add(jpg);
} catch (Exception e) {
e.printStackTrace();
}finally {
document.close();
}
}
}
itext生成pdf
最新推荐文章于 2020-08-13 23:14:55 发布