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读取该 ...
随机推荐
- 转:SSDB:快速取代redis的nosql
原文来自于:http://hao.jobbole.com/ssdb%EF%BC%9A%E5%BF%AB%E9%80%9F%E5%8F%96%E4%BB%A3redis%E7%9A%84nosql/ S ...
- JAVA循环结合标签使用,控制跳转
public static void main(String[] args) { outer: for (int i = 0; true; i++) { inner: for (int j = 0; ...
- C++ Primer 随笔 Chapter 9 顺序容器
参考:http://www.cnblogs.com/kurtwang/archive/2010/08/19/1802912.html 1..顺序容器:vector(快速随机访问):list(快速插入 ...
- AC+DP练习
1.HDU 2222 Keywords Search 求目标串中出现了几个模式串. #include<iostream> #include<cstdio> #include&l ...
- 1A Theatre Square
题目大意; 有一个广场,广场的大小是n*m, 有a*a的石砖,石砖铺广场可以比广场大,石砖不能切割.问最少需要多少个石砖. ===================================== ...
- 数学(FFT):BZOJ 3527 [Zjoi2014]力
题目在这里:http://wenku.baidu.com/link?url=X4j8NM14MMYo8Q7uPE7-7GjO2_TXnMFA2azEbBh4pDf7HCENM3-hPEl4mzoe2w ...
- Invert Binary Tree——LeetCode
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
- ubuntu 下修改host文件
原文地址:http://www.cnblogs.com/kingcat/archive/2012/02/23/2364509.html 有些时候,我们需要让某些域名指向本地,来实现调试,下面介绍下ub ...
- Apache multiple domains setup
Running several name-based web sites on a single IP address. Your server has a single IP address, an ...
- rpm常用操作
1.查询.检查软件包 rpm {-q|--query} [select-options] [query-options] rpm {-V|--verify} [select-options] [ver ...