我想使用java itext创建pdf。它将在我第一次单击按钮时创建pdf。但一旦创建pdf,则需要重新运行该项目以再次创建pdf。我需要通过运行项目一次来多次创建pdf。如何通过运行项目一次创建pdf?
File file=new File(location);
if(!file.exists())
{
file.mkdir();
}
try{
PdfWriter writer = PdfWriter.getInstance(doc,new FileOutputStream(location+"Admit of DIU "+generatedKey+".pdf"));
doc.setPageSize(one);
doc.setMargins(10, 10, 10, 10);
doc.open();
Paragraph pUniversityName= new Paragraph("University",font);
Paragraph pAddress= new Paragraph("address.\n\n\n");
Paragraph pRoll=new Paragraph("Exam Roll No :"+acdata.getRoll()+"\n");
Paragraph pBatch=new Paragraph("Batch No :"+acdata.getBatch()+"\n");
Paragraph p4=new Paragraph("\n\n\n Department "+acdata.getDepartment()+" \n\n\n");
Paragraph p5=new Paragraph(" Full Name of the Examinee : "+acdata.getName()+"\n");
Paragraph p6=new Paragraph(" Father's Name: "+acdata.getFathersName());
Paragraph p7=new Paragraph(" Mother's Name: "+acdata.getMothersName());
Paragraph p8=new Paragraph(" Courses' name for apperaring at the Examinations: (1) "+courseName.get(0)+" ( "+courseCode.get(0)+" ).");
Paragraph p9=new Paragraph(" (2) "+courseName.get(1)+" ( "+courseCode.get(1)+" ). "+" (3) "+courseName.get(2)+" ( "+courseCode.get(2)+" )");
pUniversityName.setAlignment(Paragraph.ALIGN_CENTER);
pAddress.setAlignment(Paragraph.ALIGN_CENTER);
pRoll.setIndentationLeft(620);
pBatch.setIndentationLeft(620);
image.scaleAbsoluteHeight(120);
image.scaleAbsoluteWidth((image.getWidth() * 110) /image.getHeight());
image.setAbsolutePosition(45,530);
Image diulogo=Image.getInstance("src/images/DiuLogo.png");
diulogo.scaleAbsoluteHeight(26);
diulogo.scaleAbsoluteWidth(50);
diulogo.setAbsolutePosition(375,595);
doc.add(pUniversityName);
doc.add(pAddress);
doc.add(pRoll);
doc.add(pBatch);
doc.add(p4);
doc.add(image);
doc.add(logo);
doc.add(p5);
doc.add(p6);
doc.add(p7);
doc.add(p8);
doc.add(p9);
if(courseName.size()>4){
Paragraph p10=new Paragraph(" (4) "+courseName.get(3)+" ( "+courseCode.get(3)+" ). "+" (5) "+courseName.get(4)+" ( "+courseCode.get(4)+" )");
doc.add(p10);
}
if(courseName.size()>5){
Paragraph p11=new Paragraph(" (6) "+courseName.get(5)+" ( "+courseCode.get(5)+" ) "+" (7) ");
doc.add(p11);
}
doc.close();
JOptionPane.showMessageDialog(null, "Admit No DIU-"+generatedKey);
Desktop.getDesktop().open(new java.io.File(location+"Admit of DIU "+generatedKey+".pdf"));
}
catch(Exception ec){
Logger.getLogger(AdmitCard.class.getName()).log(Level.SEVERE, null, ec);
}
现在在这里,我为学生的录取卡生成了pdf文件。如果我为卷1创建pdf,则会创建pdf,然后,如果尝试为卷2创建pdf而无需重新运行该项目,则不会创建pdf。如何通过一次运行项目为多个学生创建pdf。