diff options
| author | Georgi Nikolov <ggeorgi60@gmail.com> | 2025-02-04 21:03:44 +0200 |
|---|---|---|
| committer | Georgi Nikolov <ggeorgi60@gmail.com> | 2025-02-04 21:03:44 +0200 |
| commit | 83304592d155b0fed33dcdac3ffdf0b6ca393ab6 (patch) | |
| tree | d014e71838fff983b3c041f0bfc277aca0a1e16c /views | |
| parent | e2e0c2ffd139d3f2a653fbe4ffa110c2d58bcce6 (diff) | |
| download | nowayforward_human-83304592d155b0fed33dcdac3ffdf0b6ca393ab6.tar nowayforward_human-83304592d155b0fed33dcdac3ffdf0b6ca393ab6.tar.gz nowayforward_human-83304592d155b0fed33dcdac3ffdf0b6ca393ab6.zip | |
Added a basic pdf exporter that works 50% of the times
Diffstat (limited to 'views')
| -rw-r--r-- | views/archive/item.php | 7 | ||||
| -rw-r--r-- | views/list/export/index.php | 39 | ||||
| -rw-r--r-- | views/list/export/meta.php | 4 |
3 files changed, 50 insertions, 0 deletions
diff --git a/views/archive/item.php b/views/archive/item.php index 467fb2c..25b1719 100644 --- a/views/archive/item.php +++ b/views/archive/item.php @@ -7,7 +7,14 @@ </div> <div class="details"> <span>Visits: <?= $page->Visits ?></span> + <iframe id="printFrame" src="<?= '/archives/' . $page->WID . '/index.php' ?>" style="display:none;"></iframe> <span class="float-right"><?= Database\User::fromDBuid($page->RequesterUID)->Username ?></span> + <form action="/list/export/index.php" method="GET"> + <input type="hidden" name="wid" value="<?= $page->WID ?>"> + <input type="hidden" name="title" value="<?= $page->Title ?>"> + <input type="hidden" name="url" value="<?= $page->URL ?>"> + <button>Export to PDF</button> + </form> </div> </section> <section name="itemButton" hidden> diff --git a/views/list/export/index.php b/views/list/export/index.php new file mode 100644 index 0000000..6e58405 --- /dev/null +++ b/views/list/export/index.php @@ -0,0 +1,39 @@ +<?php + namespace Dompdf; + + require_once(__DIR__ . '/../../../libs/dompdf/autoload.inc.php'); + use Dompdf\Dompdf; + use Dompdf\Options; + + try { + createWithDOMPDF(); + } + catch (Exception $e) {} + + function createWithDOMPDF() { + $url = $_GET['url']; + $title = $_GET['title']; + $wid = $_GET['wid']; + $archive_dir = __DIR__ . '/../../../.archives/' . $wid; + $html = file_get_contents($archive_dir . '/index.php'); + + $dompdf = new Dompdf(); + $options = $dompdf->getOptions(); + $options->setDefaultFont('DejaVu Sans'); + $options->setIsPhpEnabled(True); + $options->setIsJavascriptEnabled(True); + $options->setIsRemoteEnabled(True); + $options->setChroot($archive_dir . '/../'); + $options->setIsHtml5ParserEnabled(True); + $dompdf->setOptions($options); + $dompdf->setBasePath($archive_dir); + + $dompdf->loadHTML($html); + $dompdf->setBasePath($archive_dir); + $dompdf->setPaper('A4', 'landscape'); + $dompdf->render(); + //$dompdf->stream($title . '.pdf', array('Attachment'=>0)); + // NOTE: Uncomment this to enable the download + $dompdf->stream($title . '.pdf'); + } +?> diff --git a/views/list/export/meta.php b/views/list/export/meta.php new file mode 100644 index 0000000..2546db5 --- /dev/null +++ b/views/list/export/meta.php @@ -0,0 +1,4 @@ +<?php + +$title = 'Export to PDF'; +$controller = 'list'; |
