Forum How do I...?

Issue calling prince through php on RedHat

tjbryant
I had some php code working on my local windows dev and when I moved it to the dev RedHat server I can't get it to work. What I am getting back is an empty response.

public function convert(Request $request){
try{
$prince = new Prince(env("PRINCE_PATH"));
// Log::info($request->input('html'));
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="document.pdf"');
Log::info("about to send");
$prince->convert_string_to_passthru($request->input('html'));
} catch(Exception $e){
Log::error($e->getMessage());
return response($e->getMessage(), 500);
}
}

I have PRINCE_PATH set to '/usr/lib/prince/bin/prince'

I have added this to the sudoers file:

apache ALL=(user) NOPASSWORD: /usr/lib/prince/bin/prince


Is there something I am missing?
mikeday
It might be good to double-check by explicitly specifying "/usr/lib/prince/bin/prince" (or just "/usr/bin/prince") as the executable path and a simple HTML string like "<h1>Hello</h1>".

Also can you successfully run Prince on the server from the terminal?
tjbryant
Yea, I've tried /usr/bin and /user/lib/bin/prince/bin/prince both in the code with the same result. They both work at the command line.

I tried the simple HTML you suggested and still got back an empty string.

Any other suggestions?
tjbryant
Hmm, I just ran this command on the command line:

/usr/lib/prince/bin/prince test.html -o out.pdf

and got this error:

prince: internal error: no available fonts

Does that help? I didn't see this error in any of the apache/laravel logs.
tjbryant
Actually that was it. I ran yum groupinstall fonts and then the code worked.

thanks.
tjbryant
Is there anything that needs to be done to get paged media to work on redhat? I noticed that page numbers which were showing up under windows are not showing up now that I have moved to the redhat dev server. This is the css I am using.

@page:left {
@bottom-left {
content: counter(page) ' of ' counter(pages);
}
}
@page:right {
@bottom-right {
content: counter(page) ' of ' counter(pages);
}
}
mikeday
That should work fine; is it an external style sheet?
tjbryant
Because I am sending the html to a service that is converting it to PDF, I am inserting the css into a <style> tag in the header.
tjbryant
Sorry, I should have said in <head> not in the header.
mikeday
That should work then, does it work if you run Prince on the same HTML from the command-line?