Esempio n. 1
0
 public function overlaps(Rect $rect)
 {
     for ($y = $this->lry; $y <= $this->uly; $y++) {
         if ($rect->contains($this->ulx, $y)) {
             return true;
         }
         if ($rect->contains($this->lrx, $y)) {
             return true;
         }
     }
     for ($x = $this->ulx; $x <= $this->lrx; $x++) {
         if ($rect->contains($x, $this->uly)) {
             return true;
         }
         if ($rect->contains($x, $this->lry)) {
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
<?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");
Esempio n. 3
0
//-----------------------------------------------------------------------------------
PDFNet::Initialize();
echo nl2br("-------------------------------------------------\n");
echo nl2br("Opening the input pdf...\n");
$in_doc = new PDFDoc($input_path . "newsletter.pdf");
$in_doc->InitSecurityHandler();
// Create a list of pages to import from one PDF document to another.
$import_pages = new VectorPage();
for ($itr = $in_doc->GetPageIterator(); $itr->HasNext(); $itr->Next()) {
    $import_pages->push($itr->Current());
}
$new_doc = new PDFDoc();
$imported_pages = $new_doc->ImportPages($import_pages);
// Paper dimension for A3 format in points. Because one inch has
// 72 points, 11.69 inch 72 = 841.69 points
$media_box = new Rect(0.0, 0.0, 1190.88, 841.6900000000001);
$mid_point = $media_box->Width() / 2;
$builder = new ElementBuilder();
$writer = new ElementWriter();
for ($i = 0; $i < $imported_pages->size(); ++$i) {
    // Create a blank new A3 page and place on it two pages from the input document.
    $new_page = $new_doc->PageCreate($media_box);
    $writer->Begin($new_page);
    // Place the first page
    $src_page = $imported_pages->get($i);
    $element = $builder->CreateForm($src_page);
    $sc_x = $mid_point / $src_page->GetPageWidth();
    $sc_y = $media_box->Height() / $src_page->GetPageHeight();
    $scale = $sc_x < $sc_y ? $sc_x : $sc_y;
    // min(sc_x, sc_y)
    $element->GetGState()->SetTransform($scale, 0.0, 0.0, $scale, 0.0, 0.0);
Esempio n. 4
0
 public function fetchMapSection(Rect $src, Rect $dst = null)
 {
     if (is_null($dst)) {
         $dst = $src;
     }
     $img = imagecreatetruecolor($dst->width, $dst->height);
     //find pieces from source images
     $point = (object) array('x' => $src->left, 'y' => $src->top);
     $_piece = $this->findMapSectionForPoint($point);
     if ($src->within($_piece->bounds)) {
         $src_img = imagecreatefrompng($_piece->file);
         imagecopyresampled($img, $src_img, 0, 0, $src->left - $_piece->bounds->left, $src->top - $_piece->bounds->top, $dst->width, $dst->height, $src->width, $src->height);
         // source width and height
     } else {
         // bounds spans across multiple backing images
         throw new Exception("Spanned images not implemented");
     }
     return $img;
 }
Esempio n. 5
0
function Create3DAnnotation($doc, $annots)
{
    // ---------------------------------------------------------------------------------
    // Create a 3D annotation based on U3D content. PDF 1.6 introduces the capability
    // for collections of three-dimensional objects, such as those used by CAD software,
    // to be embedded in PDF files.
    $link_3D = $doc->CreateIndirectDict();
    $link_3D->PutName("Subtype", "3D");
    // Annotation location on the page
    $link_3D_rect = new Rect(25.0, 180.0, 585.0, 643.0);
    $link_3D->PutRect("Rect", $link_3D_rect->x1, $link_3D_rect->y1, $link_3D_rect->x2, $link_3D_rect->y2);
    $annots->PushBack($link_3D);
    // The 3DA entry is an activation dictionary (see Table 9.34 in the PDF Reference Manual)
    // that determines how the state of the annotation and its associated artwork can change.
    $activation_dict_3D = $link_3D->PutDict("3DA");
    // Set the annotation so that it is activated as soon as the page containing the
    // annotation is opened. Other options are: PV (page view) and XA (explicit) activation.
    $activation_dict_3D->PutName("A", "PO");
    // Embed U3D Streams (3D Model/Artwork).
    global $input_path;
    $u3d_file = new MappedFile($input_path . "dice.u3d");
    $u3d_reader = new FilterReader($u3d_file);
    // To embed 3D stream without compression, you can omit the second parameter in CreateIndirectStream.
    $u3d_data_dict = $doc->CreateIndirectStream($u3d_reader, new FlateEncode(new Filter()));
    $u3d_data_dict->PutName("Subtype", "U3D");
    $link_3D->Put("3DD", $u3d_data_dict);
    // Set the initial view of the 3D artwork that should be used when the annotation is activated.
    $view3D_dict = $link_3D->PutDict("3DV");
    $view3D_dict->PutString("IN", "Unnamed");
    $view3D_dict->PutString("XN", "Default");
    $view3D_dict->PutName("MS", "M");
    $view3D_dict->PutNumber("CO", 27.5);
    // A 12-element 3D transformation matrix that specifies a position and orientation
    // of the camera in world coordinates.
    $tr3d = $view3D_dict->PutArray("C2W");
    $tr3d->PushBackNumber(1);
    $tr3d->PushBackNumber(0);
    $tr3d->PushBackNumber(0);
    $tr3d->PushBackNumber(0);
    $tr3d->PushBackNumber(0);
    $tr3d->PushBackNumber(-1);
    $tr3d->PushBackNumber(0);
    $tr3d->PushBackNumber(1);
    $tr3d->PushBackNumber(0);
    $tr3d->PushBackNumber(0);
    $tr3d->PushBackNumber(-27.5);
    $tr3d->PushBackNumber(0);
    // Create annotation appearance stream, a thumbnail which is used during printing or
    // in PDF processors that do not understand 3D data.
    $ap_dict = $link_3D->PutDict("AP");
    $builder = new ElementBuilder();
    $writer = new ElementWriter();
    $writer->Begin($doc->GetSDFDoc());
    $thumb_pathname = $input_path . "dice.jpg";
    $image = Image::Create($doc->GetSDFDoc(), $thumb_pathname);
    $writer->WritePlacedElement($builder->CreateImage($image, 0.0, 0.0, $link_3D_rect->Width(), $link_3D_rect->Height()));
    $normal_ap_stream = $writer->End();
    $normal_ap_stream->PutName("Subtype", "Form");
    $normal_ap_stream->PutRect("BBox", 0, 0, $link_3D_rect->Width(), $link_3D_rect->Height());
    $ap_dict->Put("N", $normal_ap_stream);
}