Files
Backend/WEBROOT/services/print_static.php
T
2026-03-15 12:31:12 +01:00

77 lines
1.2 KiB
PHP

<?php
$dir = __DIR__ . "/../static";
$files = array_diff(scandir($dir), ['.', '..']);
echo '<button onclick="printFiles()">Alle Dateien drucken</button>';
echo '<div class="print-container">';
foreach ($files as $file) {
$url = "static/" . rawurlencode($file);
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
echo '<div class="print-page">';
if (in_array($ext, ['png','jpg','jpeg','webp'])) {
echo "<img src='$url'>";
}
elseif ($ext === "pdf") {
echo "<embed src='$url' type='application/pdf'>";
}
else {
echo "<p>$file kann nicht direkt gedruckt werden.</p>";
}
echo '</div>';
}
echo '</div>';
?>
<script>
function printFiles() {
console.log("Ich wurde gedrückt");
window.print();
}
</script>
<style>
.print-page {
width: 100%;
height: 100vh;
page-break-after: always;
}
.print-page img {
max-width: 100%;
}
.print-page embed {
width: 100%;
height: 100vh;
}
@media print {
body * {
visibility: hidden;
}
.print-container,
.print-container * {
visibility: visible;
}
.print-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
}
}
</style>