JAVA Read PDF file

Source: Internet
Author: User

First intersection 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");PD f.make (request,response,id); return null;}}

The Output method

/* * 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_fi    Le2=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 (); I Nputstream 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 Read PDF file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.