Java and XML (6) XML conversion PDF (FO 2 PDF)

xiaoxiao2021-03-06  25

If there is a FO file, you can switch directly to PDF. The specific method is as follows: a FO file Simple.fo : this is a paragraph Notice That AS this means DRONES ON AND ON, THE FOP SOFTWARE Automatical Calculates Line Breaks for US. Isn't That fascinating?

Conversion function Foptest.java: postage src; import java.io. *; Import org.xml.sax.inputSource; import org.xml.sax.xmlreader; import org.apache.fop.apps. *; Public class foptest {PUBLIC Static void main (string [] args) {try {driver = new driver (); // set the FO file name to be converted //Driver.setInputSource (New InputSource (args [0])); Driver.setInputSource (New InputSource ("f: //tomcat5/WebApps//myxml//xmldata//simple.fo")); // Set the output file name //driver.setoutputstream (New FileoutputStream (Args [1])); driver. SetOutputStream ("F: //tomcat5/WebApps//MYXML//xmldata//simple1.pdf")); // Setting the conversion type // can also be render_pcl, render_ps, render_txt, render_mif driver.sethrenderer Driver.render_pdf); // Start conversion driver.run ();} catch (exception e) {E.PrintStackTrace ();}}} Compile execution. Reference: Holyfairholyfair@sina.com's XML file to RTF and PDF conversion

How to embed FOP in the program

转载请注明原文地址:https://www.9cbs.com/read-65111.html

New Post(0)