css for print via xsl-fo - xmlcss for print via xsl-fo start/end indents css block à xsl-fo block...

34
George Bina [email protected] @georgebina #xmlprague CSS for Print via XSL-FO Dan Caprioara [email protected] developed by presented by

Upload: others

Post on 26-Nov-2020

35 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

George Bina [email protected]

@georgebina

#xmlprague

CSS for Print via XSL-FO

Dan Caprioara [email protected]

developed by

presented by

Page 2: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Motivation XSL-FO is a good option for generating PDF

but… it is not easy to customize!

Page 3: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Usual XSL-FO systems

Transform to XSL-FO

XML

XSLT

XSL-FO

FOP

PDF

Page 4: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Solution Provide an easy customization layer for

generating XSL-FO!

Page 5: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Proposed XSL-FO systems

Convert to XSL-FO

XML

CSS

XSL-FO

FOP

PDF

Use CSS as the easy customization layer to control the XSL-FO generation!

Page 6: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Example CSS customizations Define page properties Title formatting Watermarks Multiple columns

Page 7: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Page properties @page {

size:a4; margin: 1.3in; @top-left-corner { content:" "; background-color:silver; border-left:10pt solid white; padding: 1em; border-bottom: 0.3in solid white; } @top-left { background-color:silver; font-size: 1.5em; font-weight:bold; font-family: sans-serif; content: string(article-title); padding-left:1em; color:white; border-bottom: 0.3in solid white; } @top-right-corner{ background-color:red; color:white; font-size:large; content: counter(page); text-align: center; vertical-align: middle; border-bottom: 0.3in solid white; } }

Page 8: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Title formatting

@import url('https://fonts.googleapis.com/css?family=Lato:300,300i,400,400i,700,700i,900,900i'); title { font-weight: bold; color: blue; font-family: 'Lato', sans-serif; } section > title:before{ content: counter(sect) ". "; }

Page 9: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Title formatting

title:before { content:none!important; } title { text-align:center; }

Page 10: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Watermarks

background-image:url('draft.png'); background-repeat:no-repeat; background-position:center;

Page 11: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Multiple columns

column-count : 2; column-gap : 2em;

Page 12: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

CSS and XSL-FO While some properties are similar there are a

number of differences between XML+CSS and XSL-FO

Page 13: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Impedance mismatch between XML+CSS and XSL-FO

Different page regions Nested elements on separate pages Start/end indents for blocks and block containers Font management

Page 14: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Different page regions

main page area

top-left corner

top-right corner

left-middle

right-middle

top-center

body

region-start

CSS XSL-FO

top-left top-right

bottom-left

bottom-right

bottom-center

bottom-right corner

bottom-left corner

left-top

left-bottom

right-top

right-bottom

region-end

region-before

region-after

Page 15: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Nested elements on separate pages

<article> … <section> … </section> <section> … </section> … </article>

section { /* Each section is in its own page. */ page:sectionPage; }

<article> … </article> <article> <section> … </section> </article> <article> <section> … </section> </article> <article> … </article>

Page 16: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative to the

nearest ancestor block container, ignoring ancestor blocks…

Page 17: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Font management CSS font specifications will go into generated

FOP configuration files, not only in XSL-FO

Page 18: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

XSL-FO and FOP Some of the XSL-FO functionality is not supported

by the FO Processor or works incorrectly

Page 19: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

XML+CSS via XSL-FO to PDF

Annotate XML with CSS properties XML

CSS Slice the document into pages

Transform to XSL-FO

XSL-FO

FOP

PDF

Page 20: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Annotate XML with CSS CSS properties added as attributes CSS content added as elements

•  static before/after pseudo-elements •  counters •  other static content

Add page metadata

Page 21: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Annotate with CSS properties

<article> …

</article>

article { display:block;

}

<article css:display="block” …>

… </article>

Page 22: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Annotation elements for content <section> <title>Processor</title> </section>

section, title { display:block; } title:before {

color:green; content: "Title:";

}

<section xmlns:css="http://www.w3.org/1998/CSS" css:display="block" css:font-family="sansserif"

css:font-size="12pt"> <title css:display="block"> <css:before

css:display="inline" css:color="green"> <css:text>Title:</css:text> </css:before> Processor

</title> </section>

Page 23: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Add page metadata

<css:pages>

<css:page>

<css:property name="width" value="8.27in"/>

<css:property name="height" value="11.69in"/>

<css:property name="margin-top" value="0.5in"/>

<css:property name="margin-right" value="0.5in"/>

