XSL-FO Study Notes (1)

Source: Internet
Author: User
Tags xsl xslt xslt processor acrobat distiller
XSL-FO Study Notes (1)

Being able to generate PDF files is always mysterious to me. I used previously to generate a PDF file. 1) Open the relevant file with the corresponding software and print it to a file, such as Ali. PRN, and then manually set Ali. change PRN to Ali. PS, and then use gostview to open Ali. PS, and finally use its convert function to generate a PDF file, there is a certain rate of failure; 2) using Acrobat Distiller; 3) using Acrobat into writer.

I am always excited that I can use XSL-FO and Apache fop programming.

1. Download and install and run fop

Go to the FOP homepage to download fop. There are two versions: The maintenance version, the design version, and the maintenance version 0.20.5 Binary Package. Decompress the package to $ fophome, which contains fop. CMD (for Windows) or fop. Sh (for * nix ).

Download the sample. Fo file from here and run

FOP. CMD sample. Fo sample.pdf

, Okto generate sample.pdf.

2. There are two basic steps to convert an XML document to a PDF file:

1) Use An XSLT style sheet to convert an XML document into a file consisting of XSL-FO elements. To perform this conversion, you only need to call the XSLT processor.

2) use a display engine to convert XSL-FO elements to PDF files.

3. The XSL-FO document defines several important things when creating high-quality printable documents:

1) information about the actual page size (such as letterhead and A4)

2) information about margin (top, left, bottom, and right), header and footer, and other page features

3) text font, font size, color, and other features

4) The actual text to be printed is marked by the elements that describe paragraphs, highlights, tables, and other similar things.

4. XSL-FO document structure


<FO: root> elements include <FO: Layout-master-set> and <FO: page-sequence>.

<FO: Layout-master-set> usually contains information about the page layout, while <FO: page-sequence> contains the actual content you are formatting.

5. Examples

Sample. fo Description
<FO: Root xmlns: fo = "http://www.w3.org/1999/XSL/Format"> The root element <FO: root> and fo are the prefix of the namespace, which contains <FO: Layout-master-set> and then one or more <FO: page-sequence>.
<FO: Layout-master-set> Specify the page definition. You can use the <FO: simple-page-master> element to define each page layout.
<FO: simple-page-master-name = "Main" Defines the layout of a specific page. maste-name is the Master name of the page.
Margin-Top = "36pt" margin-Bottom = "36pt" Top and bottom margin of the page
Page-width = "8.5in" Page-Height = "11in" Actual page width and height
Margin-Left = "72pt" margin-Right = "72pt"> Page margins
<FO: Region-body margin-Bottom = "50pt" margin-Top = "50pt"/> Defines the top and bottom margins for the region-body area with a length of 50 points. The page also contains the region-before/region-after/region-Start/region-end area.
</FO: simple-page-master>
</FO: Layout-master-set>
<FO: page-sequence master-reference = "Main"> <FO: page-sequence> defines the sequence of page la s used in the document. Here, main is used for all pages.
<FO: Flow flow-name = "XSL-region-Body"> <FO: flow> defines the content displayed in a specified area. Because the Display Engine (such as FOP) can automatically or calculate line breaks, bars, and page breaks based on specified rules, it is called a stream.
<FO: block font-size = "14pt" line-Height = "17pt"> <FO: block> is the most basic element used to format a text block. It is similar to the P element in HTML. <FO: block> elements always generate a line break. The font size and row height are defined here, And the row spacing is 3. The value is generally 3-6.
This is a paragraph of text. notice that
<FO: inline font-style = "italic"> this meaningless <FO: inline> new text features are defined in the existing <FO: block>.
Prose </FO: inline> drones on and on, the fop
Software automatically calculates line breaks for us.
Isn' t that fascinating?
</FO: block>
</FO: flow>
</FO: page-sequence>
</FO: root>

6. Two Concepts

Layout mainly sets information related to paper. A page is the area used for printing. The page is divided into five regions, such as the right figure. In the above example, only the region-body area is used.

7. The unit of distance in XSL-fo

Unit Description
Cm Centimeter
Mm Millimeters
In Inch
PT Point (72 points = 1 inch)
PC Dispatch card (= 1 dispatch card, 6 dispatch card = 1 inch)
Px Pixels (sometimes formattedProgramOr the device is different, so be careful to use)
Em Width of an uppercase m

8. <FO: inline> Elements

Font-Weight = "bold" is used for bold text, font-style = "italic" is used for italic text, and font-family = "monospace" is used for font-style text ".

9. elements
text-align/Text-align-last defines how text lines/last lines are aligned, the Value Sets of both are start, center, end, and justify, which respectively indicate left, center, right, and left-right alignment.
space-before and space-after are used to specify the spacing between the blocks before and after the block. You can attach a suffix such as. Minimum,. Maximum,. Optimum, And. precedence to obtain 10 attributes.
keep-with-Next, keep-with-previous, and keep-together are used to set display control with the front block, Back block, and in the block, can be assigned. within-line ,. within-column and. suffixes such as within-page can have 12 attributes. The value set is Auto/numeric/always, and the priority is from low to high.
Break-before and break-after define the delimiter placed before and after the block respectively, with five values, such as table

attribute value value
auto enable the Display Engine to process it
column place a column break before this block
page place a paging character before this block
odd-page the Display Engine inserts a paging character (or two, if necessary) so that this part starts on an odd page. In other words, if a page break causes this block to start on an even page, fop inserts the second page break.
even-page the Display Engine inserts a paging character (or two, if necessary) so that this part starts on an even page.

The widows feature defines the minimum number of lines that must appear together when a block is displayed at the bottom of the page. The default value is 2.

The orphans feature defines the minimum number of rows that must appear at the top of the next page when a block cannot be displayed on the current page. The default value is 2.

10. Graphics

You can use <FO: External-graphic src = "..."> to specify an external GIF/jpg/SVG file. The SVG file can be embedded into the fo file itself, and use <FO: instream-foreign-Object>. line breaks can only be generated when these elements are put separately in the block.

11. Horizontal line

Implemented by using <FO: Leader>. The leader-pattern attribute is available. You can set the value space, rule, and dots to blank, solid, and dotted. The leader-Length attribute indicates the length, by default, the same width of the feature column is used.

XSL-FO Study Notes (2)


References:

1. fop Homepage

Http://xml.apache.org/fop/

2. Basic knowledge of XSL Formatting object (XSL-FO)

Http://www-900.ibm.com/developerWorks/cn/cnedu.nsf/xml-onlinecourse-bytitle/3B308072632F949FC8256D320006CA3F? OpenDocument

3. XSL specifications

Http://www.w3.org/TR/xsl/Overview.html

Posted by Hilton at September 19,200 3 pm | trackback

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.