導航:首頁 > 文檔加密 > jsppdf

jsppdf

發布時間:2022-01-19 18:22:00

⑴ 可以把jsp頁面以pdf的格式導出

response.setContentType("application/pdf;charset=gb2312")
不知道對你有沒有幫助

⑵ jsp打開PDF

在jsp中打開pdf的實現原理是在頁面上輸出adobe reader對象。
<OBJECT type="application/pdf" width=0 height=0 style="display:none">
<DIV id="PDFNotKnown" style="display:none"> </DIV>
</OBJECT>
如果沒有安裝就要提示:
<DIV id="IfNoAcrobat" style="display:none">
你需要先安裝Adobe Reader才能正常瀏覽文件,請點擊<a href=http://get.adobe.com/cn/reader/download/?installer=Reader_11.0_Chinese_Simplified_for_Windowstarget="_blank">這里</a>下載Adobe Reader.
</DIV>

⑶ jsp直接打開本地的文件夾的pdf文件

jsp中要利用java來實現打開,可以通過瀏覽器打開:
以下程序實現了讀取某個路徑下的pdf文件,並用瀏覽器打開:
package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PDFServlet extends HttpServlet {
private static final long serialVersionUID = -3065671125866266804L;
public PDFServlet() {
super();
}

public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/pdf");

FileInputStream in = new FileInputStream(new File("d:/1.pdf"));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];

while ((in.read(b)) != -1) {
out.write(b);
}

out.flush();
in.close();
out.close();
}

public void init() throws ServletException {
}
}

⑷ JSP頁面打開PDF文件

有兩種方法:
一、直接用鏈接指向這個文件。
二、用IO把文件讀取,再向頁面輸出。response.setContentType,要設置這個。

⑸ jsp頁面如何導成pdf格式

先在伺服器上生成PDF文件,然後用戶通過點擊指向PDF文件的超鏈接選擇下載或打開。這是一個思路,或者說是思路之一。本文實現了這個思路,又給出另外一個思路並通過兩種途徑實現之。

1)直接在伺服器上生成PDF文件。

<%@ page import ="com.lowagie.text.*
,com.lowagie.text.pdf.*, java.io.*"%>
<%
String filename =
"PDF"+(new Random()).nextInt()+".pdf" ;
Document document =
new Document(PageSize.A4);
ServletOutputStream out1
= response.getOutputStream();
try{
PdfWriter writer =
PdfWriter.getInstance(document,
new FileOutputStream(filename) );
document.open();
document.add(new Paragraph("Hello World"));
document.close();
}
catch(Exception e){}
%>

上面的程序在伺服器上生成了一個靜態的PDF文件。顯然,每次運行所得的PDF文件的名稱應該是獨一無二不能有重的。本程序通過隨機函數來命名生成的PDF文件。本程序的缺點就是,每次運行都會在伺服器上產生一個PDF文件,如果不及時刪除,數量會越來越大,這顯然是站點維護者所不願意看到的。

2)將PDF文件通過流的形式輸送到客戶端的緩存。這樣做的好處是不會在伺服器上留下任何「遺跡」。

i)直接通過JSP頁面生成

<%@
page import="java.io.*,
java.awt.Color,com.lowagie.text.*,
com.lowagie.text.pdf.*"%>
<%
response.setContentType
( "application/pdf" );
Document document = new Document();
ByteArrayOutputStream buffer
= new ByteArrayOutputStream();
PdfWriter writer=
PdfWriter.getInstance( document, buffer );
document.open();
document.add(new Paragraph("Hello World"));
document.close();
DataOutput output =
new DataOutputStream
( response.getOutputStream() );
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for( int i = 0;
i < bytes.length;
i++ )
{
output.writeByte( bytes[i] );
}
%>

ii)通過Servlet生成

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public void doGet
(HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException
{
Document document =
new Document(PageSize.A4, 36,36,36,36);
ByteArrayOutputStream ba
= new ByteArrayOutputStream();
try
{
PdfWriter writer =
PdfWriter.getInstance(document, ba);
document.open();
document.add(new
Paragraph("Hello World"));
}
catch(DocumentException de)
{
de.printStackTrace();
System.err.println
("A Document error:" +de.getMessage());
}
document.close();
response.setContentType
("application/pdf");
response.setContentLength(ba.size());
ServletOutputStream out
= response.getOutputStream();
ba.writeTo(out);
out.flush();
}

⑹ 想在jsp上顯示pdf,這么做,在線等

需要將pdf轉換成flash(swf)格式才可以。網路文庫上就是flash。上傳時同時傳兩份,一份原版,一份轉換後的flash文件。給我們顯示的是flash,下載時下的是原版文件。

⑺ jsp生成pdf文件,打開提示:不是一個PDF文件或該文件已損壞 這是為什麼

生成file的時候出錯了。你是否用流的形式輸出 ?流是否關閉?請從以上幾點檢查代碼。

⑻ 怎麼用jsp網頁直接打開pdf文件.達到預覽的效果,像百度那樣的

網上有個開源組件叫flexpaper,使用的flash技術
在網站後台把pdf文檔轉換成swf,就可以使用flexpaperviewer觀看了。

閱讀全文

與jsppdf相關的資料

熱點內容
listsortjava 瀏覽:180
plc閃光電路編程實例 瀏覽:297
socket編程試題 瀏覽:201
華為的伺服器怎麼設置從光碟機啟動 瀏覽:867
程序員真的累嗎 瀏覽:323
學信網app為什麼刷臉不了 瀏覽:871
天蠍vs程序員 瀏覽:991
單片機下載口叫什麼 瀏覽:186
程序員的道 瀏覽:924
雲伺服器不實名違法嗎 瀏覽:556
怎樣查看文件夾圖片是否重復 瀏覽:993
文件怎麼導成pdf文件 瀏覽:806
打開sql表的命令 瀏覽:101
安卓手機如何面部支付 瀏覽:37
天元數學app為什麼登錄不上去 瀏覽:822
明日之後為什麼有些伺服器是四個字 瀏覽:103
安卓系統l1是什麼意思 瀏覽:25
伺服器一直崩應該用什麼指令 瀏覽:924
cm202貼片機編程 瀏覽:729
php構造函數帶參數 瀏覽:179