Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on managed hosting, pdfs return blank even though file_get_contents, curl, and permissions are ok #36

Open
airplanenoise opened this issue Nov 26, 2021 · 7 comments

Comments

@airplanenoise
Copy link

@anttiviljami hi - i know this is not your main gig and that you don't use this much these days.

i have spent tons of time trying to solve this issue.

i read all the forums posts on WP, and a lot of stackoverflows about this.

i have this working just fine on a VPS, on several websites, with the same hosting company (MT), exact same code.
on MANAGED HOSTING, the PDF returns blank. the error logs show nothing I can solve:

errors.zip
errors.log

i was told by the hosting's support that this can't work on this type of hosting, but i didn't believe it since file_get_content works, curl works, and i actually managed to generate a pdf with this test file:

<?php

	$test = file_get_contents('https://DOMAIN_NAME_REMOVED/professionals/erica-wolff/pdf-preview', false);
	require_once 'wp-content/plugins/wp-pdf-templates/vendor/autoload.php';

    $dompdf = new Dompdf\Dompdf();

	define("DOMPDF_ENABLE_HTML5PARSER", true);

	$dompdf->loadHtml($test);
	
	// Render the HTML as PDF
	$dompdf->render();

	// Output the generated PDF to Browser
	// stream(filename [without .pdf], 1 compress, 1 force save dialog)
	$dompdf->stream('/var/www/wp-content/test123f.pdf',array('compress'=>0,'attachment'=>1));

?>

...going around all the Wordpress stuff found in the actual plugin.

the result is very close the functioning one we have on our dev server, but only if i try to read from -template, from -preview it fails.

test123f.pdf (16).pdf

what i am asking is this:

  • obviously dompdf works on this environment
  • i am able to generate a pdf with the layout that we want from the wordpress post
  • /pdf-template and /pdf-preview work fine
  • the pdf is blank, the stream part is blank, i attached it if someone speaks PDF :D

if anybody has any insight on how to solve this, i would be grateful. i tried swapping dompdf versions, i tried outputting just the default template that comes with the plugin, i tried debugging verbosely... (by the way, how to get the same output as the debugger found on http://eclecticgeek.com/dompdf/debug.php ? the one that shows dependencies? i wasn't able to do that

i am able to generate basic pdfs with just things like "hello world" — what fails is when i try to read content from an html.

if anybody has had experience with that and solved it, i am willing to try your solution!

my guess is that the managed hosting restrictions prevent from reading or writing the temp file

i have to disable cache to make my test work, and the font cache folder never gets the .inc file or the font files.

happy to jump on a discord if you want to check this out with me, i am totally stuck.

thanks!

@anttiviljami
Copy link
Owner

Wow, have to admit I’m a bit surprised this code is still being used 😊

if I remember correctly I saw this issue when the /pdf-{preview,render} route was inaccessible from the host itself.

i think the plugin literally makes a http call to query the endpoint, so if the endpoint is behind auth or similar, it will fail.

Might also want to check that you can read and write files in /tmp.

Are you able to turn on error logging on the host so you see any possible issues?

@airplanenoise
Copy link
Author

airplanenoise commented Nov 26, 2021 via email

@anttiviljami
Copy link
Owner

Hi @airplanenoise

file_get_contents(https://localhost/professionals/allegra-noonan/?pdf-template): failed to open stream: Address not available

Address not available sounds like localhost is not resolving to 127.0.0.1

I would experiment with changing this line to point to either to public address or 127.0.0.1 https://github.com/anttiviljami/wp-pdf-templates/blob/master/wp-pdf-templates.php#L211

@airplanenoise
Copy link
Author

thanks for the reply!

nah, i am still troubleshooting and i get further.

[27-Nov-2021 15:20:35 UTC] PHP Warning: A non-numeric value encountered in /var/www/wp-content/plugins/wp-pdf-templates/vendor/dompdf/dompdf/src/Css/Style.php on line 1330

this is the error i get.

it's just a warning.

and then the PDF is blank.
Vincent-Cavaliere.pdf.pdf

any ideas?

@anttiviljami
Copy link
Owner

Sorry, beyond that it's hard to say.

To troubleshoot, maybe add some logging and check if you're getting the right html at:

https://github.com/anttiviljami/wp-pdf-templates/blob/master/wp-pdf-templates.php#L260

@airplanenoise
Copy link
Author

airplanenoise commented Nov 28, 2021 via email

@airplanenoise
Copy link
Author

ok - i was able to troubleshoot further. this is the error i get now:

Stack trace:
#0 /var/www/wp-content/plugins/mfo-wp-pdf-templates/vendor/dompdf/dompdf/src/Dompdf.php(760): Dompdf\Dompdf->processHtml()
#1 /var/www/wp-content/plugins/mfo-wp-pdf-templates/wp-pdf-templates.php(404): Dompdf\Dompdf->render()
#2 /var/www/wp-content/plugins/mfo-wp-pdf-templates/wp-pdf-templates.php(263): _print_pdf('<html>\n<head>\n\t...')
#3 /var/www/wp-includes/class-wp-hook.php(303): _use_pdf_template('')
#4 /var/www/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#5 /var/www/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#6 /var/www/wp-includes/template-loader.php(13): do_action('template_redire...')
#7 /var/www/wp-blog-header.php(19): require_once('/var/www/wp-inc...')
#8 /var/www/index.php(17): require('/var/www/wp-blo...')
#9 {main}
  thrown in /var/www/wp-content/plugins/mfo-wp-pdf-templates/vendor/dompdf/dompdf/src/Dompdf.php on line 596

does that make sense to you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants