[composer.mpdf] added PDF lib [public_html.pdf.php] PDF basics + layout

This commit is contained in:
xdrm-brackets 2018-03-19 23:03:47 +01:00
parent bef4dad5f7
commit 228bdddd2d
6 changed files with 581 additions and 2 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
/public_html/js /public_html/js
/node_modules /node_modules
/backup /backup
/tmp

View File

@ -27,6 +27,8 @@
"require": { "require": {
"phpoffice/phpspreadsheet": "^1.1", "phpoffice/phpspreadsheet": "^1.1",
"phpstan/phpstan": "^0.9.2", "phpstan/phpstan": "^0.9.2",
"ifsnop/mysqldump-php": "2.*" "ifsnop/mysqldump-php": "2.*",
"setasign/fpdf": "1.8.1",
"mpdf/mpdf": "^7.0"
} }
} }

252
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "28e31e7da9313d9726a26a4f36bf06a3", "content-hash": "d300af5ed297b7cdfbfda9d2604a8f95",
"packages": [ "packages": [
{ {
"name": "ifsnop/mysqldump-php", "name": "ifsnop/mysqldump-php",
@ -109,6 +109,73 @@
], ],
"time": "2018-01-21T13:54:22+00:00" "time": "2018-01-21T13:54:22+00:00"
}, },
{
"name": "mpdf/mpdf",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/mpdf/mpdf.git",
"reference": "5681a0cae1eea197143d5d27f06e19b0523cd8d6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mpdf/mpdf/zipball/5681a0cae1eea197143d5d27f06e19b0523cd8d6",
"reference": "5681a0cae1eea197143d5d27f06e19b0523cd8d6",
"shasum": ""
},
"require": {
"ext-gd": "*",
"ext-mbstring": "*",
"paragonie/random_compat": "^1.4|^2.0",
"php": "^5.6 || ~7.0.0 || ~7.1.0 || ~7.2.0",
"psr/log": "^1.0",
"setasign/fpdi": "1.6.*"
},
"require-dev": {
"mockery/mockery": "^0.9.5",
"phpunit/phpunit": "^5.0",
"squizlabs/php_codesniffer": "^2.7.0",
"tracy/tracy": "^2.4"
},
"suggest": {
"ext-bcmath": "Needed for generation of some types of barcodes",
"ext-xml": "Needed mainly for SVG manipulation",
"ext-zlib": "Needed for compression of embedded resources, such as fonts"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-development": "7.0-dev"
}
},
"autoload": {
"psr-4": {
"Mpdf\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0"
],
"authors": [
{
"name": "Matěj Humpál",
"role": "Developer, maintainer"
},
{
"name": "Ian Back",
"role": "Developer (retired)"
}
],
"description": "A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support",
"homepage": "https://mpdf.github.io",
"keywords": [
"pdf",
"php",
"utf-8"
],
"time": "2018-01-03T07:32:36+00:00"
},
{ {
"name": "nette/bootstrap", "name": "nette/bootstrap",
"version": "v2.4.5", "version": "v2.4.5",
@ -673,6 +740,54 @@
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"time": "2018-02-05T13:05:30+00:00" "time": "2018-02-05T13:05:30+00:00"
}, },
{
"name": "paragonie/random_compat",
"version": "v2.0.11",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/5da4d3c796c275c55f057af5a643ae297d96b4d8",
"reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8",
"shasum": ""
},
"require": {
"php": ">=5.2.0"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"autoload": {
"files": [
"lib/random.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"pseudorandom",
"random"
],
"time": "2017-09-27T21:40:39+00:00"
},
{ {
"name": "phpoffice/phpspreadsheet", "name": "phpoffice/phpspreadsheet",
"version": "1.2.0", "version": "1.2.0",
@ -867,6 +982,53 @@
"description": "PHPStan - PHP Static Analysis Tool", "description": "PHPStan - PHP Static Analysis Tool",
"time": "2018-01-28T13:22:19+00:00" "time": "2018-01-28T13:22:19+00:00"
}, },
{
"name": "psr/log",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"time": "2016-10-10T12:19:37+00:00"
},
{ {
"name": "psr/simple-cache", "name": "psr/simple-cache",
"version": "1.0.1", "version": "1.0.1",
@ -915,6 +1077,94 @@
], ],
"time": "2017-10-23T01:57:42+00:00" "time": "2017-10-23T01:57:42+00:00"
}, },
{
"name": "setasign/fpdf",
"version": "1.8.1",
"source": {
"type": "git",
"url": "https://github.com/Setasign/FPDF.git",
"reference": "2c68c9e6c034ac3187d25968790139a73184cdb1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Setasign/FPDF/zipball/2c68c9e6c034ac3187d25968790139a73184cdb1",
"reference": "2c68c9e6c034ac3187d25968790139a73184cdb1",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"fpdf.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"no usage restriction"
],
"authors": [
{
"name": "Olivier Plathey",
"email": "oliver@fpdf.org",
"homepage": "http://fpdf.org/"
}
],
"description": "FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.",
"homepage": "http://www.fpdf.org",
"keywords": [
"fpdf",
"pdf"
],
"time": "2016-01-01T17:47:15+00:00"
},
{
"name": "setasign/fpdi",
"version": "1.6.2",
"source": {
"type": "git",
"url": "https://github.com/Setasign/FPDI.git",
"reference": "a6ad58897a6d97cc2d2cd2adaeda343b25a368ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Setasign/FPDI/zipball/a6ad58897a6d97cc2d2cd2adaeda343b25a368ea",
"reference": "a6ad58897a6d97cc2d2cd2adaeda343b25a368ea",
"shasum": ""
},
"suggest": {
"setasign/fpdf": "FPDI will extend this class but as it is also possible to use \"tecnickcom/tcpdf\" as an alternative there's no fixed dependency configured.",
"setasign/fpdi-fpdf": "Use this package to automatically evaluate dependencies to FPDF.",
"setasign/fpdi-tcpdf": "Use this package to automatically evaluate dependencies to TCPDF."
},
"type": "library",
"autoload": {
"classmap": [
"filters/",
"fpdi.php",
"fpdf_tpl.php",
"fpdi_pdf_parser.php",
"pdf_context.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jan Slabon",
"email": "jan.slabon@setasign.com",
"homepage": "https://www.setasign.com"
}
],
"description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.",
"homepage": "https://www.setasign.com/fpdi",
"keywords": [
"fpdf",
"fpdi",
"pdf"
],
"time": "2017-05-11T14:25:49+00:00"
},
{ {
"name": "symfony/console", "name": "symfony/console",
"version": "v4.0.6", "version": "v4.0.6",

Binary file not shown.

231
public_html/pdf.php Normal file
View File

@ -0,0 +1,231 @@
<?php require_once '../vendor/autoload.php';
/* (1) Initialize PDF
---------------------------------------------------------*/
/* (1) Get Font default directory */
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
/* (2) Get Font data */
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
/* (3) Create PDF file */
$pdf = new \Mpdf\Mpdf([
'mode' => 'utf-8',
'defaultCssFile' => __PUBLIC__.'/css/pdf.css',
'tempDir' => __ROOT__.'/tmp',
'fontDir' => array_merge($fontDirs, [ __PUBLIC__.'/font/' ]),
'fontdata' => $fontData + [
'Fira Sans' => [
'R' => 'FiraSans-Regular.ttf'
]
],
'default_font' => 'Fira Sans'
]);
/* (4) Set PDF title */
$pdf->SetTitle('Some PDF title');
/* (5) Store SVG */
$svg_warning = '<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" height="10" width="10" viewBox="0 0 1792 1792">
<path d="m 1024,1375 v -190 q 0,-14 -9.5,-23.5 Q 1005,1152 992,1152 H 800 q -13,0 -22.5,9.5 -9.5,9.5 -9.5,23.5 v 190 q 0,14 9.5,23.5 9.5,9.5 22.5,9.5 h 192 q 13,0 22.5,-9.5 9.5,-9.5 9.5,-23.5 z m -2,-374 18,-459 q 0,-12 -10,-19 -13,-11 -24,-11 H 786 q -11,0 -24,11 -10,7 -10,21 l 17,457 q 0,10 10,16.5 10,6.5 24,6.5 h 185 q 14,0 23.5,-6.5 9.5,-6.5 10.5,-16.5 z m -14,-934 768,1408 q 35,63 -2,126 -17,29 -46.5,46 -29.5,17 -63.5,17 H 128 Q 94,1664 64.5,1647 35,1630 18,1601 -19,1538 16,1475 L 784,67 q 17,-31 47,-49 30,-18 65,-18 35,0 65,18 30,18 47,49 z" style="fill: #ea4b35" />
</svg>';
/* (2) Set Header|Footer
---------------------------------------------------------*/
/* (1) Set Header content (Left, Right) */
$header_content = [
'C' => [ 'color' => '#aaa', 'content' => 'Fiche enseignant Sophie Gouardères (sgouarde)' ],
'line' => 1
];
/* (2) Apply Header */
$pdf->setHeader([
'odd' => $header_content,
'even' => $header_content
]);
/* (1) Set Footer content (Left, Right) */
$footer_content = [
'L' => [ 'color' => '#aaa', 'content' => 'Généré le @date_création' ],
'R' => [ 'color' => '#aaa', 'content' => 'Page {PAGENO} sur {nbpg}' ],
'line' => 1
];
/* (2) Apply Footer */
$pdf->setFooter([
'odd' => $footer_content,
'even' => $footer_content
]);
/* (3) Page 1 - Récapitulatif
---------------------------------------------------------*/
/* (1) Initialize page */
$pdf->AddPage();
/* (2) Write content */
$pdf->WriteHTML('<br>
<h3>1. Récapitulatif</h3>
<hr>
<article>
<p>
Mollitia quo ullam voluptas quia delectus nihil ab. (<a href="https://git.xdrm.io">cliquer ici</a>) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut
</p>
<blockquote>
Mollitia quo ullam voluptas quia delectus nihil ab. Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut
</blockquote>
<p class="warning">
Mollitia quo ullam voluptas quia delectus nihil ab. (<a href="https://git.xdrm.io">cliquer ici</a>) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut
</p>
<table>
<thead>
<tr>
<td class="color ac">Donnée</td>
<td class="color ac">Valeur</td>
</tr>
</thead>
<tbody>
<tr>
<td class="ar">Heures à faire</td>
<td>192 h</td>
</tr>
<tr>
<td class="ar">Equivalents TD</td>
<td>241.41 h</td>
</tr>
<tr>
<td class="ar">Heures programmées</td>
<td>217.5 h</td>
</tr>
<tr>
<td class="ar">Heures manquantes</td>
<td>'.$svg_warning.' 10 h </td>
</tr>
<tr>
<td class="ar">Heures sup.</td>
<td>0</td>
</tr>
</tbody>
</table>
</article>
');
/* (4) Page 2 - Enseignements
---------------------------------------------------------*/
/* (1) Initialize page */
$pdf->AddPage();
/* (2) Write content */
$pdf->WriteHTML('<br>
<h3>2. Enseignements</h3>
<hr>
<article>
<p>
Mollitia quo ullam voluptas quia delectus nihil ab. (<a href="https://git.xdrm.io">cliquer ici</a>) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut
</p>
<blockquote>
Mollitia quo ullam voluptas quia delectus nihil ab. Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut
</blockquote>
<p>
Mollitia quo ullam voluptas quia delectus nihil ab. (<a href="https://git.xdrm.io">cliquer ici</a>) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut
</p>
<br><br><br>
<table>
<thead>
<tr>
<th colspan="5" class="ac">Liste des enseignements programmés</th>
</tr>
<tr>
<td class="color ac">Code UE</td>
<td class="color ac">Nom UE</td>
<td class="color ac">Prestation</td>
<td class="color ac">volume horaire</td>
<td class="color ac">formations</td>
</tr>
</thead>
<tbody>
<tr>
<td>T0XALA2V</td>
<td>Algorithmique avancée</td>
<td>Cours</td>
<td>13.5 heures</td>
<td><ul>
<li>MIASHS</li>
<li>L1 INFO (S2)</li>
</ul></td>
</tr>
<tr>
<td>T0XALA2V</td>
<td>Algorithmique avancée</td>
<td>TD</td>
<td>22 heures</td>
<td><ul>
<li>L1 INFO (S2)</li>
</ul></td>
</tr>
<tr>
<td>T0XALA2V</td>
<td>Algorithmique avancée</td>
<td>TP</td>
<td>5 heures</td>
<td><ul>
<li>MIASHS</li>
<li>L1 INFO (S2)</li>
<li>L2 INFO (S2)</li>
</ul></td>
</tr>
<tr>
<td>T0MSAP3U</td>
<td>Algorithmique et programmation avancée</td>
<td>TP</td>
<td>12 heures</td>
<td><ul>
<li>MIASHS</li>
<li>L1 INFO (S2)</li>
<li>L2 INFO (S2)</li>
</ul></td>
</tr>
</tbody>
</table>
</article>
');
/* (N) Print out PDF file
---------------------------------------------------------*/
$pdf->Output();

95
webpack/scss/pdf.scss Normal file
View File

@ -0,0 +1,95 @@
/* (1) Reset
---------------------------------------------------------*/
*{
margin: 0;
padding: 0;
}
body{
background-color: #fff;
font-size: 16px;
color: #444;
}
/* (2) Basic layout
---------------------------------------------------------*/
article{
// Titles
h3{
color: #555;
}
// Titles' separators
hr{
display: block;
border-style: solid;
border-width: 1px;
}
// paragraphs
p{
text-indent: 2em;
}
// links
a{
color: #2d92cc;
text-decoration: underline;
}
// quotes
blockquote{
margin-left: 0;
padding-left: 1em;
border-left: 2px solid #eee;
color: #999;
}
// tables
table{
border-collapse: collapse;
color: #555;
tr{
td{
padding: .2em 1em;
border: 1px dotted rgb(221, 221, 221);
background-color: #fff;
}
// each other row is darker
&:nth-child(2n) td{
background-color: #eee;
}
}
// table headers bold revert
thead tr th{
font-weight: normal;
}
thead tr td.color,
thead tr th.color{
background-color: rgb(75, 189, 209);
color: #fff;
}
td.ar{ text-align: right; }
td.ac{ text-align: center; }
td.al{ text-align: left; }
}
}