Skip to content

Commit

Permalink
Item892: Convert GenPDFAddOn - Fixes to PDF metadata, added debug par…
Browse files Browse the repository at this point in the history
…ameter

git-svn-id: http://svn.foswiki.org/trunk/GenPDFAddOn@2433 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Feb 10, 2009
1 parent 660d308 commit 92163c4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
4 changes: 3 additions & 1 deletion data/System/GenPDFAddOn.txt
Expand Up @@ -68,8 +68,10 @@ The following table shows the various configuration variables and their meaning.
| =pdfmargins= | GENPDFADDON_MARGINS | =undef= | =top:0.5in,bottom:2.5cm,left:12pt,right:15mm= | Specify the page margins (white space to edge of page) |
| =pdfbodycolor= | GENPDFADDON_BODYCOLOR | =undef= | =#CCff99= | Specify the background colour of all pages |
| =pdfstruct= | GENPDFADDON_STRUCT | =book= | =webpage= | use =book= for structured topics, i.e. when rendering a bunch of topics recursively; use =webpage= when printing a topic without a specific heading structure, i.e. if it is just a normal webpage or if it has got a special VIEW_TEMPLATE |
| =pdfcopyright= | GENPDFADDON_COPYRIGHT | =%WEBCOPYRIGHT%= | =Copyright 2009= | Should PDF Metadata include the Foswiki %%NOP%WEBCOPYRIGHT% or another value. If set to 0, copyright is excluded. If set to any other string, the string is included in the metadata. Htmldoc has a bug and appends the copyright to the author metadata, which can break some document management systems that depend on the metadata. Set to =0= to exclude the copyright from the PDF metadata. |
| =pdfdebug= | GENPDFADDON_DEBUG | =0= | =1= | Include debug messages and don't clean up temporary files after execution |

If using Foswiki preference variables, copy them to the appropriate web preferences page.
If using Foswiki preference variables, copy them to the appropriate web preferences page. This plugin does not read settings from this topic!

%SEARCH{"[G]ENPDFADDON_" topic="%TOPIC%" type="regex" casesensitive="on" limit="21" nosearch="on" nosummary="on" header=" * Settings for the %SYSTEMWEB%.%TOPIC% Plugin" nototal="on" multiple="on" format=" * #Set $pattern(.*(G.*?N_.*? ).*) = "}%

Expand Down
7 changes: 5 additions & 2 deletions data/System/GenPDFAddOnDemo.txt
@@ -1,7 +1,8 @@
%META:TOPICINFO{author="ProjectContributor" date="1233972234" format="1.1" version="1.2"}%
%META:TOPICINFO{author="ProjectContributor" date="1234067891" format="1.1" version="1.2"}%
%META:TOPICPARENT{name="GenPDFAddOn"}%
%TOC%

=<!-- PDFSTART --> inserted here to avoid a blank page for the Foswiki TOC=
<!-- PDFSTART -->
---+ GenPDFAddOnDemo

This is a sample document to show what can be achieved with the GenPDFAddOn Plugin.
Expand Down Expand Up @@ -143,6 +144,8 @@ Generated: %DISPLAYTIME%
% META:FIELD{name="TopicHeadline" title="TopicHeadline" value="A look at what the GenPDFAddOn plugin can do"}%
% META:FIELD{name="KeyWords" title="KeyWords" value="PDF, plugin, acrobat"}%
</verbatim>
<!-- PDFSTOP -->
=&lt;!-- PDFSTOP --&gt; inserted here to stop before the signature=

-- Main.WadeTurland - 14 Jun 2005

Expand Down
52 changes: 39 additions & 13 deletions lib/Foswiki/Contrib/GenPDF.pm
Expand Up @@ -72,6 +72,8 @@ our $query;
our %tree;
our %prefs;

our $NO_PREFS_IN_TOPIC = 1; # Don't read the Plugin topic for preferences.

