Hello,
I am opening a pdf document from a servlet using the following code.
But the file does not open directly.It comes with a (open with...) option
where I have to select the pdf format to open the pdf document.
My actual requirement is to open the file directly by a single click on a
hyperlink on the browser and don't want (open with..)option.
Can anybody please suggest me how I can achieve this.
my code is below:
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
ServletOutputStream out = res.getOutputStream();
Document document = new Document(PageSize.A4.rotate());
res.setContentType("aplication/pdf");
try
{
PdfWriter.getInstance(document,out);
}catch(Exception ex)
{
System.out.println(">>>>>>>>>>>>>>>"+ex);
}
Paragraph para= new Paragraph("");
para.setAlignment(1);
document.open();
for(int i=0;i<certnames.length;i++)
{
System.out.println("I am here 1a1a1a1a1a");
StringTokenizer objst= new
StringTokenizer(certnames[i],"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;
}
}
try {
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.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
System.out.println("I am here 2a2a2a2a2a");
}
document.close();
out.close();
}
}
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
-------------------------------------------------------
This sf.net email is sponsored by: Dice - The leading online job board
for high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code=31
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions