Skip to content

Commit

Permalink
Item9112:
Browse files Browse the repository at this point in the history
   * added content-disposition header working around acroread's inability to properly parse url params
   * documented interplay of GenPDFPrincePlugin and ZonePlugin on a foswiki-1.0.9 engine



git-svn-id: http://svn.foswiki.org/trunk/GenPDFPrincePlugin@7671 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Jun 7, 2010
1 parent e0abe8d commit bd75f9d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
14 changes: 12 additions & 2 deletions data/System/GenPDFPrincePlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1241721334" format="1.1" version="1.2"}%
%META:TOPICINFO{author="ProjectContributor" comment="save topic" date="1266576108" format="1.1" reprev="1.3" version="1.3"}%
---+!! %TOPIC%

This plugin generates PDF using [[http://www.princexml.com/][Prince XML]].
Expand All @@ -15,18 +15,28 @@ Here's the complete Foswiki documentation in [[%SCRIPTURL{"view"}%/%SYSTEMWEB%/C
---++ Installation
You will have to download Prince XML from http://www.princexml.com/download.

If you are using other plugins that implement a =completePageHandler= (see InstalledPlugins) then you most
probably need to tune the =$Foswiki::cfg{PluginsOrder}= to list the %TOPIC% behind those. For example,
if you are using Foswiki:Extensions/ZonePlugin then you will have to list both giving them a specific order
how they execute the =completePageHandler=:

<verbatim>
$Foswiki::cfg{PluginsOrder} = '...., ZonePlugin, GenPDFPrincePlugin';
</verbatim>

%$INSTALL_INSTRUCTIONS%

---++ Plugin Info
<!--
* Set SHORTDESCRIPTION = 'Generate PDF using Prince XML';
-->
| Author: | Foswiki:Main.MichaelDaum |
| Copyright: | &copy; 2009, Michael Daum http://michaeldaumconsulting.com |
| Copyright: | &copy; 2009-2010, Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 07 Jun 2010 | added content-disposition to ease saving the pdf to disk |
| 20 Aug 2009 | improved error handling |
| 07 May 2009 | initial release |
| Home: | Foswiki:Extensions/%TOPIC% |
Expand Down
41 changes: 38 additions & 3 deletions lib/Foswiki/Plugins/GenPDFPrincePlugin.pm
Expand Up @@ -25,13 +25,22 @@ use Foswiki::Plugins ();
use Error qw(:try);

our $VERSION = '$Rev: 4419 (2009-07-03) $';
our $RELEASE = '1.1';
our $RELEASE = '1.2';
our $SHORTDESCRIPTION = 'Generate PDF using Prince XML';
our $NO_PREFS_IN_TOPIC = 1;
our $baseTopic;
our $baseWeb;

use constant DEBUG => 0; # toggle me

###############################################################################
sub writeDebug {
print STDERR "GenPDFPrincePlugin - $_[0]\n" if DEBUG;
}

###############################################################################
sub initPlugin {
my ($topic, $web, $user, $installWeb) = @_;
($baseTopic, $baseWeb) = @_;

if ($Foswiki::Plugins::VERSION < 2.0) {
Foswiki::Func::writeWarning('Version mismatch between ',
Expand Down Expand Up @@ -69,13 +78,17 @@ sub completePageHandler {

# creater html file
print $htmlFile "$_[0]";
#writeDebug("htmlFile=".$_[0]);

# create prince command
my $session = $Foswiki::Plugins::SESSION;
my $pubUrl = $session->getPubUrl(1);
my $princeCmd = $Foswiki::cfg{GenPDFPrincePlugin}{PrinceCmd} ||
'/usr/bin/prince --baseurl %BASEURL|U% -i html -o %OUTFILE|F% %INFILE|F% --log=%ERROR|F%';

writeDebug("princeCmd=$princeCmd");
writeDebug("BASEURL=$pubUrl");

# execute
my ($output, $exit) = Foswiki::Sandbox->sysCommand(
$princeCmd,
Expand All @@ -87,16 +100,38 @@ sub completePageHandler {

local $/ = undef;

my $error = '';
if ($exit || DEBUG) {
$error = <$errorFile>;
}

writeDebug("GenPDFPrincePlugin - error=$error");
writeDebug("GenPDFPrincePlugin - output=$output");

if ($exit) {
my $error = <$errorFile>;
my $html = $_[0];
my $line = 1;
$html = '00000: '.$html;
$html =~ s/\n/"\n".(sprintf "\%05d", $line++).": "/ge;
throw Error::Simple("execution of prince failed ($exit): \n\n$error\n\n$html");
}


$_[0] = <$pdfFile>;
}

###############################################################################
sub modifyHeaderHandler {
my ($hopts, $request) = @_;

my $query = Foswiki::Func::getCgiQuery();
my $contenttype = $query->param("contenttype") || 'text/html';

# is this a pdf view?
return unless $contenttype eq "application/pdf";

# add disposition
$hopts->{'Content-Disposition'} = "inline;filename=$baseTopic.pdf";
}

1;
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/GenPDFPrincePlugin/build.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w
BEGIN {
foreach my $pc (split(/:/, $ENV{TWIKI_LIBS})) {
foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) {
unshift @INC, $pc;
}
}
Expand Down

0 comments on commit bd75f9d

Please sign in to comment.