# Need to keep temporary image files around until htmldoc runs,
# so keep the file handles at the upper level
my @tempfiles = ();
Expand Down Expand Up @@ -303,7 +305,7 @@ sub _createTitleFile {
# BUG: this will match _everything_ from the first open span, to the last end span, losing alot of content.
#$text =~ s/<span class="foswikiNewLink".*?>([\w\s]+)<.*?\/span>/$1/gs;

# Fix the image tags to use hard-desk path range than url paths.
# Fix the image tags to use hard-disk path rather than url paths.
# This is needed in case wiki requires read authentication like SSL client
# certificates.
# Fully qualify any unqualified URLs (to make it portable to another host)
Expand All @@ -316,7 +318,7 @@ sub _createTitleFile {
my ( $fh, $name ) = tempfile(
'GenPDFAddOnXXXXXXXXXX',
DIR => $tempdir,
UNLINK => 0, # DEBUG
#UNLINK => 0, # DEBUG
SUFFIX => '.html'
);
open $fh, ">$name";
Expand Down Expand Up @@ -429,7 +431,7 @@ sub _fixImages {
catch Foswiki::AccessControlException with {

# ignore access errors - htmldoc will ignore empty files, but log an error
_writeDebug( "File Access Exception"
&Foswiki::Func::writeDebug( "File Access Exception"
. $imgInfo->{web} . " "
. $imgInfo->{topic} . " "
. $imgInfo->{file} );
Expand Down Expand Up @@ -494,9 +496,13 @@ s/(<p(.*) style="page-break-before:always")/\n<!-- PAGE BREAK -->\n<p$1/gis;

# Prepend META tags for PDF meta info - may be redefined later by topic text
my $meta =
'<META NAME="AUTHOR" CONTENT="%REVINFO{format="$wikiusername"}%"/>'
'<META NAME="AUTHOR" CONTENT="%SPACEOUT{%REVINFO{format="$wikiname"}%}%"/>'
; # Specifies the document author.
$meta .= '<META NAME="COPYRIGHT" CONTENT="%WEBCOPYRIGHT%"/>'
#
# As of htmldoc 1.8.27, it appends the copyright statement into the Author metadata. This can break
# some content management systems. Copyright metadata can be excluded by setting to '0'.
#
$meta .= '<META NAME="COPYRIGHT" CONTENT="' . $prefs{'copyright'} . '"/>' if $prefs{'copyright'}
; # Specifies the document copyright.
$meta .=
'<META NAME="DOCNUMBER" CONTENT="%REVINFO{format="r1.$rev - $date"}%"/>'
Expand Down Expand Up @@ -618,6 +624,22 @@ sub _getPrefs {
use constant MARGINS => undef;
use constant BODYCOLOR => undef;
use constant STRUCT => 'book';
use constant DEBUG => 0;
use constant COPYRIGHT => '%WEBCOPYRIGHT%';

# copyright notice inserted into PDF Metadata
$prefs{'copyright'} = $query->param('pdfcopyright');
if ($prefs{'copyright'} eq '') {
$prefs{'copyright'} = Foswiki::Func::getPreferencesValue("GENPDFADDON_COPYRIGHT");
if ($prefs{'copyright'} eq '') {
$prefs{'copyright'} = COPYRIGHT;
}
}

# Debugging: Logs to data/debug.txt and preserves temporary files
$prefs{'debug'} = $query->param('pdfdebug')
|| Foswiki::Func::getPreferencesValue("GENPDFADDON_DEBUG")
|| DEBUG;

# header/footer topic
$prefs{'hftopic'} = $query->param('pdfheadertopic')
Expand Down Expand Up @@ -817,7 +839,8 @@ This is the core method to convert the current page into PDF format.
sub viewPDF {

# initialize module wide variables
$query = new CGI;
#$query = new CGI;
$query = Foswiki::Func::getCgiQuery();
%tree = ();
%prefs = ();

Expand Down Expand Up @@ -882,7 +905,7 @@ sub viewPDF {
map {
my ( $ch, $par ) = split( /:/, $_ );
push @{ $tree{$par} }, $ch if $par;
# _writeDebug ( "Parent |$par| Child |$ch|");
_writeDebug ( "Parent |$par| Child |$ch|");
} split( /\|/, $list );
}

Expand Down Expand Up @@ -975,15 +998,17 @@ sub viewPDF {
# Disable CGI feature of newer versions of htmldoc
# (thanks to Brent Roberts for this fix)
$ENV{HTMLDOC_NOCGI} = "yes";

my ( $Output, $exit ) = Foswiki::Sandbox->sysCommand(
$htmldocCmd . ' ' . join( ' ', @htmldocArgs ) );
_writeDebug( "htmldoc exited with $exit" );
if ( !-e $outputFile ) {
die "error running htmldoc ($htmldocCmd): $Output\n";
die "error running htmldoc ($htmldocCmd) - Check logs and files in tmp directory for errors. \n\n @htmldocArgs ";
}

# output the HTML header and the output of HTMLDOC
my $cd = "filename=${webName}_$topic.";
try {
try {
if ( $prefs{'format'} =~ /pdf/ ) {
print CGI::header(
-TYPE => 'application/pdf',
Expand Down Expand Up @@ -1012,16 +1037,17 @@ sub viewPDF {
close $ofh;

# Cleaning up temporary files
unlink $outputFile, $titleFile;
unlink @contentFiles;
unlink $outputFile, $titleFile unless $prefs{'debug'};
unlink @contentFiles unless $prefs{'debug'};
unlink @tempfiles unless $prefs{'debug'};
}

### sub _writeDebug
##
## Writes a common format debug message if debug is enabled

sub _writeDebug {
&Foswiki::Func::writeDebug( "GenPDF - " . $_[0] ); # if $debugDefault;
&Foswiki::Func::writeDebug( "GenPDF - " . $_[0] ) if $prefs{'debug'};
} ### SUB _writeDebug


Expand All @@ -1034,7 +1060,7 @@ sub _depthFirst {
my @children = grep { $_; } @{ $tree{$parent} };
for ( sort @children ) {

_writeDebug("new child of $parent: '$_'"); # DEBUG
_writeDebug("new child of $parent: '$_'") if $prefs{'debug'}; # DEBUG
push @$topics, $_;
if ( defined $tree{$_} ) {

Expand Down

0 comments on commit 92163c4

Please sign in to comment.