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