Η μετατροπή PDF σε SWF (Flash) επιτρέπει την εμφάνιση εγγράφων ως interactive'animations στο web. Σημαντικό: Το Flash έχει αποκατασταθεί (EOL 31 Δεκεμβρίου 2020) και δεν υποστηρίζεται από σύγχρονους browsers. Αυτός ο οδηγός είναι για ιστορικούς/legacy λόγους.
<embed>, <object>, <iframe>Προαπαιτούμενα: Windows Server, SWFTools εγκατεστημένο, PHP COM extension ενεργοποιημένο.
https://www.swftools.org/C:\SWFTools\)pdf2swf.exe υπάρχει<?php
// Ρυθμίσεις paths
$softwarePath = "C:\\SWFTools\\pdf2swf.exe";
$pdfPath = "C:\\SWFTools\\document.pdf";
$swfOutput = "C:\\SWFTools\\document.swf";
// Arguments: -o output.swf input.pdf
$arguments = "-o \"$swfOutput\" \"$pdfPath\"";
// Πλήρης εντολή
$cmd = "\"$softwarePath\" $arguments";
// Εκτέλεση μέσω COM (Windows Script Host)
try {
$wshShell = new COM("WScript.Shell");
// 0 = hidden, true = wait for completion
$returnCode = $wshShell->Run("cmd /C $cmd", 0, true);
if ($returnCode === 0) {
echo "Μετατροπή ολοκληρώθηκε: $swfOutput";
// Optional: Serve το SWF
if (file_exists($swfOutput)) {
header('Content-Type: application/x-shockwave-flash');
header('Content-Disposition: inline; filename="document.swf"');
readfile($swfOutput);
}
} else {
echo "Σφάλμα μετατροπής. Exit code: $returnCode";
}
} catch (com_exception $e) {
echo "COM Exception: " . $e->getMessage();
}
?>
convert.phpphp convert.php<?php
// serve_pdf.php
$file = __DIR__ . '/protected_docs/' . basename($_GET['file']);
// Security checks
if (!file_exists($file) || !is_readable($file)) {
http_response_code(404);
exit("File not found");
}
// Validate PDF
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $file);
finfo_close($finfo);
if ($mime !== 'application/pdf') {
http_response_code(400);
exit("Not a PDF");
}
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . basename($file) . '"');
header('Content-Length: ' . filesize($file));
header('X-Content-Type-Options: nosniff');
readfile($file);
?>
<!DOCTYPE html>
<html>
<head>
<title>PDF Viewer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<style>
#viewer { width: 100%; height: 800px; border: 1px solid #ccc; }
</style>
</head>
<body>
<canvas id="viewer"></canvas>
<script>
const url = 'serve_pdf.php?file=document.pdf';
pdfjsLib.getDocument(url).promise.then(pdf => {
pdf.getPage(1).then(page => {
const canvas = document.getElementById('viewer');
const context = canvas.getContext('2d');
const viewport = page.getViewport({ scale: 1.5 });
canvas.height = viewport.height;
canvas.width = viewport.width;
page.render({ canvasContext: context, viewport: viewport });
});
});
</script>
</body>
</html>
| Χαρακτηριστικό | SWFTools (Legacy) | PDF.js (Modern) |
|---|---|---|
| Browser Support | Μόνο παλιούς (IE, Flash plugin) | Όλοι οι σύγχρονοι |
| Mobile | Όχι | Ναι |
| Performance | Server-side rendering | Client-side GPU accelerated |
| Search/Select Text | Λιγότερο ακριβές | Πλήρης υποστήριξη |
| Security | COM execution risks | Sandboxed JS |
Αποφύγετε SWF/Flash για νέα projects. Χρησιμοποιήστε PDF.js ή native browser embedding. Το SWFTools είναι'abandoned project (τελευταία έκδοση 2012).
Πνευματικά δικαιώματα © Γνώση Υπολογιστών Όλα τα δικαιώματα διατηρούνται.