コード例 #1
0
// A three step tutorial to convert PDF page to an image.
// A) Open the PDF document.
$doc = new PDFDoc($input_path . "tiger.pdf");
// Initialize the security handler, in case the PDF is encrypted.
$doc->InitSecurityHandler();
// B) The output resolution is set to 92 DPI.
$draw->SetDPI(92);
// C) Rasterize the first page in the document and save the result as PNG.
$draw->Export($doc->GetPageIterator()->Current(), $output_path . "tiger_92dpi.png");
echo nl2br("Example 1: " . $output_path . "tiger_92dpi.png" . ". Done.\n");
// Export the same page as TIFF
$draw->Export($doc->GetPageIterator()->Current(), $output_path . "tiger_92dpi.tif", "TIFF");
//--------------------------------------------------------------------------------
// Example 2) Convert the all pages in a given document to JPEG at 72 DPI.
echo nl2br("Example 2:\n");
$hint_set = new ObjSet();
//  A collection of rendering 'hits'.
$doc = new PDFDoc($input_path . "newsletter.pdf");
// Initialize the security handler, in case the PDF is encrypted.
$doc->InitSecurityHandler();
$draw->SetDPI(72);
// Set the output resolution is to 72 DPI.
// Use optional encoder parameter to specify JPEG quality.
$encoder_param = $hint_set->CreateDict();
$encoder_param->PutNumber("Quality", 80);
// Traverse all pages in the document.
for ($itr = $doc->GetPageIterator(); $itr->HasNext(); $itr->Next()) {
    $filename = $output_path . "newsletter" . $itr->Current()->GetIndex() . ".jpg";
    echo nl2br($filename . "\n");
    $draw->Export($itr->Current(), $filename, "JPEG", $encoder_param);
}
コード例 #2
0
// Add a TIFF image to the output file
$img = Image::Create($doc->GetSDFDoc(), $input_path . "grayscale.tif");
$element = $builder->CreateImage($img, new Matrix2D((double) $img->GetImageWidth(), 0.0, 0.0, (double) $img->GetImageHeight(), 10.0, 50.0));
$writer->WritePlacedElement($element);
$writer->End();
// Save the page
$doc->PagePushBack($page);
// Add the page to the document page sequence
// ----------------------------------------------------------
// Embed a monochrome TIFF. Compress the image using lossy JBIG2 filter.
$page = $doc->PageCreate(new Rect(0.0, 0.0, 612.0, 794.0));
$writer->Begin($page);
// begin writing to this page
// Note: encoder hints can be used to select between different compression methods.
// For example to instruct PDFNet to compress a monochrome image using JBIG2 compression.
$hint_set = new ObjSet();
$enc = $hint_set->CreateArray();
// Initilaize encoder 'hint' parameter
$enc->PushBackName("JBIG2");
$enc->PushBackName("Lossy");
$img = Image::Create($doc->GetSDFDoc(), $input_path . "multipage.tif");
$element = $builder->CreateImage($img, new Matrix2D(612.0, 0.0, 0.0, 794.0, 0.0, 0.0));
$writer->WritePlacedElement($element);
$writer->End();
// Save the page
$doc->PagePushBack($page);
// Add the page to the document page sequence
// ----------------------------------------------------------
// Add a JPEG2000 (JP2) image to the output file
// Create a new page
$page = $doc->PageCreate();