Exemplo n.º 1
0
echo nl2br("Done. Result saved in newsletter_page_insert.pdf...\n");
//Close the open document to free up document memory sooner than waiting for the
//garbage collector
$in1_doc->Close();
$in2_doc->Close();
// Sample 5 - Replicate pages within a single document
echo nl2br("_______________________________________________\n");
echo nl2br("Sample 5 - Replicate pages within a single document...\n");
echo nl2br("Opening the input pdf...\n");
$doc = new PDFDoc($input_path . "newsletter.pdf");
$doc->InitSecurityHandler();
// Replicate the cover page three times (copy page #1 and place it before the
// seventh page in the document page sequence)
$cover = $doc->GetPage(1);
$p7 = $doc->GetPageIterator(7);
$doc->PageInsert($p7, $cover);
$doc->PageInsert($p7, $cover);
$doc->PageInsert($p7, $cover);
// Replicate the cover page two more times by placing it before and after
// existing pages.
$doc->PagePushFront($cover);
$doc->PagePushBack($cover);
$doc->Save($output_path . "newsletter_page_clone.pdf", 0);
echo nl2br("Done. Result saved in newsletter_page_clone.pdf...\n");
$doc->Close();
// Sample 6 - Use ImportPages() in order to copy multiple pages at once
// in order to preserve shared resources between pages (e.g. images, fonts,
// colorspaces, etc.)
echo nl2br("_______________________________________________\n");
echo nl2br("Sample 6 - Preserving shared resources using ImportPages...\n");
echo nl2br("Opening the input pdf...\n");
Exemplo n.º 2
0
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.
$buffer = $doc->Save(SDFDoc::e_remove_unused);
// Write the contents of the buffer to the disk
$outfile = fopen($output_path . "doc_memory_edit.txt", "w");
fwrite($outfile, $buffer);
fclose($outfile);