2012-01-05 47 views

回答

2

我開始PHP的輸出緩衝,那麼就產生LaTeX的代碼,就像你生成HTML代碼。之後檢索緩衝區,併爲其添加一個LaTeX生成器。例如:

<?php ob_start(); ?> 
\documentclass{article} 
\begin{document} 
\section{Title} 
\subsection{Subtitle} 
Plain text. 
\subsection{Another subtitle} 
More plain text. :-P 
\end{document} 
<?php 
    $latex = ob_get_clean(); 
    $file = tmpnam('/tmp'); 
    file_put_contents($file, $latex); 
    exec('latex --output /path/to/your/result.pdf '.escapeshellarg($file)); 
    unlink($file); 
?> 

請注意,上面的代碼具有僞代碼的狀態。我只是從記憶和受過教育的猜測中寫出東西,而不是測試任何東西。但是這個原則應該起作用。