コード例 #1
0
<?php

include_once 'data.php';
include_once 'functions.php';
include_once 'pdfclass.php';
session_write_close();
// Sanitize PDF filename.
$file = '';
if (!empty($_REQUEST['file'])) {
    $file = preg_replace('/[^a-zA-z0-9\\_\\.pdf]/', '', $_REQUEST['file']);
} else {
    sendError("No PDF provided.");
}
$pdfHandler = new PDFViewer($file);
if (!empty($_GET['extractimage']) && !empty($_GET['image']) && !empty($_GET['x']) && !empty($_GET['y']) && !empty($_GET['width']) && !empty($_GET['height'])) {
    // Extract image from a pdf page image.
    $pdfHandler->extractImage($_GET['image'], $_GET['x'], $_GET['y'], $_GET['width'], $_GET['height']);
} elseif (!empty($_GET['renderpdf']) && !empty($_GET['page'])) {
    // Create page image.
    $pdfHandler->createPageImage($_GET['page']);
} elseif (isset($_GET['renderthumbs']) && !empty($_GET['from'])) {
    // Create thumbs.
    $pdfHandler->createPageThumbs($_GET['from']);
} elseif (isset($_GET['renderbookmarks'])) {
    // Extract bookmarks.
    echo $pdfHandler->extractBookmarks();
} elseif (isset($_GET['rendertext'])) {
    // Extract text into database.
    $pdfHandler->extractXMLText();
} elseif (isset($_GET['gettextlayer']) && !empty($_GET['from'])) {
    // Get text from the database.
コード例 #2
0
ファイル: icon.php プロジェクト: jamesscottbrown/i-librarian
header("Cache-Control: max-age={$seconds_to_cache}");
header("Cache-Control: private");
header('Last-Modified: ' . gmdate(DATE_RFC1123, filemtime($pdf_path . DIRECTORY_SEPARATOR . $file)));
// Content type
header('Content-Type: image/jpeg');
header("Content-Disposition: inline");
// Output from cache
if (is_readable($icon) && filemtime($pdf_path . DIRECTORY_SEPARATOR . $file) < filemtime($icon)) {
    ob_clean();
    flush();
    readfile($icon);
    die;
}
// Make big image if not found
if (!is_readable($image) || filemtime($image) < filemtime($pdf_path . DIRECTORY_SEPARATOR . $file)) {
    $pdfHandler = new PDFViewer($file);
    $pdfHandler->createPageImage(1);
}
// Icon dimensions
$new_width = 720;
$new_height = 480;
if (!is_readable($image)) {
    // Error! Ghostscript DOES NOT WORK
    $image_p = imagecreate($new_width, $new_height);
    $background_color = imagecolorallocate($image_p, 255, 255, 255);
    $text_color = imagecolorallocate($image_p, 255, 0, 0);
    imagestring($image_p, 3, 20, 20, "Error! Program Ghostscript not functional.", $text_color);
} else {
    // Resample
    list($width, $height) = getimagesize($image);
    $image_p = imagecreatetruecolor($new_width, $new_height);
コード例 #3
0
<?php

include_once 'data.php';
include_once 'functions.php';
include_once 'pdfclass.php';
session_write_close();
// Sanitize PDF filename.
$file = '';
if (!empty($_GET['file'])) {
    $file = preg_replace('/[^a-zA-z0-9\\_\\.pdf]/', '', $_GET['file']);
} else {
    displayError("No PDF provided.");
}
// Start the PDFViewer class.
$pdfHandler = new PDFViewer($file);
// Get page number and sizes.
$page_info = $pdfHandler->getPageInfo();
$page_number = $page_info['page_number'];
$page_sizes = $page_info['page_sizes'];
// Initial page number.
$page = $pdfHandler->getInitialPageNumber();
// Image resolutions in PPI.
$thumb_res = $pdfHandler->thumb_resolution;
$page_res = $pdfHandler->page_resolution;
// Display PDF file.
if (!isset($_GET['inline'])) {
    ?>

    <!DOCTYPE html>
    <html style="width:100%;height:100%">
        <head>
コード例 #4
0
ファイル: index.php プロジェクト: aaronsaray/aaronsaray.com
     * @param $filePath
     * @param $cacheLocation
     */
    protected function processFileToImageCache($filePath, $cacheLocation)
    {
        if (!is_dir($cacheLocation)) {
            mkdir($cacheLocation);
        }
        $imagick = new \Imagick();
        $imagick->setResolution(150, 150);
        $imagick->readImage($filePath);
        $imagick->writeImages($cacheLocation . '/rendered.jpg', true);
    }
}
ob_start();
$pdfViewer = new PDFViewer();
// NO ACTION means to just show the list
if (!isset($_GET['action'])) {
    $PDFs = $pdfViewer->getPDFList();
    if (empty($PDFs)) {
        echo '<p>There are no PDFs available.</p>';
    } else {
        echo '<p>Choose a file:</p>';
        echo '<ul>';
        foreach ($PDFs as $pdf) {
            $filename = basename($pdf);
            echo "<li><a href='?action=view&file={$filename}'>{$filename}</a></li>";
        }
        echo '</ul>';
    }
} else {