OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / include / lib / patTemplate / patTemplate / OutputFilter / PdfLatex.php
1 <?PHP
2 /**
3  * patTemplate output filter that creates PDF files from latex
4  *
5  * $Id: PdfLatex.php 440 2008-03-30 09:00:16Z fishbone $
6  *
7  * @package             patTemplate
8  * @subpackage  Filters
9  * @author              Stephan Schmidt <schst@php.net>
10  */
11
12 /**
13  * patTemplate output filter that creates PDF files from latex
14  *
15  * $Id: PdfLatex.php 440 2008-03-30 09:00:16Z fishbone $
16  *
17  * @package             patTemplate
18  * @subpackage  Filters
19  * @author              Stephan Schmidt <schst@php.net>
20  */
21 class patTemplate_OutputFilter_PdfLatex extends patTemplate_OutputFilter
22 {
23    /**
24     * filter name
25         *
26         * This has to be set in the final
27         * filter classes.
28         *
29         * @var  string
30         */
31         var     $_name  =       'PdfLatex';
32
33         var $_params = array(
34                                'cacheFolder' => './'
35                            );
36
37    /**
38         * tidy the data
39         *
40         * @access       public
41         * @param        string          data
42         * @return       string          compressed data
43         */
44         function apply( $data )
45         {
46             $cacheFolder = $this->getParam('cacheFolder');
47             $texFile     = tempnam($cacheFolder, 'pt_tex_') . '.tex';
48             $fp = fopen($texFile, 'w');
49             fwrite($fp, $data);
50             fclose($fp);
51
52             $command = 'pdflatex --interaction=nonstopmode '.$texFile;
53             exec($command);
54             exec($command);
55
56             $pdf = $texFile . '.pdf';
57             $pdf = file_get_contents($pdf);
58
59             return $pdf;
60         }
61 }
62 ?>