commited all contents created by participants
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
session_start();
|
||||
//include autoloader
|
||||
require_once 'dompdf/autoload.inc.php';
|
||||
|
||||
// reference the Dompdf namespace
|
||||
use Dompdf\Dompdf;
|
||||
|
||||
// instantiate and use the dompdf class
|
||||
$dompdf = new Dompdf();
|
||||
$dompdf->set_option('defaultFont', 'Helvetica');
|
||||
|
||||
// execute shell python commande
|
||||
// change the command with the name of your script
|
||||
$command = escapeshellcmd('python scripts/perec.py');
|
||||
$output = shell_exec($command);
|
||||
//get random word for the cover
|
||||
$word = explode("<p>", $output);
|
||||
$randomWord = $word[rand(0, count($word))];
|
||||
|
||||
|
||||
$dompdf->loadHtml(
|
||||
'<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>PEREC</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
<body class="toPrint">
|
||||
<header>
|
||||
<!-- Change the cover here -->
|
||||
<div class="randomWord">'.$randomWord.'</div>
|
||||
<h1>Frankenstein</h1>
|
||||
<h2>Marie Shelley</h2>
|
||||
</header>
|
||||
|
||||
<main><p>'.
|
||||
$output.
|
||||
'</p></main>
|
||||
</body></html>'
|
||||
);
|
||||
|
||||
//(Optional) Setup the paper size and orientation
|
||||
$dompdf->setPaper('A6', 'portrait');
|
||||
|
||||
// Render the HTML as PDF
|
||||
$dompdf->render();
|
||||
|
||||
// add the header
|
||||
$canvas = $dompdf->get_canvas();
|
||||
|
||||
// Add font for page number
|
||||
$font = $dompdf->getFontMetrics()->get_font("Reglo", "normal");
|
||||
// Add page number
|
||||
$canvas->page_text(145, 390, "{PAGE_NUM} ",$font, 7, array(0,0,0));
|
||||
|
||||
// Output the generated PDF to Browser
|
||||
//Change the name of the pdf by changing "Perec"
|
||||
$dompdf->stream("Perec", array("Attachment" => 0));
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user