iframe 내부에서 pdf를 인쇄하기위한 몇 가지 옵션을 조사했으며 아무 것도 작동하지 않는 것 같습니다.PDF를 iframe 내용의 jsp로 인쇄하십시오.
간단한 상세 사항 :
- 나는 사용자로부터 일부 검색 매개 변수를 얻을.
- 나는 데이터베이스 검색을 수행 한 다음 Apachi FOP를 사용하여 결과의 PDF를 생성합니다.
- 인쇄 및 취소 버튼이있는 웹 페이지로 연결됩니다.
- 사용자가 [인쇄] 버튼을 클릭하면 PDF가 표시된 창이 열립니다.
- 사용자가 PDF를 인쇄 할 수있는 인쇄 대화 상자가 열립니다.
- PDF 파일이 서버에서 삭제되었습니다.
- 창문 가까이
고급 정보 :이 내용은 IE8에서 작동 할 필요가
- .
- FOP 통합은 XSLT 변환을 사용하지 않습니다. 문자열로 포맷 된 입력 된 FOP XML의 StringReader 만 사용합니다.
- PDF를 표시하는 창은 실제로 두 개의 JSP 페이지입니다.
- 첫 페이지 :
- 는 소스
- 으로서 제 2 JSP 페이지와 iframe이 있음 iframe이
- 번째 페이지에 PDF를 출력 부하에 printPDF() 함수를 실행 :
- 자바의 BufferedOutputStream와 메소드가 ServletOutputStream은
- 는 를 출력 후 파일을 삭제합니다 사용
- 용도 out = pageContent.pushBody(); 여기
첫 번째 JSP 페이지 (인쇄 함수를 호출 실행)의 일부입니다
여기<body onload='printPDF()'>
<table>
<tr>
<td class="content">
<%
// get myfilename from the myfile parameter on the URL
String myfile = request.getParameter("myfile");
out.print("<iframe src='fc_view_letter.jsp?myfile="+ myfile + "' id='pdfFrame'></iframe>");
%>
</td>
</tr>
</table>
<script>
function printPDF()
{
var id = 'pdfFrame';
var iframe = document.frames ? document.frames[0] : document.getElementById(id);
var ifWin = iframe.contentWindow || iframe;
ifWin.focus();
ifWin.printPage();
//ifWin.print();
}
</script>
</body>
이 두 번째 JSP 페이지 (PDF를 표시하는 하나)의 대부분 : 내가 생각하는 문제는
<%@ page session="false" %>
<%@ page import="java.io.*" %>
<%@ page import="java.net.URLDecoder" %>
<html>
<head>
</head>
<body>
<%
String myfile = request.getParameter("myfile");
String myfiledecoded = "";
myfiledecoded = URLDecoder.decode(myfile, "UTF8");
String myfilename = myfiledecoded;
String extension;
int dotPos = myfilename.lastIndexOf(".")+1;
extension = myfilename.substring(dotPos);
int slashPos = myfilename.lastIndexOf("/")+1;
String secondparam = "filename=" + myfiledecoded.substring(slashPos);
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", secondparam);
try {
ServletOutputStream sout = response.getOutputStream();
response.setHeader("Content-Disposition", secondparam);
File file = new File(myfilename);
FileInputStream fstream = new FileInputStream(file);
BufferedInputStream bis = null;
bis = new BufferedInputStream(fstream);
BufferedOutputStream bos = null;
bos = new BufferedOutputStream(sout);
byte[] buff = new byte[1024];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
bis.close();
bos.close();
sout.flush();
sout.close();
//file.delete();
}
catch (Exception e) {
System.out.println("Exception Occured....................");
}
out.clear();
out = pageContext.pushBody();
%>
</body>
</html>
입니다 : 나는 버퍼가 HTML을 모두 제거 만 PDF를 표시라고 생각 해요. 적어도 IE에서는 그렇게합니다. 파이어 폭스를 보았을 때 PDF 파일을 임베드했다. 어쩌면 HTML이 아니기 때문에 iframe의 내용을 가져올 수 없습니다.
여기 내 소스는 지금까지 있습니다 :
Javascript Print iframe contents only
How to open print dialog after pdf generated?
http://www.ehow.com/how_7352227_use-javascript-print-pdf.html
http://www.webmasterworld.com/forum91/4086.htm
how to print pdf inside embed/iframe using javascript
Printing contents of a dynamically created iframe from parent window
나는 누군가가 알고있는 경우 FOP의 XML에 온로드 인쇄 이벤트를 추가 할 의향이로드 될 때 실행 일부 인쇄 자바 스크립트를 추가 무엇 FOP XML에 자바 스크립트 이벤트를 추가하는 방법. – milesacul