Whene我在瀏覽器上打開PDF我想將它打印在div而不是所有頁面中。 我該怎麼做?這裏是我的JSP代碼:將PDF打印到div中
<%@ page language="java" import="com.search.ts.*
,java.io.*
,java.net.*
,javax.xml.namespace.QName
,javax.jws.*
,javax.xml.ws.* "
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ebook reader</title>
<%@ page language="java" import="com.search.ts.CallSEI_CallSPort_Client,java.util.*,com.search.ts.Links,com.search.ts.LinksResponse" %>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="right_section">
<div class="right_box">
<%
String filename= request.getParameter("err");
//String filename =(String) request.getAttribute("linkbook");
File file = new File("F:/fichiers/", filename+".pdf");
response.setContentType(getServletContext().getMimeType(file.getName()));
response.setContentLength((int) file.length());
response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
BufferedInputStream input = null;
BufferedOutputStream output = null;
try {
input = new BufferedInputStream(new FileInputStream(file));
output = new BufferedOutputStream(response.getOutputStream());
byte[] buffer = new byte[8192];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
} finally {
if (output != null) try { output.close(); } catch (IOException ignore) {}
if (input != null) try { input.close(); } catch (IOException ignore) {}
}
%>
</div>
</div>
</body>
</html>
你可以在這裏發佈代碼,以防鏈接網站在未來發生故障嗎?另外,保持鏈接到原來的。將這些事情備份起來是一個不錯的主意,這樣如果兩年後有人來到你的鏈接頁面,他們仍然會有解決方案。 – 2011-06-08 19:33:56
您應該將工作解決方案從您的鏈接複製到此答案(至少是代碼),以防鏈接將來死亡,以便人們可以通過SO訪問解決方案。 – 2011-06-08 19:40:23