@kofikwarteng opened this Issue on March 21st 2016

Hello,
I'm running PIWIK on a VPS with Ubuntu 15.04, HHVM 3.12.0 and NGINX 1.9.10. I have both PHP 5.6.4 and HHVM installed on that server. I use PHP to serve old web applications and HHVM for modern ones.

PIWIK works great under HHVM and reduces CPU load but PDF reports cannot be generated under HHVM.

I created a personal daily, weekly and monthly email report for one of my tracking sites under my account. On the reports table, there is an option to download the PDF.

When it is clicked this is the error message that comes up:
http://snag.gy/5td22.jpg

When I switch from HHVM to PHP, the PDF works flawlessly.

@emirb commented on March 21st 2016 Contributor

Seems that when using HHVM, Piwik's API renderer sets wrong response format (XML).

PDF file format requires EOF to be used as file trailer, on the last line of the content.
This is done in https://github.com/tecnickcom/TCPDF/blob/develop/tcpdf.php#L9988

Piwik's API renderer appends XML response to valid PDF content, resulting in garbaged output:

... PDF content
0000413826 00000 n
0000414317 00000 n
0000414489 00000 n
0000414685 00000 n
0000414750 00000 n
0000414950 00000 n
0000419257 00000 n
trailer
<< /Size 24 /Root 23 0 R /Info 21 0 R /ID 
[ <8aeb203749d4538ab33be9cb9db12ceb> <8aeb203749d4538ab33be9cb9db12ceb> ] >>
startxref
419506
%%EOF
<?xml version="1.0" encoding="utf-8" ?>
<result></result>

Therefore, the browser cannot show the PDF content correctly, and shows you the XML error message instead.

Furthermore, when using HHVM instead of PHP engine, even though TCPDF is already setting correct Content-Type header when generating inline browser output (https://github.com/tecnickcom/TCPDF/blob/6.2.12/tcpdf.php#L7624), the actual header's value being sent is text/xml.

Content-Type: text/xml; charset=utf-8
X-Powered-By: HHVM/3.12.1
Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1
Content-Disposition: inline; filename="All_Websites_-_Sunday_March_20_2016_-_test.pdf"

Correct response headers using PHP 5.6.19:

Content-Type: application/pdf
Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1
Content-Disposition: inline; filename="All_Websites_-_Sunday_March_20_2016_-_test.pdf"

Temporary solution

You can bypass this behaviour by appending &format=original parameter into the PDF report URI. That will show the report in your browser correctly, by setting correct Content-Type response header and also disabling the additional XML output being appended.

LTS solution

This issue requires thorough investigation, but from what I can see so far, here would be some proposed solutions:

That way we would ensure that there is no extra content appended to the inline browser PDF output.

@tsteur commented on March 29th 2016 Owner

@emirb thank you a lot for investigating and giving us insights into the problem. :+1: :+1:

I haven't tried to reproduce it but wonder if this PR maybe kind of fixed the content type issue: https://github.com/piwik/piwik/pull/9700

@kofispaceman or @emirb can you maybe try with latest beta version 2.16.1 (at least 2.16.1-b2 or master branch)

@mattab commented on March 31st 2016 Owner

Hi @kofispaceman - do you still have the issue with our latest beta? please let us know http://piwik.org/faq/how-to-update/faq_159/

@kofikwarteng commented on April 3rd 2016

Hello @mattab and @tsteur,

I will test the latest beta and let you guys know. @emirb was right. HHVM was rendering the content as XML instead of PDF.

@mattab commented on July 18th 2016 Owner

Hi @kofispaceman @emirb let us know if the issue is still here

This Issue was closed on July 18th 2016
Powered by GitHub Issue Mirror