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

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