[xep-support] Re: Cooltool - Bookfolding an existing PDF

From: Kirch Fritz <Friedrich.Kirch@it2media.de>
Date: Tue Mar 31 2015 - 22:33:09 PST

Hi,

I've tested your folding stylesheet with the XEPUserGuide.pdf
Why is the folded PDF 2,003 KB while the initial PDF is only 1.470 KB?

Fritz Kirch
IT2media

Von: Xep-support [mailto:xep-support-bounces@renderx.com] Im Auftrag von Kevin Brown
Gesendet: Mittwoch, 1. April 2015 00:21
An: 'RenderX Community Support List'
Betreff: [xep-support] Cooltool - Bookfolding an existing PDF

Recently a few questions were asked about bookfolding. In the past we have presented a solution that used the RenderX Intermediate Format and shows how to bookfold a document before final output.

But what about a random PDF you have laying around? Well, with RenderX's new extension (rx:pdf-page) which can be used on <fo:external-graphic/> to select a specific page of a PDF to use as an image, we can create bookfolded output from any PDF you have.

Bookfolding is typically creating a booklet for saddle stitching, outputting the document by combining two pages into one in a specific order. When printed, this document can be combined, folded and stitched into a booklet. A good example is say you have a 10 page document, you would normally combine as follows (duplexed) with all pages twice the width of the original page:

10, 1 as page 1
2,9 as page 2
8,3 as page 3
4,7 as page 4
6, 5 as page 5

Sometimes you may not want to include the back or front pages as they are used for the cover. In this case you would have:

1 as page 1 as same size
9, 2 as page 2 double the width
3, 8 as page 3 double the width
7, 4 as page 4 double the width
5,6 as page 4 double the width
10 as page 10 as same size

So, lets say we have a PDF in hand (even page count of course) and we want to create a bookfolded document. We may create a simple XML file that describes this job as follows:

<bookfold>
    <document src="XEPUserGuide.pdf" cover="false"/>
    <pagewidth>8.27in</pagewidth>
    <pageheight>11in</pageheight>
    <pages>206</pages>
</bookfold>

This simple XML tells us what document to use, whether we want a cover or not and some information about that PDF. This information we need to feed the formatter to make sure the document size and pagination is correct. Using this simple XSL below, we can create a simple XSL FO that takes advantage of this new extension by placing the PDF pages into a new two column document using:

<fo:external-graphic rx:pdf-page="#" src="XEPUserGuide.pdf"/>

Give it a test. Send me any questions or enhancements.

[cid:image001.png@01D06C56.3FF65580]

We are working on a new update to Cloudformatter client which will include both PDF merging, stamping and this bookfolding among many other sample templates. And with Cloudformatter, you do not even need RenderX installed locally, it will format on the web and return the document to you.

Kevin Brown
RenderX

PS: http://www.cloudformatter.com/Nimbus is our free to use XSL Designer.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:rx="http://www.renderx.com/XSL/Extensions"
    version="1.0">
    <xsl:template match="/bookfold">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master page-width="{pagewidth}" page-height="{pageheight}" master-name="front">
                    <fo:region-body/>
                </fo:simple-page-master>
                <fo:simple-page-master page-width="2 * {pagewidth}" page-height="{pageheight}" master-name="all">
                    <fo:region-body column-count="2" column-gap="0in"/>
                </fo:simple-page-master>
                <fo:simple-page-master page-width="{pagewidth}" page-height="{pageheight}" master-name="back">
                    <fo:region-body/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <xsl:if test="document/@cover='true'">
                <fo:page-sequence master-reference="front">
                    <fo:flow flow-name="xsl-region-body">
                        <fo:block line-height="0">
                            <fo:external-graphic src="{document/@src}" rx:pdf-page="1"/>
                        </fo:block>
                    </fo:flow>
                </fo:page-sequence>
            </xsl:if>
            <fo:page-sequence master-reference="all">
                <fo:flow flow-name="xsl-region-body">
                    <xsl:call-template name="pages"/>
                </fo:flow>
            </fo:page-sequence>
            <xsl:if test="document/@cover='true'">
                <fo:page-sequence master-reference="back">
                    <fo:flow flow-name="xsl-region-body">
                        <fo:block line-height="0">
                            <fo:external-graphic src="{document/@src}" rx:pdf-page="{number(pages)}"/>
                        </fo:block>
                    </fo:flow>
                </fo:page-sequence>
            </xsl:if>
        </fo:root>
    </xsl:template>
    <xsl:template name="pages">
        <xsl:choose>
            <xsl:when test="document/@cover='true'">
                <xsl:call-template name="page">
                    <xsl:with-param name="pgleft" select="number(pages) - 1"/>
                    <xsl:with-param name="pgright" select="2"/>
                    <xsl:with-param name="odd" select="true()"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="page">
                    <xsl:with-param name="pgleft" select="number(pages)"/>
                    <xsl:with-param name="pgright" select="1"/>
                    <xsl:with-param name="odd" select="true()"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="page">
        <xsl:param name="pgleft"/>
        <xsl:param name="pgright"/>
        <xsl:param name="odd"/>
        <fo:block line-height="0">
            <fo:external-graphic src="{document/@src}" rx:pdf-page="{$pgleft}"/>
        </fo:block>
        <fo:block line-height="0">
            <fo:external-graphic src="{document/@src}" rx:pdf-page="{$pgright}"/>
        </fo:block>
        <xsl:if test="not(($pgleft - $pgright) = -1 or ($pgleft - $pgright) = 1)">
        <xsl:choose>
            <xsl:when test="$odd">
                <xsl:call-template name="page">
                    <xsl:with-param name="pgleft" select="$pgright + 1"/>
                    <xsl:with-param name="pgright" select="$pgleft - 1"/>
                    <xsl:with-param name="odd" select="false()"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="page">
                    <xsl:with-param name="pgleft" select="$pgright - 1"/>
                    <xsl:with-param name="pgright" select="$pgleft + 1"/>
                    <xsl:with-param name="odd" select="true()"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
        </xsl:if>

    </xsl:template>
</xsl:stylesheet>

**********************************************************************
Diese E-Mail wurde auf Viren ueberprueft.
mailsweeper@it2media.de
**********************************************************************

_______________________________________________
(*) To unsubscribe, please visit http://lists.renderx.com/mailman/options/xep-support
(*) By using the Service, you expressly agree to these Terms of Service http://w
ww.renderx.com/terms-of-service.html

image001.png
Received on Tue Mar 31 22:30:49 2015

This archive was generated by hypermail 2.1.8 : Tue Mar 31 2015 - 22:30:56 PST