Java Export PDF file data

Source: Internet
Author: User

tip: Exporting a PDF file requires 3 jar package Itext-2.1.5.jar,itextasian.jar,itext-rtf-2.1.4.jar. 

Public BooleanOutputpdfjhsy (Entitybean data) {Try{global.getinstance (). Logapp ("Export PDF Start"); String Pdfpath= File.get ("Leap/nsestmodule/wrmodule/nsjhsyzm.pdf"). GetAbsolutePath (); //Get the PDF template path from the Eclipse folder String Imgpath= File.get ("Leap/nsestmodule/wrmodule/image/weiji.gif"). GetAbsolutePath (); //Bottom right corner stamped picture pdfreader reader = new Pdfreader (Pdfpath); //Create an Output directoryString Pdfsavepath = Nameedpathutil.getpath ("default") + "nsestpdf/"; File.get (Pdfsavepath). mkdir (); String filename= Global.getinstance (). Getuuid () + ". pdf"; Pdfsavepath= pdfsavepath+filename; Pdfstamper Stamp=NewPdfstamper (Reader,NewFileOutputStream (Pdfsavepath)); //get the top content section of the first pagePdfcontentbyte over = stamp.getovercontent (1); //Get table fields (with Adobe Acrobat Pro Tools)Acrofields form =stamp.getacrofields ();SimpleDateFormat SDF2=NewSimpleDateFormat ("yyyy mm month DD Day"); Entitybean Bean=data; Try{Form.setfield ("Busino", Bean.getstring ("Busino")); Form.setfield ("JSBM", Bean.getstring ("JSBM")); Form.setfield ("Wname", Bean.getstring ("Wname")); Form.setfield ("Wsfz", Bean.getstring ("Wsfz")); Form.setfield ("Mname", Bean.getstring ("Mname")); Form.setfield ("Msfz", Bean.getstring ("Msfz")); Form.setfield ("Whjd", Bean.getstring ("Whjd")); Form.setfield ("Wxjzd", Bean.getstring ("Wxjzd")); Form.setfield ("Hyzk", Bean.getstring ("Hyzk")); Form.setfield ("Jsqk", Bean.getstring ("Jsqk")); Form.setfield ("Zncount", Bean.getstring ("Zncount")); Form.setfield ("Znqk", Bean.getstring ("Znqk")); Form.setfield ("Slrq", Sdf2.format (Sdf.parse (bean.getstring ("SLRQ"))) ) ); Form.setfield ("Wfjhsyzc", Bean.getstring ("Wfjhsyzc")); Form.setfield ("Qtsm", Bean.getstring ("QTSM")); Form.setfield ("Wname2", Bean.getstring ("Wname2")); Form.setfield ("Wsfz2", Bean.getstring ("WSFZ2")); Form.setfield ("Zmlxname", Bean.getstring ("Zmlxname")); Form.setfield ("JBr", Bean.getstring ("JBR")); Form.setfield ("Lxdh", Bean.getstring ("Lxdh")); Form.setfield ("Sprq", Bean.getstring ("Sprq")); } Catch(Exception e) {global.getinstance (). Logapp ("Insert PDF form Field exception"); E.printstacktrace (); } stamp.setformflattening (true);//This sentence must not be less//Create an Image objectImage image =image.getinstance (Imgpath); //sets the output position of the Image object Pa.getasnumber (Pa.size ()-1). Floatvalue () is the maximum value of the y-axis of the page's PDF axisImage.setabsoluteposition (398,170); Image.scalepercent (70); Over.addimage (image); Over.stroke (); Stamp.close (); global.getinstance (). Logapp ("Export PDF End"); } Catch(FileNotFoundException e) {global.getinstance (). Logapp ("Exception 1"); E.printstacktrace (); return false; } Catch(documentexception e) {global.getinstance (). Logapp ("Exception 2"); E.printstacktrace (); return false; } Catch(IOException e) {global.getinstance (). Logapp ("Exception 3"); E.printstacktrace (); return false; } finally { } return true; }

Java Export PDF file data

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.