[COCOON JFOR] Convert FO to RTF Format Documentation
Before you continue to read, we assume that you are familiar with the following knowledge, or you can refer to the appendices later in this article:
N Cocoon (one of the eight sub-projects in the XML project of Apache)
N xsl formatting objects (xsl-fo)
n FOP (Formatting Objects Processor)
n jf (Open-Source Java XSL-FO TO RTF Converter)
Key words:
Cocoon, JFOR, XML, XSL-FO
Summary:
For how to convert the PDF format document to a Word document, our idea is that you can: pdfàfoàrtf.
First, let's see how to convert FO to the RTF format. We can make Cocoon JFOR do this.
Overview
We already know that using WH2FO and FOP can successfully convert Word2000 documents to PDF format documents.
The first step is converted to XSL-FO, and the specific OpenSource can be found at http://www-uk.hpl.hp.com/people/fabgia/wh2fo/wh2fo.html.
In the second step, according to http://www-900.ibm.com/developerworks/cn/xml/x-xslfo2app/index.shtml
Guide, convert XSL-FO to PDF.
Simple command example:
> java org.apache.fop.Apps.fop everything.fo everyhes.pdf
Or after the FOP (http://apache.linux process/dist/xml/fop/) is installed, run:
FOP.CMD Sample.fo Sample.pdf
You can output the PDF file.
So how do we do it in turn? Convert PDF files to Word files.
There is no direct way to Microsoft KB, and their suggestion is that you open the PDF file with Acrobat Reader 5.0, paste the required content to Word with the copy text or Copy Image command. Some people claim that you can use Acrobat Reader 5.0 as an RTF format.
How To: Convert Adobe Acrobat Reader (* .pdf) Files in Word 2002 (290927)
- This Article Explains How To Convert A Portable Document Format (PDF) Document from Adobe Acrobat Reader to Microsoft Word.
Pdfàfoàrtf
Our idea is that it can be like this: pdfàfoàrtf.
First, let's see how to convert FO to the RTF format. We can make Cocoon JFor to do this:
Install COCOON:
Install Cocoon is relatively simple. Divide several steps:
The first step, install JDK:
Make sure your JDK version is high enough, mine is J2SDK1.4.2_02; then set java_home as the JDK directory, or run commands:
Set java_home = f: /j2sdk1.4.2_02
Step 2, install COCOON:
Download Cocoon 2.1.3:
The Latest Source Distribution (Cocoon 2.1.3):
· TAR / GZIP FORMAT (UNIX Platforms): Cocoon-Latest-src.tar.gz · Zip Format (Windows Platforms): Cocoon-laTest-src.zip
After decompression, run the build.bat under COCOON-2.1.3, to compile Cocoon:
E: /COCOON-2.1.3> Build
USING JAVA from f: /j2sdk1.4.2_02/
Buildfile: build.xml
Prepare:
----------------------------------- ----------
Apache Cocoon 2.1.3 [1999-2003]
----------------------------------- ----------
Building with apache ant version 1.5.4 Compiled on August 12 2003
...
...
Validate-jars:
Copying 1 File to E: /COCOON-2.1.3/build/cocoon-2.1.3/temp
VALIDATE-Config:
Validating Configuration FILES
Validating Cocoon.xconf Using a Very Basic Relax Ng Grammar ...
Build Successful
Total Time: 2 minutes 30 seconds
After the compilation is successful, we can try Cocoon's effect.
Step 3, start COCOON:
Essentially, Cocoon is still a servlet. Run Cocoon.bat under Cocoon-2.1.3, to start COCOON:
E: /COCOON-2.1.3> Cocoon servlet
Cocoon.bat: using ./build/webapp as the WebApp Directory
So, there was a Cocoon's run window:
Let's try the effect: Open IE, type
Http: // localhost: 8888
You can see:
Okay, everything is normal.
Now, we have to try the conversion of foàrtf. The premise is that the JFOR package must be placed under Cocoon.
Step 4, install JFOR to COCOON:
Official website from JFOR
http://www.jfor.org/
Download the JFOR binary package. address is:
http://prdownloads.sourceforge.net/jfor/jfor-0.7.2rc1.jar?download
Download JFOR-0.7.2rc1.jar and put it in
Cocoon-2.1.3 / lib / opt
Subfolder.
Then re-build Cocoon, step in the second step.
Start Cocoon Servlet again.
The fifth step, an example of XMLàrtf:
in
Cocoon-2.1.3 / build / webapp /
Enclose a folder in the directory, such as the name is called "RTFDemo".
Establish such documents:
SiteMap.xmap
XML Version = "1.0"?>
map: view>
map: view>
map: view>
map: views>
map: match>
map: pipeline>
map: pipelines>
map: Sitemap>
SiteMap.xmap is a current site configuration, it is very important. "Map: Match" node indicates how to convert it.
Create a new subfolder Fo, where you are putting such a file:
Hello.xml
XML Version = "1.0" encoding = "GB2312"?>
content>
page>
with
Page2fo.xsl
XML Version = "1.0"?>
XMLns: XSL = "http://www.w3.org/1999/xsl/transform" XMLns: fo = "http://www.w3.org/1999/xsl/format"> Page-heiGHT = "29.7cm" Page-width = "21cm" Margin-top = "1cm" Margin-bottom = "2cm" Margin-left = "2.5cm" Margin-right = "2.5cm"> fo: Simple-page-master> fo: REPEATABLE-Page-Master-Alternatives> fo: Page-Sequence-Master> fo: layout-master-set> Font-size = "10pt" Font-family = "serif" Line-height = "14pt"> Page fo: static-content> fo: flow> fo: Page-Sequence> fo: root> xsl: template> xsl: template> xsl: template> xsl: stylesheet> Ok, everything is ready. Browse Http: // localhost: 8888 / RTFDemo / Hello.rtf You can see the output of the RTF version, you can save it as hello.rtf: At the same time, Cocoon's window also outputs this process: 12: 39: 40.852 Event Started SocketListener on 0.0.0.0:8888 12: 39: 40.852 Event Started Org.MortBay.jetty.server@1037c71 JFOR.INFO: JFOR V0.7.1 - Setting Up Conversion ... JFOR.INFO: PARSING XSL: FO Document ... JFOR.INFO: Writing Out RTF ... JFOR.INFO: DONE CONVERTING XSL: FO TO RTF. JFOR.DEBUG: Conversion Took 80 MilliseConds. JFOR.INFO: JFOR V0.7.1 - Setting Up Conversion ... JFOR.INFO: PARSING XSL: FO Document ... Ok, XMLàrtf is implemented using Cocoon Jfor. However, this is the first step in the Long March. to be continued. Abbreviated language list: COCOON: CoCoon is one of the eight submersible in the XML project of the Apache, and CoCoon is an XML release framework according to the official definition of Apache. It allows you to define the conversion of XML documents and documents, and eventually generate the form of the form you choose, such as HTML, PDF, SVG, VRML, and more. In addition, Cocoon enables you to add processing logic in the XML file, thus a dynamic characteristic of the XML pipe. Official Homepage: http://cocoon.apache.org/ XSL-fo: The XSL formatted object specification is formal recommendations for W3C, commonly referred to as XSL-FO, XSL-FO defines many XML tags, which describes how to display content. XSL-FO documents define a few things that are very important when making high quality printable documents: · Information about the actual size of the page (stationery and A4, etc.) · Information about page margins (top, left, bottom, and right), header and footer and other features of the page · Information about text, font size, color, and other features · The actual text to be printed, by the description paragraph, highlight, the elements of analogs, etc. Study the XSL-FO specification on the W3C site (W3.org/tr/xsl) (400 pages in total). For more general information about XSL-FO, please visit the W3C Style page located at the w3.org/style/xsl/. XSL-FO Detailed tutorial: http://www-900.ibm.com/developerWorks/cn/cnedu.nsf/xml-onlinecourse-bytitle/3b308072632f949fc8256d320006ca3f?opendocument FOP FOP (Formatting Objects Processor) is the first XSL: FO-based print format processor and the first format processor that is unrelated to the output. It is a Java program that can read in the object tree and generate rendered pages to output to the specified stream. The currently supported output format has PDF, PCL, PS, SVG, XML (represented by tree structure), printer, AWT, MIF, and TXT. The main output refers to PDF. James Tauber - the original author of FOP. He developed the original version of the tool, and opened the code very generously, and then handed it to Apache XML Project. Download the Apache XML project's FOP package from XML.Apache.org/dist/fop. FO tool JFOR (Java XSL-FO TO RTF Converter) Converts XML documents in accordance with XSL-FO to RTF (Rich-TEXT FORMAT), which is intended to convert XSL-FO (usually using XSLT generation) documents to PDF ( Similar to FOP or other similar tools).