developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #130: genericLatex.class.php

File genericLatex.class.php, 2.6 KB (added by Aubanel MONNIER, 13 years ago)

the genericLatex response

Line 
1<?php
2require_once (JELIX_LIB_RESPONSE_PATH.'jResponseText.class.php');
3 
4class genericLatex extends jResponseText {
5 /**
6     * selector of the main template file
7     * This template should contains the body content, and is used by the $body template engine
8     * @var string
9     */
10    public $bodyTpl = '';
11/**
12     * The template engine used to generate the content
13     * @var jTpl
14     */
15    public $body = null;
16/**
17     * Authors of the document
18     * @var array
19     */
20    public $authors = array();
21/**
22     * Document title
23     * @var string
24     */
25    public $title = '';
26
27 /**
28    * constructor;
29    * setup the template engine
30    */
31    function __construct ($attributes=array()){
32        $this->body = new jTpl();
33        parent::__construct($attributes);
34    }
35
36 function output(){
37
38 global $gJConfig;
39       
40        ob_start();
41        echo  '
42 \documentclass[11pt]{article}
43 \usepackage{graphicx}    % needed for including graphics e.g. EPS, PS
44 \topmargin -1.5cm        % read Lamport p.163
45 \oddsidemargin -0.04cm   % read Lamport p.163
46 \evensidemargin -0.04cm  % same as oddsidemargin but for left-hand pages
47 \textwidth 16.59cm
48 \textheight 21.94cm
49 %\pagestyle{empty}       
50 \parskip 7.2pt           % sets spacing between paragraphs
51 %\renewcommand{\baselinestretch}{1.5}  % Uncomment for 1.5 spacing between lines
52 \parindent 0pt           % sets leading space for paragraphs
53\begin{document}
54\title{'.$this->title.'}
55\author{';
56foreach ($this->authors as $a) echo $a.'\\\\'."\n";
57echo'}
58\date{\today}
59\maketitle
60 ';
61 $this->body->display($this->bodyTpl);
62 echo  '
63
64 \end{document}';
65$data= ob_get_contents();
66ob_end_clean();
67
68 $fbase=md5($data);
69 $fpath=JELIX_APP_TEMP_PATH;
70$texFile=$fpath.$fbase.'.tex';
71$pdfFile=$fpath.$fbase.'.pdf';
72
73if (! file_exists($pdfFile)){
74//Naïve cache: we have an md5 on the content of the tex file. If the pdf corresponding to this content already exists, just serve it. No managment of cache deletion :o/
75 jFile::write($texFile, $data);
76 
77 $pdflatex_path='pdflatex';
78 exec('
79TEXMFOUTPUT='.$fpath.' &&
80export TEXMFOUTPUT &&
81TEXINPUTS=:'.$fpath.' &&
82export TEXINPUTS &&
83'.$pdflatex_path.' --interaction=batchmode '.$texFile);
84
85}
86
87        $this->_httpHeaders['Content-Type']='application/pdf';
88        $this->_httpHeaders['Content-length']=@filesize($pdfFile);
89        $this->_httpHeaders['Content-Disposition']='attachment; filename='.$this->title.'.pdf';
90        $this->sendHttpHeaders();
91       
92        readfile($pdfFile);
93        return true;
94 }
95   // modifications communes aux actions utilisant cette reponses
96   protected function _commonProcess(){
97       
98   }
99}
100?>