Blame Scripts/Functions/Render/Docbook/docbook_convertToPdfFromXml.sh

2fa604
#!/bin/bash
2fa604
#
2fa604
# docbook_convertToPdfFromXml.sh -- This function transforms DocBook
2fa604
# files which have set the XML DTD in them.  To produce PDF from
2fa604
# DocBook XML DTD, we need an XSLT engine (e.g., through `xsltproc'
2fa604
# command) to produce formatting objects (FO), which then must be
2fa604
# processed with an FO engine (e.g., through `pdfxmltex' command,
2fa604
# which uses PassiveTex) to produce the PDF output.
2fa604
#
2fa604
# In this configuration and using default configuration settings, I've
2fa604
# presented the following problems:
2fa604
#
2fe9b7
# 1. Something is wrong with headings. They are not expanded along
2fe9b7
# the whole page-body. They seem to be rendered in a reduced width
2fe9b7
# (1 inch approximatly). This provokes the heading to be broken in a
2fe9b7
# two-to-five letters column and sometimes it overlaps the
2fe9b7
# sectioning titles (e.g., chatper, section). I tried to customize
2fe9b7
# the value of `header.column.widths' and `page.margin.top' but it
2fe9b7
# seems to be not there where I need to touch.
2fa604
#
2fe9b7
# 2. TOC's indentation is not rendered. Even the `toc.indent.width'
2fe9b7
# property is set to 24 by default.
2fa604
#
2fe9b7
# 3. Inside lists, when items are more than one line, the
2fe9b7
# indentation seems to work for the first line only.  All other
2fe9b7
# lines in the same item are not indented and begin completly
2fe9b7
# unaligned.
2fa604
#
2fe9b7
# 4. Long file paths near the end of page-body aren't hyphenated.
2fe9b7
# Even the `hyphenate' property is set to `true' by default.
386d14
#
386d14
# In this configuration and using default configuration settings, I've
386d14
# presented the following advantages:
386d14
#
2fe9b7
# 1. It is possible to produce localized PDF outputs through
2fe9b7
# `xml2po', the default way of producing localized content inside
2fe9b7
# the `centos-art.sh' script.
2fa604
#
63e984
# To make the whole process transparent, a temporal directory is
63e984
# created for intermediate works and final files are moved then to
63e984
# their final location.
63e984
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
2fa604
#
2fa604
# This program is free software; you can redistribute it and/or modify
2fa604
# it under the terms of the GNU General Public License as published by
2fa604
# the Free Software Foundation; either version 2 of the License, or (at
2fa604
# your option) any later version.
2fa604
#
2fa604
# This program is distributed in the hope that it will be useful, but
2fa604
# WITHOUT ANY WARRANTY; without even the implied warranty of
2fa604
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2fa604
# General Public License for more details.
2fa604
#
2fa604
# You should have received a copy of the GNU General Public License
2fa604
# along with this program; if not, write to the Free Software
2fa604
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2fa604
#
2fa604
# ----------------------------------------------------------------------
a9c76e
# $Id$
2fa604
# ----------------------------------------------------------------------
2fa604
2fa604
function docbook_convertToPdfFromXml {
2fa604
2fa604
    # Print action message.
386d14
    if [[ -f ${FILE}.sgml.pdf ]];then
386d14
        cli_printMessage "${FILE}.xml.pdf" --as-updating-line
386d14
    else
386d14
        cli_printMessage "${FILE}.xml.pdf" --as-creating-line
386d14
    fi
2fa604
2fa604
    local -a STYLE_TEMPLATE
2fa604
    local -a STYLE_INSTANCE
2fa604
    local STYLE_INSTANCE_FINAL=''
2fa604
2fa604
    # Define name of temporal directory where the DocBook to PDF
2fa604
    # transformation will take place.
2fa604
    local TMPDIR=$(cli_getTemporalFile "docbook2pdf")
2fa604
2fa604
    # Define absolute path to DocBook source file. This is the
2fa604
    # repository documentation manual file where DOCTYPE and ENTITY
2fa604
    # definition lines are set.
2fa604
    local SRC=${INSTANCE}
2fa604
2fa604
    # Define absolute path to PDF target file. This is the final
2fa604
    # location the PDF file produced as result of DocBook to PDF
2fa604
    # transformation will be stored in.
386d14
    local DST="${FILE}.xml.pdf"
2fa604
2fa604
    # Define file name of formatting object (.fo) file. This file is
2fa604
    # an intermediate file needed to produced the PDF.
2fa604
    local FO=$(basename ${FILE}).fo
2fa604
2fa604
    # Define file name of PDF file.  This is the file we were looking
2fa604
    # for and the one moved, once produced.
2fa604
    local PDF=$(basename ${FILE}).pdf
2fa604
2fa604
    # Prepare XSL final instances used in transformations.
2fa604
    ${RENDER_BACKEND}_prepareStyles "${DOCBOOK_STYLES_DIR}/docbook2fo.xsl"
2fa604
2fa604
    # Verify temporal directory and create it if doesn't exist.
2fa604
    if [[ ! -d $TMPDIR ]];then
2fa604
        mkdir $TMPDIR
2fa604
    fi
2fa604
2fa604
    # Move inside temporal directory.
2fa604
    pushd $TMPDIR > /dev/null
2fa604
2fa604
    # Create formatting object supressing output from stderr.
2fa604
    xsltproc --output ${FO} ${STYLE_INSTANCE_FINAL} ${SRC} &> /dev/null
2fa604
386d14
    # Create PDF format from formatting object. The `pdfxmltex'
386d14
    # command (which use the `PassiveTex' engine) must be executed
386d14
    # twice in order for the document's cross references to be built
386d14
    # correctly.
2fa604
    if [[ $? -eq 0 ]];then
2fa604
        pdfxmltex ${FO} > /dev/null
2fa604
        pdfxmltex ${FO} > /dev/null
2fa604
    else 
2fa604
        cli_printMessage "`gettext "Cannot produce the formatting object."`" --as-error-line
2fa604
    fi
2fa604
2fa604
    # Verify `pdfxmltex' exit status and, if everything is ok, move
2fa604
    # PDF file from temporal directory to its target location.
2fa604
    if [[ $? -eq 0 ]];then
2fa604
        mv $PDF $DST
2fa604
    else 
2fa604
        cli_printMessage "`gettext "Cannot produce the PDF file."`" --as-error-line
2fa604
    fi
2fa604
2fa604
    # Return to where we initially were.
2fa604
    popd > /dev/null
2fa604
2fa604
    # Remove temporal directory and temporal style instances created.
2fa604
    rm -r $TMPDIR
2fa604
    rm ${STYLE_INSTANCE[*]}
2fa604
2fa604
}