// PDFNet::SetResourcesPath("../../../resources"); // PDFNet::SetColorManagement(); // PDFNet::SetDefaultDeviceCMYKProfile("D:/Misc/ICC/USWebCoatedSWOP.icc"); // PDFNet::SetDefaultDeviceRGBProfile("AdobeRGB1998.icc"); // will search in PDFNet resource folder. // ---------------------------------------------------- // Optional: Set predefined font mappings to override default font // substitution for documents with missing fonts... // PDFNet::AddFontSubst("StoneSans-Semibold", "C:/WINDOWS/Fonts/comic.ttf"); // PDFNet::AddFontSubst("StoneSans", "comic.ttf"); // search for 'comic.ttf' in PDFNet resource folder. // PDFNet::AddFontSubst(PDFNet::e_Identity, "C:/WINDOWS/Fonts/arialuni.ttf"); // PDFNet::AddFontSubst(PDFNet::e_Japan1, "C:/Program Files/Adobe/Acrobat 7.0/Resource/CIDFont/KozMinProVI-Regular.otf"); // PDFNet::AddFontSubst(PDFNet::e_Japan2, "c:/myfonts/KozMinProVI-Regular.otf"); // PDFNet::AddFontSubst(PDFNet::e_Korea1, "AdobeMyungjoStd-Medium.otf"); // PDFNet::AddFontSubst(PDFNet::e_CNS1, "AdobeSongStd-Light.otf"); // PDFNet::AddFontSubst(PDFNet::e_GB1, "AdobeMingStd-Light.otf"); $draw = new PDFDraw(); //-------------------------------------------------------------------------------- // Example 1) Convert the first page to PNG and TIFF at 92 DPI. // 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"); //--------------------------------------------------------------------------------
$doc->PagePushBack($page); // Set the default viewing preference to display 'Layer' tab. $prefs = $doc->GetViewPrefs(); $prefs->SetPageMode(PDFDocViewPrefs::e_UseOC); $doc->Save($output_path . "pdf_layers.pdf", SDFDoc::e_linearized); echo nl2br("Done.\n"); // The following is a code snippet shows how to selectively render // and export PDF layers. $doc = new PDFDoc($output_path . "pdf_layers.pdf"); $doc->InitSecurityHandler(); if (!$doc->HasOC()) { echo nl2br("The document does not contain 'Optional Content'\n"); } else { $init_cfg = $doc->GetOCGConfig(); $ctx = new Context($init_cfg); $pdfdraw = new PDFDraw(); $pdfdraw->SetImageSize(1000, 1000); $pdfdraw->SetOCGContext($ctx); // Render the page using the given OCG context. $page = $doc->GetPage(1); // Get the first page in the document. $pdfdraw->Export($page, $output_path . "pdf_layers_default.png"); // Disable drawing of content that is not optional (i.e. is not part of any layer). $ctx->SetNonOCDrawing(false); // Now render each layer in the input document to a separate image. $ocgs = $doc->GetOCGs(); // Get the array of all OCGs in the document. if ($ocgs != null) { $sz = $ocgs->Size(); for ($i = 0; $i < $sz; ++$i) { $ocg = new Group($ocgs->GetAt($i));