Beispiel #1
0
file_put_contents($output_path . "tiger_100dpi_rot90.raw", $bmp->GetBuffer());
echo nl2br("Example 3: " . $output_path . "tiger_100dpi_rot90.raw. Done.\n");
$draw->SetRotate(Page::e_0);
// Disable image rotation for remaining samples.
//--------------------------------------------------------------------------------
// Example 4) Convert PDF page to a fixed image size. Also illustrates some
// other features in PDFDraw class such as rotation, image stretching, exporting
// to grayscale, or monochrome.
// Initialize render 'gray_hint' parameter, that is used to control the
// rendering process. In this case we tell the rasterizer to export the image as
// 1 Bit Per Component (BPC) image.
$mono_hint = $hint_set->CreateDict();
$mono_hint->PutNumber("BPC", 1);
// SetImageSize can be used instead of SetDPI() to adjust page  scaling
// dynamically so that given image fits into a buffer of given dimensions.
$draw->SetImageSize(1000, 1000);
// Set the output image to be 1000 wide and 1000 pixels tall
$draw->Export($page, $output_path . "tiger_1000x1000.png", "PNG", $mono_hint);
echo nl2br("Example 4: " . $output_path . "tiger_1000x1000.png. Done.\n");
$draw->SetImageSize(200, 400);
// Set the output image to be 200 wide and 300 pixels tall
$draw->SetRotate(Page::e_180);
// Rotate all pages 90 degrees clockwise.
// 'gray_hint' tells the rasterizer to export the image as grayscale.
$gray_hint = $hint_set->CreateDict();
$gray_hint->PutName("ColorSpace", "Gray");
$draw->Export($page, $output_path . "tiger_200x400_rot180.png", "PNG", $gray_hint);
echo nl2br("Example 4: " . $output_path . "tiger_200x400_rot180.png. Done.\n");
$draw->SetImageSize(400, 200, false);
// The third parameter sets 'preserve-aspect-ratio' to false.
$draw->SetRotate(Page::e_0);
// Set the default viewing preference to display 'Layer' tab.
$prefs = $doc->GetViewPrefs();
$prefs->SetPageMode(PDFDocViewPrefs::e_UseOC);
$doc->Save($output_path . "pdf_layers.pdf", SDFDoc::e_linearized);
echo nl2br("Done.\n");
// The following is a code snippet shows how to selectively render
// and export PDF layers.
$doc = new PDFDoc($output_path . "pdf_layers.pdf");
$doc->InitSecurityHandler();
if (!$doc->HasOC()) {
    echo nl2br("The document does not contain 'Optional Content'\n");
} else {
    $init_cfg = $doc->GetOCGConfig();
    $ctx = new Context($init_cfg);
    $pdfdraw = new PDFDraw();
    $pdfdraw->SetImageSize(1000, 1000);
    $pdfdraw->SetOCGContext($ctx);
    // Render the page using the given OCG context.
    $page = $doc->GetPage(1);
    // Get the first page in the document.
    $pdfdraw->Export($page, $output_path . "pdf_layers_default.png");
    // Disable drawing of content that is not optional (i.e. is not part of any layer).
    $ctx->SetNonOCDrawing(false);
    // Now render each layer in the input document to a separate image.
    $ocgs = $doc->GetOCGs();
    // Get the array of all OCGs in the document.
    if ($ocgs != null) {
        $sz = $ocgs->Size();
        for ($i = 0; $i < $sz; ++$i) {
            $ocg = new Group($ocgs->GetAt($i));
            $ctx->ResetStates(false);