$zoom_rect = new Rect(216.0, 522.0, 330.0, 600.0); $page->SetCropBox($zoom_rect); // Set the page crop box. // Select the crop region to be used for drawing. $draw->SetPageBox(Page::e_crop); $draw->SetDPI(900); // Set the output image resolution to 900 DPI. $draw->Export($page, $output_path . "tiger_zoom_900dpi.png", "PNG"); echo nl2br("Example 5: " . $output_path . "tiger_zoom_900dpi.png. Done.\n"); $draw->SetImageSize(50, 50); // Set the thumbnail to be 50x50 pixel image. $draw->Export($page, $output_path . "tiger_zoom_50x50.png", "PNG"); echo nl2br("Example 5: " . $output_path . "tiger_zoom_50x50.png. Done.\n"); $cmyk_hint = $hint_set->CreateDict(); $cmyk_hint->PutName("ColorSpace", "CMYK"); //-------------------------------------------------------------------------------- // Example 6) Convert the first PDF page to CMYK TIFF at 92 DPI. // A three step tutorial to convert PDF page to an image echo nl2br("Example 6:\n"); // 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 TIFF. $pg = $doc->GetPage(1); $draw->Export($pg, $output_path . "out1.tif", "TIFF", $cmyk_hint); echo nl2br("Example 6: Result saved in " . $output_path . "out1.tif\n"); $doc->Close(); echo "Done.";
function CertifyPDF() { $infile = '../../TestFiles/newsletter.pdf'; $outfile = '../../TestFiles/Output/newsletter_certified.pdf'; $certfile = '../../TestFiles/pdftron.pfx'; $result = true; try { echo nl2br('Certifying PDF document: "' . $infile . '".' . PHP_EOL); // Open an existing PDF $doc = new PDFDoc($infile); // Add an StdSignatureHandler instance to PDFDoc, making sure to keep track of it using the ID returned. $sigHandlerId = $doc->AddStdSignatureHandler($certfile, "password"); // Create a new signature form field in the PDFDoc. $sigField = $doc->FieldCreate('Signature1', Field::e_signature); // Assign the form field as an annotation widget to the PDFDoc so that a signature appearance can be added. $page1 = $doc->GetPage(1); $widgetAnnot = Widget::Create($doc->GetSDFDoc(), new Rect(0.0, 0.0, 0.0, 0.0), $sigField); $page1->AnnotPushBack($widgetAnnot); $widgetAnnot->SetPage($page1); $widgetObj = $widgetAnnot->GetSDFObj(); $widgetObj->PutNumber('F', 132.0); $widgetObj->PutName('Type', 'Annot'); // Tell PDFNetC to use the SignatureHandler created to sign the new signature form field. $sigDict = $sigField->UseSignatureHandler($sigHandlerId); // Add more information to the signature dictionary. $sigDict->PutName('SubFilter', 'adbe.pkcs7.detached'); $sigDict->PutString('Name', 'PDFTron'); $sigDict->PutString('Location', 'Vancouver, BC'); $sigDict->PutString('Reason', 'Document verification.'); // Appearance can be added to the widget annotation. Please see the "SignPDF()" function for details. // Add this sigDict as DocMDP in Perms dictionary from root $root = $doc->GetRoot(); $perms = $root->PutDict('Perms'); // add the sigDict as DocMDP (indirect) in Perms $perms->Put('DocMDP', $sigDict); // add the additional DocMDP transform params $refObj = $sigDict->PutArray("Reference"); $transform = $refObj->PushBackDict(); $transform->PutName("TransformMethod", "DocMDP"); $transform->PutName("Type", "SigRef"); $transformParams = $transform->PutDict("TransformParams"); $transformParams->PutNumber("P", 1); // Set permissions as necessary. $transformParams->PutName("Type", "TransformParams"); $transformParams->PutName("V", "1.2"); // Save the PDFDoc. Once the method below is called, PDFNetC will also sign the document using the information // provided. $doc->Save($outfile, 0); echo nl2br('Finished certifying PDF document' . PHP_EOL); $doc->Close(); } catch (Exception $e) { echo nl2br($e->getMessage() . PHP_EOL); echo nl2br($e->getTraceAsString() . PHP_EOL); $result = false; } return $result; }
<?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");
$itr = $obj->Find("Filter"); if ($itr->HasNext() && $itr->Value()->IsName() && $itr->Value()->GetName() == "JBIG2Decode") { continue; } $filter = $obj->GetDecodedStream(); $reader = new FilterReader($filter); $hint_set = new ObjSet(); // A hint to image encoder to use JBIG2 compression $hint = $hint_set->CreateArray(); $hint->PushBackName("JBIG2"); $hint->PushBackName("Lossless"); $new_image = Image::Create($cos_doc, $reader, $input_image->GetImageWidth(), $input_image->GetImageHeight(), 1, ColorSpace::CreateDeviceGray(), $hint); $new_img_obj = $new_image->GetSDFObj(); $itr = $obj->Find("Decode"); if ($itr->HasNext()) { $new_img_obj->Put("Decode", $itr->Value()); } $itr = $obj->Find("ImageMask"); if ($itr->HasNext()) { $new_img_obj->Put("ImageMask", $itr->Value()); } $itr = $obj->Find("Mask"); if ($itr->HasNext()) { $new_img_obj->Put("Mask", $itr->Value()); } $cos_doc->Swap($i, $new_img_obj->GetObjNum()); } } $pdf_doc->Save("../../TestFiles/Output/US061222892_JBIG2.pdf", SDFDoc::e_remove_unused); $pdf_doc->Close(); echo "Done.";