$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); } echo nl2br("Done.\n"); // Examples 3-5 // Common code for remaining samples. $tiger_doc = new PDFDoc($input_path . "tiger.pdf"); // Initialize the security handler, in case the PDF is encrypted. $tiger_doc->InitSecurityHandler(); $page = $tiger_doc->GetPage(1); //-------------------------------------------------------------------------------- // Example 3) Convert the first page to raw bitmap. Also, rotate the // page 90 degrees and save the result as RAW. $draw->SetDPI(100);
<?php //--------------------------------------------------------------------------------------- // Copyright (c) 2001-2014 by PDFTron Systems Inc. All Rights Reserved. // Consult LICENSE.txt regarding license information. //--------------------------------------------------------------------------------------- include "../../../PDFNetC/Lib/PDFNetPHP.php"; PDFNet::Initialize(); // Relative path to the folder containing the test files. $input_path = getcwd() . "/../../TestFiles/"; $output_path = $input_path . "Output/"; // Test - Adjust the position of content within the page. echo nl2br("_______________________________________________\n"); echo nl2br("Opening the input pdf...\n"); $input_doc = new PDFDoc($input_path . "tiger.pdf"); $input_doc->InitSecurityHandler(); $pg_itr1 = $input_doc->GetPageIterator(); $media_box = new Rect($pg_itr1->Current()->GetMediaBox()); $media_box->x1 -= 200; $media_box->x2 -= 200; $media_box->Update(); $input_doc->Save($output_path . "tiger_shift.pdf", 0); $input_doc->Close(); echo nl2br("Done. Result saved in tiger_shift...\n");
$file = new MappedFile($input_path . "tiger.pdf"); $file_sz = $file->FileSize(); $file_reader = new FilterReader($file); $mem = $file_reader->Read($file_sz); $test = array(); for ($i = 0; $i < strlen($mem); $i++) { $test[] = ord($mem[$i]); } $doc = new PDFDoc($mem, $file_sz); $doc->InitSecurityHandler(); $num_pages = $doc->GetPageCount(); $writer = new ElementWriter(); $reader = new ElementReader(); // Create a duplicate of every page but copy only path objects for ($i = 1; $i <= $num_pages; ++$i) { $itr = $doc->GetPageIterator(2 * $i - 1); $reader->Begin($itr->Current()); $new_page = $doc->PageCreate($itr->Current()->GetMediaBox()); $next_page = $itr; $next_page->Next(); $doc->PageInsert($next_page, $new_page); $writer->Begin($new_page); while (($element = $reader->Next()) != null) { //if ($element->GetType() == Element::e_path) $writer->WriteElement($element); } $writer->End(); $reader->End(); } $doc->Save($output_path . "doc_memory_edit.pdf", SDFDoc::e_remove_unused); // Save the document to a memory buffer.
$reader->FormBegin(); ProcessElements($reader); $reader->End(); break; case Element::e_image: ProcessImage($element); break; } } } # Relative path to the folder containing the test files. $input_path = getcwd() . "/../../TestFiles/"; $output_path = $input_path . "Output/"; PDFNet::Initialize(); # Extract text data from all pages in the document echo nl2br("__________________________________________________\n"); echo nl2br("Extract page element information from all \n"); echo nl2br("pages in the document.\n"); $doc = new PDFDoc($input_path . "newsletter.pdf"); $doc->InitSecurityHandler(); $pgnum = $doc->GetPageCount(); $page_begin = $doc->GetPageIterator(); $page_reader = new ElementReader(); for ($itr = $page_begin; $itr->HasNext(); $itr->Next()) { echo nl2br("Page " . $itr->Current()->GetIndex() . "----------------------------------------\n"); $page_reader->Begin($itr->Current()); ProcessElements($page_reader); $page_reader->End(); } $doc->Close(); echo nl2br("Done.\n");
$writer->WriteElement($element); break; default: $writer->WriteElement($element); } } } PDFNet::Initialize(); echo nl2br("-------------------------------------------------\n"); // Open the test file echo nl2br("Opening the input file...\n"); $doc = new PDFDoc($input_path . $input_filename); $doc->InitSecurityHandler(); $writer = new ElementWriter(); $reader = new ElementReader(); $itr = $doc->GetPageIterator(); while ($itr->HasNext()) { $page = $itr->Current(); $reader->Begin($page); $writer->Begin($page, ElementWriter::e_replacement, false); $map1 = array(); ProcessElements($reader, $writer, $map1); $writer->End(); $reader->End(); $map2 = array(); while (!(empty($map1) && empty($map2))) { foreach ($map1 as $k => $v) { $obj = $v; $writer->Begin($obj); $reader->Begin($obj, $page->GetResourceDict()); ProcessElements($reader, $writer, $map2);