1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

PDF rendering improvements.

* Check both doc-path and bin-path for logo.
* Allow PDF to be output to a location other than the output directory.
* Use PDF-specific version variable for more flexible formatting.
This commit is contained in:
David Steele 2018-02-16 15:09:37 -05:00
parent 0e27060952
commit 3eed4bbb43
5 changed files with 44 additions and 6 deletions

View File

@ -79,10 +79,13 @@ sub new
{name => 'bCacheOnly', required => false},
);
# Set the bin path
$self->{strBinPath} = abs_path(dirname($0));
# Set the base path if it was not passed in
if (!defined($self->{strDocPath}))
{
$self->{strDocPath} = abs_path(dirname($0));
$self->{strDocPath} = $self->{strBinPath};
}
# Set cache file names

View File

@ -8,10 +8,11 @@ use warnings FATAL => qw(all);
use Carp qw(confess);
use English '-no_match_vars';
use Cwd qw(abs_path);
use Data::Dumper;
use Exporter qw(import);
our @EXPORT = qw();
use File::Basename qw(dirname);
use File::Basename qw(dirname basename);
use File::Copy;
use POSIX qw(strftime);
use Storable qw(dclone);
@ -93,8 +94,16 @@ sub process
my $oRender = $self->{oManifest}->renderGet(RENDER_TYPE_PDF);
# Should the logo be pulled from the doc path or the bin path?
my $strLogoFile = "$self->{oManifest}{strDocPath}/resource/latex/cds-logo.eps";
if (!$self->{oManifest}->storage()->exists($strLogoFile))
{
$strLogoFile = "$self->{oManifest}{strBinPath}/resource/latex/cds-logo.eps";
}
# Copy the logo
copy("$self->{oManifest}{strDocPath}/resource/latex/cds-logo.eps", "$self->{strLatexPath}/logo.eps")
copy($strLogoFile, "$self->{strLatexPath}/logo.eps")
or confess &log(ERROR, "unable to copy logo");
my $strLatex = $self->{oManifest}->variableReplace(
@ -141,8 +150,14 @@ sub process
$strLatex .= "\n% " . ('-' x 130) . "\n% End document\n% " . ('-' x 130) . "\n\\end{document}\n";
my $strLatexFileName = $self->{oManifest}->variableReplace("$self->{strLatexPath}/" . $$oRender{file} . '.tex');
# Get base name of output file to use for processing
(my $strLatexFileBase = basename($$oRender{file})) =~ s/\.[^.]+$//;
$strLatexFileBase = $self->{oManifest}->variableReplace($strLatexFileBase);
# Name of latex file to use for output and processing
my $strLatexFileName = $self->{oManifest}->variableReplace("$self->{strLatexPath}/" . $strLatexFileBase . '.tex');
# Output latex and build PDF
$self->{oManifest}->storage()->put($strLatexFileName, $strLatex);
executeTest("pdflatex -output-directory=$self->{strLatexPath} -shell-escape $strLatexFileName",
@ -150,6 +165,21 @@ sub process
executeTest("pdflatex -output-directory=$self->{strLatexPath} -shell-escape $strLatexFileName",
{bSuppressStdErr => true});
# Determine path of output file
my $strLatexOutputName = $oRender->{file};
if ($strLatexOutputName !~ /^\//)
{
$strLatexOutputName = abs_path($self->{strLatexPath} . "/" . $oRender->{file});
}
# Copy pdf file if is is not already in the correct place
if ($strLatexOutputName ne "$self->{strLatexPath}/" . $strLatexFileBase . '.pdf')
{
copy("$self->{strLatexPath}/" . $strLatexFileBase . '.pdf', $strLatexOutputName)
or confess &log(ERROR, "unable to copy pdf to " . $strLatexOutputName);
}
# Return from function and log return values if any
logDebugReturn($strOperation);
}

View File

@ -64,6 +64,7 @@
<!-- PDF variables -->
<variable key="pdf-title">{[project]} User Guide</variable>
<variable key="pdf-subtitle">Open Source PostgreSQL Backup and Restore Utility</variable>
<variable key="pdf-version">Version {[version]}</variable>
<variable key="pdf-file">CrunchyBackRest-UserGuide-{[version]}</variable>
</variable-list>

View File

@ -107,7 +107,7 @@
}
\lfoot[]{{[pdf-title]}\\
Version {[version]}}
{[pdf-version]}}
\cfoot[]{\ \\-\ \thepage\ -}
\rfoot[]{Crunchy Data Solutions, Inc.\\\today}
\pagestyle{fancy}
@ -129,7 +129,7 @@
\begin{center}
{\large \ }\\[18ex]
{\huge \bfseries {[pdf-title]}}\\[1ex]
{\large \bfseries Version {[version]}}\\[4ex]
{\large \bfseries {[pdf-version]}}\\[4ex]
{\large {[pdf-subtitle]}}\\[12ex]
\includegraphics[width=6in]{{[logo]}}\\[12ex]
{\large Crunchy Data Solutions, Inc.}\\[1ex]

View File

@ -161,6 +161,10 @@
<p>Add table render for Markdown format.</p>
</release-item>
<release-item>
<p>PDF rendering improvements. Check both <path>doc-path</path> and <path>bin-path</path> for logo. Allow PDF to be output to a location other than the <path>output</path> directory. Use PDF-specific version variable for more flexible formatting.</p>
</release-item>
<release-item>
<p>Deploy historical documentation to <path>prior</path> rather than the root directory.</p>
</release-item>