From bd75f9d02cfd7bf1671dc2e81c9be4cdd74532be Mon Sep 17 00:00:00 2001 From: MichaelDaum Date: Mon, 7 Jun 2010 07:47:07 +0000 Subject: [PATCH] Item9112: * 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 --- data/System/GenPDFPrincePlugin.txt | 14 ++++++- lib/Foswiki/Plugins/GenPDFPrincePlugin.pm | 41 +++++++++++++++++-- .../Plugins/GenPDFPrincePlugin/build.pl | 2 +- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/data/System/GenPDFPrincePlugin.txt b/data/System/GenPDFPrincePlugin.txt index 2753d6c..027f050 100644 --- a/data/System/GenPDFPrincePlugin.txt +++ b/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]]. @@ -15,6 +15,15 @@ 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=: + + +$Foswiki::cfg{PluginsOrder} = '...., ZonePlugin, GenPDFPrincePlugin'; + + %$INSTALL_INSTRUCTIONS% ---++ Plugin Info @@ -22,11 +31,12 @@ You will have to download Prince XML from http://www.princexml.com/download. * Set SHORTDESCRIPTION = 'Generate PDF using Prince XML'; --> | Author: | Foswiki:Main.MichaelDaum | -| Copyright: | © 2009, Michael Daum http://michaeldaumconsulting.com | +| Copyright: | © 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: |   | +| 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% | diff --git a/lib/Foswiki/Plugins/GenPDFPrincePlugin.pm b/lib/Foswiki/Plugins/GenPDFPrincePlugin.pm index 86ea4e0..48dd68e 100644 --- a/lib/Foswiki/Plugins/GenPDFPrincePlugin.pm +++ b/lib/Foswiki/Plugins/GenPDFPrincePlugin.pm @@ -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 ', @@ -69,6 +78,7 @@ sub completePageHandler { # creater html file print $htmlFile "$_[0]"; + #writeDebug("htmlFile=".$_[0]); # create prince command my $session = $Foswiki::Plugins::SESSION; @@ -76,6 +86,9 @@ sub completePageHandler { 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, @@ -87,8 +100,15 @@ 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; @@ -96,7 +116,22 @@ sub completePageHandler { 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; diff --git a/lib/Foswiki/Plugins/GenPDFPrincePlugin/build.pl b/lib/Foswiki/Plugins/GenPDFPrincePlugin/build.pl index 776c5dc..b9f14e6 100755 --- a/lib/Foswiki/Plugins/GenPDFPrincePlugin/build.pl +++ b/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; } }