1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?php
// src/files.php
//
// fonctions pour manipuler les fichiers latex et pdf
function makeFile($path, $file_name, $data)
{
file_put_contents($path. $file_name, $data);
chmod($path . $file_name, 0644); // droits en octal
//~ protected function createFile(string $latex, string $file_name, string $latexPath)
//~ {
//~ // nom du fichier créé = nom.tex
//~ // pour les devis, factures et enveloppes, le nom est le code la prestation
//~ // pour les livre de recettes et registres des achats mensuels:
//~ // le nom du fichier suit cet exemple: "Recettes-2022-06-Juin.tex"
//~ // pour le livre de recette ou le registre des achats annuel, même principe: "Achats-2022.tex"
//~ // pour le bilan comptable annuel, ça donne: "Bilan-2022.tex"
//~ $fichier = fopen($latexPath . $file_name, "w+");
//~ fputs($fichier, $latex);
//~ fclose($fichier);
//~ }
}
function makeFolder(string $path)
{
if(!file_exists($path))
{
mkdir($path);
chmod($path, 0755); // droits en octal
}
}
// commande système pdflatex
function latexToPdf(string $latex_path, string $file_name, string $pdf_path)
{
// paramètre optionnel
$output_dir = '';
if($pdf_path !== '')
{
$output_dir = '-output-directory=' . $pdf_path . ' ';
}
// compilation
//echo 'pdflatex ' . $output_dir . $latex_path . $file_name . "\n";
exec('pdflatex ' . $output_dir . $latex_path . $file_name);
// nettoyage
$basename = basename($file_name, '.tex');
unlink($pdf_path . $basename . '.aux');
unlink($pdf_path . $basename . '.log');
}
function makeTexAndPdf(Object $Object) // paramètre = enfant de Latex
{
if(get_class($Object) !== 'EnveloppeVersoLatex')
{
makeFolder($Object->getLatexPath());
makeFolder($Object->getPdfPath());
}
makeFile($Object->getLatexPath(), $Object->getFileName(), $Object->getLatex()); // fichier .tex
latexToPdf($Object->getLatexPath(), $Object->getFileName(), $Object->getPdfPath()); // fichier .pdf avec pdflatex
}
//~ function removeFile(Object $Object)
//~ {}
|