Page 1 of 1

Trying out flow() in pdf-css

Posted: Fri Nov 13, 2015 5:09 pm
by Glimmerino
I'm currently trying out the pdf-css plugin wit the free version of prince xml. I can't however get the flow function to work. I want to put certain map metadata in the page header but I want to style the data differently. I think the right way to approach it is to use the flow () thing. But I can't get this to work. My code currently looks like:

*[class ~= "map/map"][title] {
flow: static(maptitle);

}

@page :right{
@top-right {
content: flow(maptitle);
}
@bottom-right {
/**/
}
@bottom-left {
/**/
}
}

The map title does, however, not show.

Best regards
Kristian Wennberg

Re: Trying out flow() in pdf-css

Posted: Mon Nov 16, 2015 1:34 pm
by Dan
Hello,

By using "flow", you effectively remove the element from the normal flow and you are moving it into a static part of the page. See:
http://www.princexml.com/doc/8.1/proper ... ince-flow/
http://www.princexml.com/doc/8.1/page-headers-footers/

So you are moving the entire bookmap into the top of the page (*[class ~= "map/map"][title] matches possibly the entire map), which is not ok.

I recommend generating a new XML element that contains the title that can be moved to the page header. In the stylesheet:

frameworks/dita/DITA-OT/plugins/com.oxygenxml.pdf.css/post-process.xsl

You should modify the template that generates the <oxy:front-page> element and generate another element before it, let's name it <oxy:title-to-move-to-headers>. This contains the book title text:

Code: Select all


   <!--

Create a title page

-->
<xsl:template match="*[contains(@class, ' map/map ')]">
<xsl:copy>
<xsl:copy-of select="@*"/>

<!-- INSERT THIS -->
<oxy:title-to-move-to-headers>
<xsl:choose>
<xsl:when test="@title">
<xsl:value-of select="@title"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates
select="opentopic:map/*[contains(@class, ' topic/title ')]"/>
</xsl:otherwise>
</xsl:choose>
</oxy:title-to-move-to-headers>
<!-- END INSERT -->

<oxy:front-page>
<oxy:front-page-title>
<xsl:choose>
Then modify the CSS:
frameworks\dita\css\print\p-page-titles-and-numbers.css to have this content:

Code: Select all


@media print {

title-to-move-to-headers {
flow: static(th);
}

@page :left {
@top-left {
content:flow(th);
}
}

@page :right{
@top-right {
content:flow(th);
}
}
}
Please note that there are similar files in the DITA-OT installations, but these are used only when running the DITA-OT transformations from the command line, not from oXygen.
frameworks\dita\DITA-OT\plugins\com.oxygenxml.pdf.css\css\print\p-page-titles-and-numbers.css
frameworks\dita\DITA-OT2x\plugins\com.oxygenxml.pdf.css\css\print\p-page-titles-and-numbers.css

As a general rule, when testing CSS extensions, try with very small documents, not necessarily related to DITA.


Cheers,
Dan

Re: Trying out flow() in pdf-css

Posted: Mon Nov 16, 2015 6:16 pm
by Glimmerino
Thank you Dan for making things clearer. There are however two issues that I still struggle with.

The code you suggested adds a blank first page. How do I get rid of it without loosing the "title to move to headers variable"?

Even though the flow-thing now works it does not solve my core problem and that is that I want to style content differently in the same @page region. For example my company header consist of two line of text: "Company Classification" and directly beneath this line is the actual classification (could be RESTRICTED/CLASSIFIED/OPEN). These two text lines shall have different font size. Thats the reason for the individual formatting.

I guess "Company Classification " could be defined as an xsl-variable with static content. And then flowed just like the earlier example. However, it looks like its not possible to flow different elements to the same page-region.

Regards
Kristian

Re: Trying out flow() in pdf-css

Posted: Tue Nov 17, 2015 12:05 pm
by Dan
Hello Kristian,

1. For the first problem, move the <oxy:title-to-move-to-headers> inside <oxy:front-page-title>.

Code: Select all


 <xsl:template match="*[contains(@class, ' map/map ')]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<oxy:front-page>
<oxy:front-page-title>
<xsl:choose>
<xsl:when test="@title">
<xsl:value-of select="@title"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates
select="opentopic:map/*[contains(@class, ' topic/title ')]"/>
</xsl:otherwise>
</xsl:choose>
<oxy:title-to-move-to-headers>
<xsl:choose>
<xsl:when test="@title">
<xsl:value-of select="@title"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates
select="opentopic:map/*[contains(@class, ' topic/title ')]"/>
</xsl:otherwise>
</xsl:choose>
</oxy:title-to-move-to-headers>

</oxy:front-page-title>
</oxy:front-page>
..............
2. For the second problem, regarding styling differently parts of the header, why don't you generate from XSLT a more complex content for the <oxy:title-to-move-to-headers>, and then style each of the elements individually from CSS?


Cheers,
Dan