Formatting Objects

23
Formatting Objects http://apache.roweboat.net/xml/ fop/
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    223
  • download

    1

Transcript of Formatting Objects

Formatting Objects

http://apache.roweboat.net/xml/fop/

What is it? Why would I use it?

• FOP (Formatting Objects Processor) is the world's first print formatter driven by XSL formatting objects (XSL-FO) and the world's first output independent formatter. It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output. Output formats currently supported include PDF, PCL, PS, SVG, XML (area tree representation), Print, AWT, MIF and TXT. The primary output target is PDF.

More about FOP

• FOP (Formatting Objects Processor) is the world's first print formatter driven by XSL formatting objects (XSL-FO) and the world's first output independent formatter. It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output. Output formats currently supported include PDF, PCL, PS, SVG, XML (area tree representation), Print, AWT, MIF and TXT. The primary output target is PDF.

downloads

• You’ll have to download FOP from xml.apache.org/fop

• FOP uses Xalan and Xerces parsers.

• FOP includes java programs for which you’ll need J2SE

the batch file

• The FOP download includes a batch file FOP.bat.

• To run this, build a DOS prompt to point to the FOP directory (FOP-0.20.5 is the version number for the directory I downloaded on 8/12/05)

• The FOP batch file expects the name of an fo file as the first (input) parameter and a pdf as the second (output) parameter.

OPTIONS

• -d debug mode -x dump configuration settings -q quiet mode -c cfg.xml use additional configuration file cfg.xml -l lang the language to use for user information -s (-at output) omit tree below block areas -txt.encoding (-txt output encoding use the encoding for the output file. The encoding must be a valid java encoding. -o [password] pdf file will be encrypted with option owner password -u [password] pdf file will be encrypted with option user password -noprint pdf file will be encrypted without printing permission -nocopy pdf file will be encrypted without copy content permission -noedit pdf file will be encrypted without edit content permission -noannotations pdf file will be encrypted without edit annotation permission

[INPUT]

• infile XSLFO input file (the same as the next)

-fo infile xsl:fo input file

-xml infile xml input file, must be used together with -xsl

-xsl stylesheet xslt stylesheet

[OUTPUT]

outfile input will be rendered as pdf file into outfile -pdf outfile input will be rendered as pdf file (outfile req'd) -

awt input will be displayed on screen -mif outfile input will be rendered as mif file (outfile req'd) -

pcl outfile input will be rendered as pcl file (outfile req'd) -ps outfile input will be rendered as PostScript file (outfile req'd)

-txt outfile input will be rendered as text file (outfile req'd) -svg outfile input will be rendered as an svg slides file (outfile req'd) -at outfile representation of area tree as XML (outfile req'd)

-print input file will be rendered and sent to the printer see print specific options with "-print help"

[Examples]

• fop foo.fo foo.pdf

• fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)

• fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf fop foo.fo -mif foo.mif fop foo.fo -print (or)

• fop -print foo.fo

• fop foo.fo -awt

your own batch files

• You may wish to make You may wish to make your own batch files (you’ll need to fix paths) to run xalan. This batch file requires 3 parameters, the xml file, the xsl file and a fo file:

java -classpath C:\xalan-j-current-bin\xalan-j_2_6_0\bin\xalan.jar;C:\xalan-j-current-bin\xalan-j_2_6_0\bin\xercesImpl.jar org.apache.xalan.xslt.Process -IN %1 -XSL %2 -OUT %3

A batch file to run fop – you’ll need to fix paths. This batch file requires 2 parameters

set LIBDIR=C:\fop\fop-0.20.5\libset LOCALCLASSPATH=C:\fop\fop-0.20.5\build\fop.jarSet LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xml-apis.jarset LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xercesImpl-

2.2.1.jarset LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\xalan-2.4.1.jarset LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\batik.jarset LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\avalon-

framework-cvs-20020806.jarset LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jimi-1.0.jarset LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_core.jarset LOCALCLASSPATH=%LOCALCLASSPATH%;%LIBDIR%\jai_codec.jarjava -cp "%LOCALCLASSPATH%" org.apache.fop.apps.Fop %1 %2

running FOP

simple.pdf created from simple.fo

simple.fo

• the file simple.fo is in the notes.

• typically a formatted object file would be built with a special editing tool.

• An fo file is an xml file, so it can have extension xml, xsl or fo (or whatever).

C:\pathtofop\>FOP readme.fo readme.pdf

fo file

• Xalan parser can produce an fo from xml using a stylesheet.

Running fop (excerpt from readme.pdf)

running fop on table.foC:\FIT\FOP-02~1.5>fop table.fo table.pdf[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser[INFO] FOP 0.20.5[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser[INFO] building formatting object tree[INFO] setting up fonts[INFO] [1][INFO] [2][INFO] [3][INFO] [4][INFO] [5][INFO] [6][INFO] [7][INFO] Parsing of document complete, stopping renderer

an fo table <fo:block text-align="start">this is normal text. this is normal text. this is normal text. this is normal text. this is normal text. this is

normal text. </fo:block> <!-- table start --> <fo:table table-layout="fixed"> <fo:table-column column-width="50mm"/> <fo:table-column column-width="50mm"/> <fo:table-column column-width="50mm"/> <fo:table-body> <fo:table-row> <fo:table-cell ><fo:block>good</fo:block></fo:table-cell> <fo:table-cell ><fo:block>bad</fo:block></fo:table-cell> <fo:table-cell ><fo:block>ugly</fo:block></fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell ><fo:block>nice</fo:block></fo:table-cell> <fo:table-cell ><fo:block>dice</fo:block></fo:table-cell> <fo:table-cell ><fo:block>vice</fo:block></fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell ><fo:block>literature</fo:block></fo:table-cell> <fo:table-cell ><fo:block>music</fo:block></fo:table-cell> <fo:table-cell ><fo:block>art</fo:block></fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell ><fo:block>java</fo:block></fo:table-cell> <fo:table-cell ><fo:block>perl</fo:block></fo:table-cell> <fo:table-cell ><fo:block>python</fo:block></fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> <!-- table end --> <!-- normal text --> <fo:block text-align="start">this is normal text. this is normal text. this is normal text. this is normal text. this is normal text. this is normal text. </fo:block>

table.pdf

fonts.fo to fonts.pdf

more fop: fo file in notes

Text examples don’t seem to work

Microsoft(R) Windows DOS(C)Copyright Microsoft Corp 1990-2001.

C:\FOP\FOP-02~1.5>fop topic_list.fo topics.pdf[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser[INFO] FOP 0.20.5[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser[INFO] building formatting object tree[INFO] setting up fonts[WARNING] A 'flow-name' is required for fo:flow. This constraint will be enforced in future versions of FOP[ERROR] file:/c:/fop/FOP-02~1.5/topic_list.fo:24:42 master-reference '' for fo:page-sequence matches no simple-page-master or page-sequence-master

C:\FOP\FOP-02~1.5>