<css:property name="margin-left" value="0.5in"/>

<css:property name="margin-bottom" value="0.5in"/>

</css:page>

</css:pages>

@page { size: A4; margin: 0.5in;

}

Page 24: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Special considerations Defaults Implicit rules Inherited CSS properties @media rules

Page 25: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Slice the document into pages Get ready for transformation to XSL-FO

•  Wrap everything in a root element •  Create page-sequence containers for each set of

pages

Page 26: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Slice into page sequences <css:root xmlns:css="http://www.w3.org/1998/CSS" xmlns="http://docbook.org/ns/docbook"> <css:pages> <css:page name="section_page"> <css:property name="margin-left" value="2cm"/> </css:page> </css:pages> <css:page-sequence page="css2fo-default"> <article version="5.0" css:display="block" css:font-family="sansserif" css:font-size="12pt"> <title css:display="block" css:font-size="20pt">Sample</title> </article> </css:page-sequence> <css:page-sequence page="section_page"> <article version="5.0" css:display="block" css:font-family="sansserif" css:font-size="12pt"> <section css:display="block"> <title css:display="block" css:font-size="20pt">Introduction</title> </section> </article> </css:page-sequence> <css:page-sequence page="section_page"> <article version="5.0" css:display="block" css:font-family="sansserif" css:font-size="12pt"> <section css:display="block"> <title css:display="block" css:font-size="20pt">Content</title> </section> </article> </css:page-sequence> <css:page-sequence page="css2fo-default"> <article version="5.0" css:display="block" css:font-family="sansserif" css:font-size="12pt"> <acknowledgements css:display="block"> <para css:display="block">Thanks!</para> </acknowledgements> </article> </css:page-sequence> </css:root>

<article xmlns="http://docbook.org/ns/docbook" version="5.0" xmlns:css="http://www.w3.org/1998/CSS"

css:display="block" css:font-family="sansserif" css:font-size="12pt">

<title css:display="block" css:font-size="20pt"> Sample

</title> <section css:display="block" css:page="section_page"> <title css:display="block" css:font-size="20pt">

Introduction </title> </section> <section css:display="block" css:page="section_page"> <title css:display="block" css:font-size="20pt">

Content </title> </section> <acknowledgements css:display="block"> <para css:display="block">Thanks!</para> </acknowledgements> </article>

<css:pages> <css:page name="section_page"> <css:property name="margin-left" value="2cm"/> </css:page> </css:pages>

Page 27: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Transform to XSL-FO XSLT Processing Applied on CSS annotations

the original element names are not relevant for this conversion

<xsl:template match="*[@css:display = 'inline'"> <fo:inline> <xsl:apply-templates select="@* except @css:display | node()"/> </fo:inline> </xsl:template>

Page 28: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Apply FOP to generate PDF

Annotate XML with CSS properties XML

CSS Slice the document into pages

Transform to XSL-FO

XSL-FO

FOP

PDF

FOP Configuration File

Page 29: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Advanced CSS support oXygen CSS engine supports

•  :has() section:has(title) {…}

•  multiple before and after pseudo-elements section::before(100) {…}

•  XPath extension function oxy_xpath("count(preceding-sibling::*)")

Page 30: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Example Add word and character count after each section

paragraph

section > para:after(10) { color:gray; font-size:0.8em; content: " (" oxy_xpath('count(tokenize(normalize-space(.), " "))') " words)"; } section > para:after(12) { color:gray; font-size:0.8em; content: " (" oxy_xpath('string-length(normalize-space(.))') " characters)"; }

Page 31: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Page 32: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Related work CSSToXSLFO

http://www.re.be/css2xslfo/index.xhtml PrinceXML

https://www.princexml.com/ AntennaHouse

http://www.antennahouse.com/ PDF Reactor

http://www.pdfreactor.com/ Vivlyostyle

http://vivliostyle.com/

Page 33: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Takeaways CSS can be the easy customization layer for

generating XSL-FO CSS may not solve all the customization

requirements in general, but for technical documentation it should be enough

Although there are a number of impedance mismatches between CSS and XSL-FO there are ways to solve them

Page 34: CSS for Print via XSL-FO - XMLCSS for Print via XSL-FO Start/end indents CSS block à XSL-FO block CSS block with width à XSL-FO block container Indent on a block container is relative

@georgebina #xmlprague Copyright @ Syncro Soft, 2017. All rights reserved.

CSS for Print via XSL-FO

Thank you

Questions? [email protected] @georgebina http://www.oxygenxml.com