码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA 读取pdf文件

时间:2015-04-21 12:50:13      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:

 

第一个路口action 

/*
 * wuhan syspro author zhangrui 2010/08/23
*/
package jp.co.syspro.poo.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class PrintPdfAction extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
	HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		PdfExport pdf = new PdfExport();
		String id=request.getParameter("id");
		pdf.make(request,response,id);
		return null;
		}
}

进行输出方法

/*
 * author syspro wuhan zhangrui 2010/8/20
*/
package jp.co.syspro.poo.action;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.BaseFont;   
import com.lowagie.text.pdf.PdfTemplate;   
import jp.co.syspro.poo.dao.System3Dao;

public class PdfExport extends PdfPageEventHelper {
	
	    public PdfTemplate tpl;
	    
	    public BaseFont bf;
	    
	    public void make(HttpServletRequest request, HttpServletResponse response,String id) throws Exception{  
	    	ArrayList f_file2=System3Dao.getInstance().getFile(id);
	    	InputStream f_file=(InputStream)f_file2.get(0);
	    	Integer f_size=Integer.parseInt(f_file2.get(1).toString());
	    	response.reset();
			response.setContentType("application/pdf");
			OutputStream output = response.getOutputStream();
			InputStream fis = f_file;
			byte[] b = new byte[f_size];
			int i = 0;
			while ((i = fis.read(b)) > 0) {
				output.write(b, 0, i);
			}
			output.flush();
	    } 
}

 

JAVA 读取pdf文件

标签:

原文地址:http://www.cnblogs.com/sunxun/p/4444035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!