42947

Compiling a latex document from PHP [duplicate]

Question:

This question already has an answer here:

<ul><li> <a href="/questions/11240725/how-can-i-get-php-to-compile-a-latex-document-if-it-www-data-cant-get-access" dir="ltr" rel="nofollow">How can I get PHP to compile a LaTeX document if it (www-data) can't get access to the required packages?</a> <span class="question-originals-answer-count"> 4 answers </span> </li> </ul>

I want to use the shell_exec command to compile a very simple latex file in order to generate a report of sorts in the webpage.

I move to the folder where I created the tex file. If I issue the command (from console, by typing)

pdflatex report.tex

Everything works as expected.

The first thing I have tried is issuing the command in php:

$cmd_out = shell_exec("pdflatex " . $wcopy);

where $wcopy contains the full path of the file to be compiled (report.tex in the example). The latex file contained an image and at first the compilation failed because I was issuing the pdflatex command from the directory where the php script resides and both the picture and the report.tex files are in a different directory. I fixed that problem by modifying the latex file so that the image path is relative the directory where the php script is located.

The next time I tried to run the script I get this very misterious message from pdflatex:

pdfTeX error: pdflatex (file ecrm1095): Font ecrm1095 at 600 not found

I believe this has something to do the php function shell_exec, although I'm not sure.

Can any one tell me what I might be doing wrong? I added the whole bit of the image, because I think it might be a clue.

EDIT:

Adding requested information. The server is running in a Debian Linux Distribution and the user that will execute those commands is www-data

Answer1:

This is running as part of a web page, presumably?

The problem is probably that your script is running as a different user. I expect it is running as apache; and apache might well not have the right path configured, or the right Latex setup for finding font directories and the like.

You haven't given much detail as to what system you're running on, but you could try running it as apache to see if you can reproduce the error. If this is Linux, then become root, then go into the right directory, and run

su - apache pdflatex report.tex

to see what happens. To become root, you might be able to use su on its own, if you know the root password; or if you're on Ubuntu, try

sudo bash

to become root (and give it your own password), and then the line I previously suggested to run as apache.

Recommend

  • Error producing PDF from TeX source Error: pandoc document conversion failed with error 43 Execution
  • How to troubleshoot JS dependencies between webjars and scala-js jars in an SBT project?
  • How to load the application in Web-View in a specific browser like Chrome or Firefox in Android
  • tomcat : How to get opened jdbc:oracle connection's stack trace?
  • Why does the address of an object change across methods?
  • In VIm, how to remove all lines that are duplicate somewhere?
  • IE readonly textarea problem
  • 'include' of functions in groovy scripts
  • Is it safe to accept URL parameters for populating the `url_for` method?
  • if some function is not optimized does it mean that all functions where it is declared are not optim
  • How dotnet build chooses the output name
  • How can I let users share their location in Bot Framework webchat channel?
  • Create function that can pass a parameter without making a new component
  • Dynamically load css stylesheet and wait for it to load
  • Access object instance inside an event handler
  • Cannot save model when using ember render helper
  • get iframe content as string
  • Using $compile in a directive triggers AngularJS infinite digest error
  • Retrieve IP address of device
  • Conversion from string “a” to type 'Boolean' is not valid
  • D3 get axis values on zoom event
  • Detect when Facebook like button is clicked
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • x64 applications using gdi+: what are the consequences on performance?
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Android fill_parent issue
  • Why is the size of this struct 32?
  • Get object from AWS S3 as a stream
  • script to move all files from one location to another location
  • ILMerge & Keep Assembly Name
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Symfony2: How to get request parameter
  • Upload files with Ajax and Jquery
  • Do I've to free mysql result after storing it?
  • How to pass list parameters for each object using Spring MVC?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • A cron job substitute?
  • json Serialization in asp
  • Proper way to use connect-multiparty with express.js?