PDF gets rendered but has 0 bytes when downloaded

2,136 views
Skip to first unread message

flieger

unread,
Mar 2, 2012, 5:26:01 AM3/2/12
to mwlib
Hi,

I have a problem with downloading pdf-files. I am using the default
public rendering service, as set in collection.php:
$wgCollectionMWServeURL = 'http://tools.pediapress.com/mw-serve/';

After klicking the link to generate a pdf-file of the current page, I
get the following message:
"data fetched. waiting for render process.."

Shortly afterwards the systems comes back telling me that the document
has been successfully created. When I klick the download-link, an
empty page opens. Trying to save the link results in saving a file,
called collection.pdf, with 0 bytes.

these are my relevant settings in localsettings.php:

require_once("$IP/extensions/Collection/Collection.php");
$wgEnableApi = true;
$wgEnableWriteAPI = true;
$wgCollectionMWServeCredentials = "user:user-pwd";
$wgGroupPermissions['user']['collectionsaveasuserpage'] = true;
$wgGroupPermissions['autoconfirmed']['collectionsaveascommunitypage']
= true;

Any help much appreciated.

Thanks,

flieger

Ralf Schmitt

unread,
Mar 2, 2012, 6:20:53 AM3/2/12
to mw...@googlegroups.com
flieger <vol...@gmx.de> writes:

> Shortly afterwards the systems comes back telling me that the document
> has been successfully created. When I klick the download-link, an
> empty page opens. Trying to save the link results in saving a file,
> called collection.pdf, with 0 bytes.

Are there any errors or warnings in your web server log?

--
Cheers
Ralf

flieger

unread,
Mar 2, 2012, 6:35:39 AM3/2/12
to mw...@googlegroups.com
if there are any, I can't see them.  The wiki is located on a server at a webhosting company, and I am not the wiki's administrator, only its most frequent user at the moment.  What can I ask the administrator to look for specifically, ie. which files and where should he look?

Thanks,
flieger


On Friday, March 2, 2012 12:20:53 PM UTC+1, Ralf Schmitt wrote:

flieger

unread,
Mar 5, 2012, 5:05:34 AM3/5/12
to mw...@googlegroups.com
Hi,

I have some additional info that might help analyzing the problem.  After searching the internet I found a similar problem on this site:
http://www.mediawiki.org/wiki/Extension_talk:Collection/Archive_1#Book_has_0_Bytes

I applied the patches indicated there, since my version of php is 5.2.17.

1. the array problem:

--- GlobalFunctions.php 2009-03-25 03:07:09.000000000 +0100
+++ GlobalFunctions.php 2010-07-17 23:33:17.000000000 +0200
@@ -1239,6 +1239,9 @@
  */
 function wfAppendQuery( $url, $query ) {
        if( $query != '' ) {
+               if ( is_array( $query ) ) {
+                       $query = http_build_query( $query );
+               }
                if( false === strpos( $url, '?' ) ) {
                        $url .= '?';
                } else {


2. the php problem.

--- Collection.body.php 2010-07-18 01:38:38.000000000 +0200
+++ Collection.body.php.patched 2010-07-18 01:38:30.000000000 +0200
@@ -1144,7 +1144,8 @@ EOS
                global $wgRequest;
                global $wgCollectionContentTypeToFilename;
 
-               $tempfile = tmpfile();
+               $tmpfname = tempnam("/tmp", "mwlib-pdf");
+               $tempfile = fopen($tmpfname, "w");
                $r = self::mwServeCommand( 'render_status', array(
                        'collection_id' => $wgRequest->getVal( 'collection_id' ),
                        'writer' => $wgRequest->getVal( 'writer' ),
@@ -1181,8 +1182,9 @@ EOS
                                header( 'Content-Disposition: ' . 'inline; filename=' . $wgCollectionContentTypeToFilename[$ct] );
                        }
                }
-               fseek( $tempfile, 0 );
-               fpassthru( $tempfile );
+               if (is_resource($tempfile))
+                       fclose($tempfile);
+               readfile( $tmpfname );
                $wgOut->disable();
        }
 
@@ -1374,6 +1376,9 @@ EOS
                        if ( !$toFile ) {
                                $text = $result;
                        }
+                       else {
+                               fclose( $toFile );
+                       }
                        $errorMessage = '';
                }
                curl_close( $c );


This morning I added two lines of debugging code to the beginning of localsettings.php, as indicated here: http://www.mediawiki.org/wiki/Manual:How_to_debug

error_reporting( E_ALL );
ini_set( 'display_errors', 1 );

I tried again to download a page of my wiki as a PDF and I was able to download collection.pdf, which contained the following lines:

<br />
<b>Warning</b>:  readfile() [<a href='function.readfile'>function.readfile</a>]: Filename cannot be empty in <b>/is/htdocs/wp1045034_DIC9D7OW2C/www/frankfurt.vij.de/wikijusta/extensions/Collection/Collection.body.php</b> on line <b>1127</b><br />

The warning refers to the line of patch that I inserted into Collection.body.php:
+               readfile( $tmpfname );

This suggests to me that somehow the pdf doesn't get filled on the pediapress server.

What do you think?

flieger

Ralf Schmitt

unread,
Mar 5, 2012, 2:30:31 PM3/5/12
to mw...@googlegroups.com
flieger <vol...@gmx.de> writes:

> I tried again to download a page of my wiki as a PDF and I was able to
> download collection.pdf, which contained the following lines:
>
> <br />
> <b>Warning</b>: readfile() [<a
> href='function.readfile'>function.readfile</a>]: Filename cannot be empty
> in
> <b>/is/htdocs/wp1045034_DIC9D7OW2C/www/frankfurt.vij.de/wikijusta/extensions/Collection/Collection.body.php</b>
> on line <b>1127</b><br />
>
> The warning refers to the line of patch that I inserted into
> Collection.body.php:
>
> + readfile( $tmpfname );
>
>
> This suggests to me that somehow the pdf doesn't get filled on the
> pediapress server.

why?

flieger

unread,
Mar 6, 2012, 10:28:25 AM3/6/12
to mw...@googlegroups.com
...because the data has been fetched.   But it's just a guess.

Again some more info.  I tried to download as a PDF a page from Wikipedia.  The whole process involves 3 steps:
  1. data fetching.
    which finishes with: data fetched. waiting for rendering process..
  2. laying out (pagename)
  3. rendering (Wikiseite: Lizenz)

When I try to print a page from my own wiki I never encountered steps 2 and 3.

Does this info help you to help me?  If not, what else can I do to make my problem clearer?

It can't be that our wiki is the only wiki that can't produce PDFs.

Thanks for you help,

flieger




Am Montag, 5. März 2012 20:30:31 UTC+1 schrieb Ralf Schmitt:
flieger <> writes:

> I tried again to download a page of my wiki as a PDF and I was able to
> download collection.pdf, which contained the following lines:
>
> <br />
> <b>Warning</b>:  readfile() [<a
> href='function.readfile'>function.readfile</a>]: Filename cannot be empty
> in

> <b>/is/htdocs/wp1045034_DIC9D7OW2C/www/.../extensions/Collection/Collection.body.php</b>

> on line <b>1127</b><br />
>
> The warning refers to the line of patch that I inserted into
> Collection.body.php:
>
> +               readfile( $tmpfname );
>
>
> This suggests to me that somehow the pdf doesn't get filled on the
> pediapress server.

why?

Reply all
Reply to author
Forward
0 new messages