Question : How to generate PDF open with new window ?

Hi,

I need design to open the new popup window with PDF.

So, i have command button , if i click the button open the new pdf window , how to do that ?

Need to use javascript for open new window ? if then how to call the jsp file for open PDF ?

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
JSP file

<%@
page import="javax.servlet.*, 
		javax.servlet.http.*,
		java.io.*,
		java.util.*,
		com.lowagie.text.pdf.*,
		com.lowagie.text.*"
		
		
	 
%><%

response.setContentType("application/pdf");
Document document = new Document();

try{
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	PdfWriter.getInstance(document, buffer); 
	document.open();
	

	//document.addHeader("firstname","Lastname");
	/*PdfPTable table = new PdfPTable(2);
	table.addCell("1");
	table.addCell("2");
	table.getTableEvent();
	
	document.add(table);*/		
	document.close(); 
	
	DataOutput dataOutput = new DataOutputStream(response.getOutputStream());
	byte[] bytes = buffer.toByteArray();
	response.setContentLength(bytes.length);
	for(int i = 0; i < bytes.length; i++)
	{
		dataOutput.writeByte(bytes[i]);
	}
	
}catch(DocumentException e){
	e.printStackTrace();
}

%>

Answer : How to generate PDF open with new window ?

Hey, look,

http://200.14.205.244/pdfTest.jsp

That is a Tomcat 5 web server, the source from the testPage is below, so it works like a charme.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
<%@ page language="java" import="java.io.FileWriter, java.io.BufferedInputStream, java.io.FileInputStream"%> 
<% 
        response.setContentType ("application/pdf");  
        response.setHeader ("Content-Disposition", "attachment; filename=\"file.pdf\"");  
        ServletOutputStream stream = response.getOutputStream();  
        BufferedInputStream fif =   
        new BufferedInputStream(new FileInputStream("C:\\file.pdf"),165535);  
                         
                        int data; 
                        while((data = fif.read()) != -1) { 
                        stream.write(data); 
                        } 
                        fif.close(); 
                        stream.close(); 
%>
Random Solutions  
 
programming4us programming4us