This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in generating multiple pdf docs on the fly from a servlet  RSS feed

 
parag Chatterjee
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got a input jsp page from where certain parameters are selected
and subit button is pressed.Control goes to a servlet.Now,the servlet
is supposed to generate multiple pdf documents on the fly.Using a third
party API I had generated pdf document as well.But only for a single pdf
generation.Even if I choose for multiple pdf generation usinga for loop
only the first one gets generated and the application stops.
I am giving my part of code as well.Can anyone please help me out.
Parag

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

if(req.getParameterValues("printReq")==null){
PrintWriter pw= res.getWriter();
pw.println("There is no certificate selected for printing");
}
else
{
String certnames[]= req.getParameterValues("printReq");
HttpSession objSession= req.getSession();
instName= (String)objSession.getValue("instructor_name");

int intlength= certnames.length ;
System.out.println(intlength);
// step 1: creation of a document-object
for(int i=0;i<certnames.length;i++)
{
ServletOutputStream out = res.getOutputStream();
Document document = new Document(PageSize.A4.rotate());

System.out.println("I am here 1a1a1a1a1a");
StringTokenizer objst= new StringTokenizer(certnames,"a");
String certName= objst.nextToken();
String certDate= objst.nextToken();
String cutCertDate= certDate.substring(0,10);
StringTokenizer objst1= new StringTokenizer(cutCertDate,"-");
String year= objst1.nextToken();
String month= objst1.nextToken();
String day = objst1.nextToken();
//System.out.println(year+ ""+ month + ""+ day + "" );
String strMonth[]= {"January","February","March","April","May","June","July","August","September","October","November","December"};
String strMonth1[]= {"01","02","03","04","05","06","07","08","09","10","11","12"};
for(int a=0;a<12;a++)
{
if(strMonth1[a].equals(month))
{
month = strMonth[a];
break;
}
}
res.setContentType("aplication/pdf");
try
{
PdfWriter.getInstance(document,out);
}catch(Exception ex)
{
System.out.println(">>>>>>>>>>>>>>>"+ex);
}
try {
Paragraph para= new Paragraph("");
para.setAlignment(1);

document.open();
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));

BaseFont helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font font = new Font(helvetica, 13, Font.BOLD);
finalDate= day + " "+ month + " , "+ year;
String newDate= finalDate;
Paragraph heading = new Paragraph(newDate,FontFactory.getFont(FontFactory.TIMES_BOLD,18, Font.BOLD));
heading.setAlignment(1);
document.add(heading);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
font = new Font(helvetica, 13, Font.BOLD);
heading = new Paragraph(instName,FontFactory.getFont(FontFactory.TIMES_BOLD,18, Font.BOLD));
heading.setAlignment(1);
document.add(heading);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
font = new Font(helvetica, 13, Font.BOLD);
heading = new Paragraph(certName,FontFactory.getFont(FontFactory.TIMES_BOLD,18, Font.BOLD));
heading.setAlignment(1);
document.add(heading);

document.add(new Chunk(" "));
document.add(new Chunk(" "));
document.add(new Chunk(" "));
document.add(new Chunk(" "));
document.add(para);
document.close();

}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
System.out.println("I am here 2a2a2a2a2a");
out.close();
}
//document.close();
}

}
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parag:
Welcome to JavaRanch!
But please read our naming policy at
http://www.javaranch.com/name.jsp
Then please re-register in accordance with the policy.
We know you'll enjoy the environment here at JavaRanch!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!