function main() { global $inputPath, $outputPath; PDFNet::Initialize(); // Sample 1: // Directly convert from PDF to XOD. echo nl2br("Converting: " . $inputPath . "newsletter.pdf" . " to " . $outputPath . "from_pdf.xod" . "\n"); Convert::ToXod($inputPath . "newsletter.pdf", $outputPath . "from_pdf.xod"); // Sample 2: // Directly convert from generic XPS to XOD. echo nl2br("Converting: " . $inputPath . "simple-xps.xps" . " to " . $outputPath . "from_xps.xod" . "\n"); Convert::ToXod($inputPath . "simple-xps.xps", $outputPath . "from_xps.xod"); // Sample 3: // Directly convert from PNG to XOD. echo nl2br("Converting: " . $inputPath . "butterfly.png" . " to " . $outputPath . "butterfly.xod" . "\n"); Convert::ToXod($inputPath . "butterfly.png", $outputPath . "butterfly.xod"); // Sample 4: // Directly convert from JPG to XOD. echo nl2br("Converting: " . $inputPath . "dice.jpg" . " to " . $outputPath . "dice.xod" . "\n"); Convert::ToXod($inputPath . "dice.jpg", $outputPath . "dice.xod"); echo nl2br("Done.\n"); }
debugLog("File not found: \"" . $FILE_DIR . $fileName . "\""); // send 404 header("HTTP/1.1 404 Not Found"); echo "<h1>404 Not Found</h1><br/>"; echo "File \"" . $fileName . "\" cannot be found."; return; } debugLog("Converting and streaming file: \"" . $FILE_DIR . $fileName . "\"..."); // set the correct content-type header("Content-Type: application/vnd.ms-xpsdocument"); PDFNet::Initialize(); // set the conversion option to not create thumbnails on XOD files because // they will not be streamed back to the client. $xodOptions = new XODOutputOptions(); $xodOptions->SetOutputThumbnails(false); $filter = Convert::ToXod(realpath($FILE_DIR . $fileName), $xodOptions); $fReader = new FilterReader($filter); $bufferSize = 64 * 1024; $totalBytes = 0; debugLog("Start streaming..."); do { $buffer = $fReader->Read($bufferSize); echo $buffer; flush(); // prevents buffering the response so the client can receive them as they are written to the stream. $totalBytes += strlen($buffer); debugLog("Sent total: " . $totalBytes . " bytes"); } while (strlen($buffer) > 0); debugLog("Done."); } catch (Exception $e) { debugLog($e->getMessage());