转义可能是一个部分,另一个是调用命令pdflatex
;我绕开(第一)通过对变量,以便pdflatex
更换的意见和换行符之前以书面文件和(二)具有与它再也没问题......
<?php
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
$texscript = '\documentclass[12pt,a4paper]{article}
\usepackage{helvet}
\usepackage{times}
\usepackage{multido}
\usepackage{fancyhdr}
\usepackage[hmargin=.8cm,vmargin=1.5cm,nohead,nofoot]{geometry}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\fancyhf{} % clear all header and footer fields
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
%\rhead{{\large\bfseries\thepage}}
\rhead{{\fbox{\large\bfseries\thepage}}}
\setcounter{page}{1}
\multido{}{1383}{\vphantom{x}\newpage}
\end{document}
';
//write code to file
$fn="texfile.tex";
$myfile = fopen($fn, "w");
fwrite($myfile, $texscript);
fclose($myfile);
//then execute pdflatex with parameter
//didnt need
//echo $PATH > myenv;
$pdflatex = shell_exec('pdflatex ' .$fn .'');
//var_dump($pdflatex);
//test for success
if (!file_exists("texfile.pdf")){
print_r(file_get_contents("texfile.log"));
} else {
echo "PDF crated from file\n";
}
//trying same without file
//removed comments and newlines
$texscript = preg_replace('/[ \t]*\%.*[ \t]*[\r\n]+/', '', $texscript);
$texscript = preg_replace('/[\r\n]+/', '', $texscript);
//ahve a look on the variable
//var_dump($texscript);
$pdflatex = shell_exec('pdflatex "' .$texscript.'"');
if (!file_exists("article.pdf")){
print_r( file_get_contents("article.log"));
} else {
echo "PDF created from String\n";
}
?>
它不应该的问题写TEX文件以及pdflatex将会写入所需PDF以外的文件。
还添加了正则表达式来替换comments/newline。
我打电话的脚本:php test.php
与GNU/Linux的Debian的8
CLI这将产生输出:
PDF crated from file
string(405) "\documentclass[12pt,a4paper]{article}\usepackage{helvet}\usepackage{times}\usepackage{multido}\usepackage{fancyhdr}\usepackage[hmargin=.8cm,vmargin=1.5cm,nohead,nofoot]{geometry}\renewcommand{\familydefault}{\sfdefault}\begin{document}\fancyhf{}\renewcommand{\headrulewidth}{0pt}\pagestyle{fancy}\rhead{{\fbox{\large\bfseries\thepage}}}\setcounter{page}{1}\multido{}{1}{\vphantom{x}\newpage}\end{document}"
PDF created from String
和PDF文件工作和具有相同的文件大小:
-rw-r--r-- 1 vv01f vv01f 3360 Mai 5 article.pdf
-rw-r--r-- 1 vv01f vv01f 3360 Mai 5 texfile.pdf
1.''“'(couble quotes)中的代码需要转义或者使用''''(单引号)代替。 2. pdflatex需要一个文件或通过管道输入,如'cat t.tex | pdflatex' 3.尝试将输出转向另一个目录,您可以使用'pdflatex'命令的'-output-directory'选项来写入其他目录。或给权写在他非常相同的目录 – vv01f
也考虑更新,如果可能,因为你的版本已经超过一年已经 – vv01f
我试过单引号..still给出了相同的错误 – mira