• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}

}
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic