PDF Plugin Creation – Part 3

Let’s now work on our cover and back pages. Moving forward, when I refer to the plugin folder, this is the one, in my case, located in Applications –> Oxygen XML Editor –> frameworks –> dita –> DITA-OT2.x –> plugins –> com.client.pdf-reg

Note: There are ways to add a cover image directly from the map. At the moment, I will not be covering that approach and instead, we will be using a more static approach. If you want a cover that changes dynamically per the map used, then you might want to learn more on how to use the e:cover-image template, which I might describe in future tutorials.

1. Cover Page

1.1 Create a Background

Using Photoshop, or any other graphic editor, create an image with the following specs, and design a background of your preference.

Note: The resolution is 120 DPI. This is what most of the PDF rendering tools use by default, but check yours in case you have to make changes.

Save this background as a PNG and name it frontcover.png.

1.2 Storing the Background File Inside the Plugin Folder

Add the artwork folder to your plugin folder: com.client.pdf-reg/cgf/common/artwork and place frontcover.png there.

1.3 Add the Background to front-matter.xsl

Using Oxygen, open the file front-matter.xsl, located in com.client.pdf-reg/xsl/fo. Add the following after <xsl:template name=”createFrontCoverContents”>:

<!--Background Graphic-->
    <fo:block-container absolute-position="absolute" background-image="./Customization/OpenTopic/common/artwork/frontcover.png" background-repeat="no-repeat" background-position="0,0" height="279.4mm" width="215.9mm" top="-18mm" left="-24mm">
<!--End Background Graphic-->

We are creating a block of content, which places frontcover.png as the first element of the page. By being the first, it is placed on the bottom layer, which is important because we want to put text on top of that image.

Since we have predetermined that, by default, all the pages in our PDF have an 18mm margin on top, and 24mm on the outside, we then need to substract this manually so the graphic is centered. See the visual guide below on how a page is distributed.

1.4 Change the Font of the __frontmatter__title Attribute

Open the file front-matter-attr.xsl, located in com.client.pdf-reg/cfg/fo/attrs. Add the code below. This will change the font family, the size of the font and the color.

Note: I will use MyriadPro-Regular as my font, but you can use any other font, as long as it is supported by your rendering platform.

<xsl:attribute-set name="__frontmatter__title">
    <xsl:attribute name="font-family">MyriadPro-Regular</xsl:attribute>
    <xsl:attribute name="font-size">50pt</xsl:attribute>
    <xsl:attribute name="color">white</xsl:attribute>

1.5 Result

This is now my cover page:

2. Back Page

2.1 Generate the Back Cover

Open the file basic-settings.xsl located in com.client.pdf-reg/cfg/fo/attrs and add the following lines. This will make sure that a back cover is generated.

<!--Generate Back Page-->
  <xsl:variable name="generate-back-cover" select="true()"/>

2.2 Edit the File front-matter.xsl

Open the file front-matter.xsl. Add in the bottom the following code:

<!--Back Cover-->
<xsl:template name="createBackCoverContents">
    <fo:block-container absolute-position="absolute" background-image="./Customization/OpenTopic/common/artwork/frontcover.png" background-repeat="no-repeat" background-position="0,0" height="279.4mm" width="215.9mm" top="-18mm" left="-24mm">
<!--End Back Cover-->

We are doing the exact same thing we did for the cover page, but in this case we are doing it inside the template called createBackCoverContents, instead of createFrontCoverContents.

2.3 Add a Text Line

I will add the copyright symbol and the current year, to complete the back cover, but the possibilities are endless.

2.4 How is it looking?

Well, it is not bad, but not what I wanted. The font is too small, the color contrast is not good, and the position should be on the right bottom part of the page.

2.5 Let’s Create a New Style for the Back Cover Content

Open the file front-matter-attr.xsl. Add the code below.

<xsl:attribute-set name="__back-cover__title">
        <xsl:attribute name="font-family">Helvetica</xsl:attribute>
        <xsl:attribute name="font-size">20pt</xsl:attribute>
        <xsl:attribute name="color">white</xsl:attribute>
        <xsl:attribute name="text-align">right</xsl:attribute>

I created a new style called __back-cover__title, which uses a different font, size and alignment than the front page cover.

2.6 Let’s Apply that Style to the Text

I need to make sure that I add the style I just created, to the block that contains my text.

2.7 Let’s Move the Text to the Bottom of the Page

By adding the attribute margin-top to the block, I can locate where the text will be placed. Keep in mind that, to the number you are using, you have to add the predetermined margin. I.e. if the number is 200mm, you add the 18mm of top margin, and the position of the block will be 218mm from the top.

2.8 Result

This is now my back page:

Leave a Reply