|
|
1a4d0e |
#!/bin/bash
|
|
|
1a4d0e |
#
|
|
|
a7c6e7 |
# docbook_convertToPdf.sh -- This function produces PDF output for
|
|
|
a7c6e7 |
# repository documentation manual, in DocBook XML format. The
|
|
|
2cddae |
# procedure was taken from `docbook-style-xsl-1.69.1-5.1'
|
|
|
2cddae |
# documentation, which says: ---To get to print, you need an XSLT
|
|
|
2cddae |
# engine (e.g., `xsltproc') to produce formatting objects (FO), which
|
|
|
2cddae |
# then must be processed with an FO engine (e.g., `pdfxmltex') to
|
|
|
2cddae |
# produce PostScript or PDF output---. To make the whole process
|
|
|
2cddae |
# transparent, a temporal directory is created for intermediate works.
|
|
|
2cddae |
# Once the PDF file is produced there, it is moved to its final
|
|
|
2cddae |
# location.
|
|
|
1a4d0e |
#
|
|
|
1a4d0e |
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
|
|
|
1a4d0e |
#
|
|
|
1a4d0e |
# This program is free software; you can redistribute it and/or modify
|
|
|
1a4d0e |
# it under the terms of the GNU General Public License as published by
|
|
|
1a4d0e |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
1a4d0e |
# (at your option) any later version.
|
|
|
1a4d0e |
#
|
|
|
1a4d0e |
# This program is distributed in the hope that it will be useful, but
|
|
|
1a4d0e |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
1a4d0e |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
1a4d0e |
# General Public License for more details.
|
|
|
1a4d0e |
#
|
|
|
1a4d0e |
# You should have received a copy of the GNU General Public License
|
|
|
1a4d0e |
# along with this program; if not, write to the Free Software
|
|
|
1a4d0e |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
1a4d0e |
#
|
|
|
1a4d0e |
# ----------------------------------------------------------------------
|
|
|
1a4d0e |
# $Id$
|
|
|
1a4d0e |
# ----------------------------------------------------------------------
|
|
|
1a4d0e |
|
|
|
a7c6e7 |
function docbook_convertToPdf {
|
|
|
1a4d0e |
|
|
|
1a4d0e |
# Print action message.
|
|
|
1a4d0e |
cli_printMessage "${MANUAL_BASEFILE}.pdf" --as-updating-line
|
|
|
1a4d0e |
|
|
|
2cddae |
# Define name of temporal directory where the DocBook to PDF
|
|
|
1a4d0e |
# transformation will take place.
|
|
|
1a4d0e |
local TMPDIR=$(cli_getTemporalFile "docbook2pdf")
|
|
|
1a4d0e |
|
|
|
2cddae |
# Define absolute path to DocBook source file. This is the
|
|
|
2cddae |
# repository documentation manual file where DOCTYPE and ENTITY
|
|
|
2cddae |
# definition lines are set.
|
|
|
a7c6e7 |
local SRC=${INSTANCE}
|
|
|
1a4d0e |
|
|
|
2cddae |
# Define absolute path to PDF target file. This is the final
|
|
|
2cddae |
# location the PDF file produced as result of DocBook to PDF
|
|
|
2cddae |
# transformation will be stored in.
|
|
|
a7c6e7 |
local DST="${FILE}.pdf"
|
|
|
1a4d0e |
|
|
|
1a4d0e |
# Define absolute path of the XSLT file used to create the
|
|
|
1a4d0e |
# formatting object (.fo) file.
|
|
|
1a4d0e |
local XSLT=/usr/share/sgml/docbook/xsl-stylesheets/fo/docbook.xsl
|
|
|
1a4d0e |
|
|
|
2cddae |
# Define file name of formatting object (.fo) file. This file is
|
|
|
2cddae |
# an intermediate file needed to produced the PDF.
|
|
|
1a4d0e |
local FO=${MANUAL_NAME}.fo
|
|
|
1a4d0e |
|
|
|
2cddae |
# Define file name of PDF file. This is the file we were looking
|
|
|
2cddae |
# for and the one moved, once produced.
|
|
|
1a4d0e |
local PDF=${MANUAL_NAME}.pdf
|
|
|
1a4d0e |
|
|
|
1a4d0e |
# Verify temporal directory and create it if doesn't exist.
|
|
|
1a4d0e |
if [[ ! -d $TMPDIR ]];then
|
|
|
1a4d0e |
mkdir $TMPDIR
|
|
|
1a4d0e |
fi
|
|
|
1a4d0e |
|
|
|
1a4d0e |
# Move inside temporal directory.
|
|
|
1a4d0e |
pushd $TMPDIR > /dev/null
|
|
|
1a4d0e |
|
|
|
1a4d0e |
# Create formatting object supressing output from stderr.
|
|
|
1a4d0e |
xsltproc ${XSLT} ${SRC} 2> /dev/null > ${FO}
|
|
|
1a4d0e |
|
|
|
2cddae |
# Create PDF format from formatting object. The `pdfxmltex' commad
|
|
|
2cddae |
# must be executed twice in order for document's cross-references
|
|
|
2cddae |
# to be built correctly.
|
|
|
1a4d0e |
if [[ $? -eq 0 ]];then
|
|
|
1a4d0e |
pdfxmltex ${FO} > /dev/null
|
|
|
1a4d0e |
pdfxmltex ${FO} > /dev/null
|
|
|
2cddae |
else
|
|
|
2cddae |
cli_printMessage "`gettext "Cannot produce the formatting object."`" --as-error-line
|
|
|
1a4d0e |
fi
|
|
|
1a4d0e |
|
|
|
2cddae |
# Verify `' exit status and, if everything is ok, move PDF file
|
|
|
2cddae |
# from temporal directory to its target location.
|
|
|
1a4d0e |
if [[ $? -eq 0 ]];then
|
|
|
1a4d0e |
mv $PDF $DST
|
|
|
2cddae |
else
|
|
|
2cddae |
cli_printMessage "`gettext "Cannot produce the PDF file."`" --as-error-line
|
|
|
1a4d0e |
fi
|
|
|
1a4d0e |
|
|
|
1a4d0e |
# Return to where we initially were.
|
|
|
1a4d0e |
popd > /dev/null
|
|
|
1a4d0e |
|
|
|
1a4d0e |
# Remove temporal directory.
|
|
|
1a4d0e |
rm -r $TMPDIR
|
|
|
1a4d0e |
|
|
|
1a4d0e |
}
|