JAVA 读取pdf文件
第一个路口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文件的更多相关文章
- java读取pdf总结
第三方软件 1.pdfbox PDFBox 0.7.3.PDFBox是一个开源的对pdf文件进行操作的库. PDFBox-0.7.3.jar加入classpath.同时FontBox1.0.jar加入 ...
- java读取pdf文本转换html
补充:一下代码基于maven,现将依赖的jar包单独导出 地址:pdf jar 完整代码地址 也就两个文件 java读取pdf中的纯文字,这里使用的是pdfbox工具包 maven引入如下配置 < ...
- java分享第十六天( java读取properties文件的几种方法&java配置文件持久化:static块的作用)
java读取properties文件的几种方法一.项目中经常会需要读取配置文件(properties文件),因此读取方法总结如下: 1.通过java.util.Properties读取Propert ...
- Java读取Excel文件的几种方法
Java读取 Excel 文件的常用开源免费方法有以下几种: 1. JDBC-ODBC Excel Driver 2. jxl.jar 3. jcom.jar 4. poi.jar 简单介绍: 百度文 ...
- Java读取txt文件
package com.loongtao.general.crawler.slave.utils; import java.io.BufferedReader; import java.io.File ...
- java 读取XML文件作为配置文件
首先,贴上自己的实例: XML文件:NewFile.xml(该文件与src目录同级) <?xml version="1.0" encoding="UTF-8&quo ...
- java 读取TXT文件的方法
java读取txt文件内容.可以作如下理解: 首先获得一个文件句柄.File file = new File(); file即为文件句柄.两人之间连通电话网络了.接下来可以开始打电话了. 通过这条线路 ...
- 用java读取properties文件--转
今天为了通过java读取properties文件,google了很长时间,终于找到了.现在特记录之和大家一起分享. 下面直接贴出代码:java类 public class Mytest pub ...
- java读取xml文件报“org.xml.sax.SAXParseException: Premature end of file” .
背景:java读取xml文件,xml文件内容只有“<?xml version="1.0" encoding="UTF-8"?>”一行 java读取该 ...
随机推荐
- 火星02坐标转换为WGS84坐标
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import jav ...
- Canny边缘检测-Wiki
Canny edge dector 由 John F. Canny 在1986年提出. Canny 算法的发展 Canny算法的步骤 2.1 降噪 2.2 寻找图像的亮度梯度 2.3 非极大值抑制 2 ...
- ASP.NET最常用的页面生命周期事件
PreInit:在页生命周期的早期阶段可以访问的事件.在PreInit事件后,将加载个性化信息和页主题. Init:在所有的控件都已初始化,且已应用所有外观设置后引发.使用该事件来读取或初始化控件属性 ...
- 【HDOJ】2267 How Many People Can Survive
BFS. #include <iostream> #include <cstdio> #include <cstring> #include <queue&g ...
- 揭开Linux操作系统的Swap交换区之谜
揭开Linux操作系统的Swap交换区之谜 Swap,即交换区,除了安装Linux的时候,有多少人关心过它呢?其实,Swap的调整对Linux服务器,特别是Web服务器的性能至关重要.通过调整Swap ...
- a great tool for automatically formating your code!
1. make your own format file at your project's root or file's folder. (The clang-format will automat ...
- a trick in reading and storing file in the exact way!
read and write file is a very common operation regarding file mainuplation. However, the powerfull g ...
- bzoj2724
分块大法好!首先预处理第i块到第j块的答案,这是可以在O(n*tot)内处理出来的 tot表示块数然后考虑询问对于[l,r],答案只可能是[l,r]之间所夹整块[i,j]的答案和非整块中的位置上的数下 ...
- 洛谷2344 奶牛抗议(DP+BIT+离散化)
洛谷2344 奶牛抗议 本题地址:http://www.luogu.org/problem/show?pid=2344 题目背景 Generic Cow Protests, 2011 Feb 题目描述 ...
- 敏捷开发 and 敏捷测试
名词解释 agile: 敏捷的:灵活:敏捷开发. scrum: 扭打,混打:并列争球:参加并列争球. sprint: 冲刺,全速跑. backlog: 积压的工作:积压待办的事务. retrospe ...