public static function run($dataDir = null) { # Create PDF document $pdf = new Document($dataDir . 'input1.pdf'); $page_count = $pdf->getPages()->size(); print "Page Count:" . $page_count . PHP_EOL; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # Save the concatenated output file (the target document) $pdf->save($dataDir . "output.doc"); print "Document has been converted successfully" . PHP_EOL; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Get properties print "xmp:CreateDate: " + $doc->getMetadata()->get_Item("xmp:CreateDate") . PHP_EOL; print "xmp:Nickname: " + $doc->getMetadata()->get_Item("xmp:Nickname") . PHP_EOL; print "xmp:CustomProperty: " + $doc->getMetadata()->get_Item("xmp:CustomProperty") . PHP_EOL; }
public static function optimize_web($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Optimize for web $doc->optimize(); #Save output document $doc->save($dataDir . "Optimized_Web.pdf"); print "Optimized PDF for the Web, please check output file." . PHP_EOL; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); $javascript = new JavascriptAction("var year=2014;\n var month=4;\n today = new Date();\n today = new Date(today.getFullYear(), today.getMonth());\n expiry = new Date(year, month);\n if (today.getTime() > expiry.getTime())\n app.alert('The file is expired. You need a new one.');"); $doc->setOpenAction($javascript); # save update document with new information $doc->save($dataDir . "set_expiration.pdf"); print "Update document information, please check output file." . PHP_EOL; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # delete a particular page $pdf->getPages()->delete(2); # save the newly generated PDF file $pdf->save($dataDir . "output.pdf"); print "Page deleted successfully!"; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # insert a empty page in a PDF $pdf->getPages()->add(); # Save the concatenated output file (the target document) $pdf->save($dataDir . "output.pdf"); print "Empty page added successfully!" . PHP_EOL; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # Instantiate ExcelSave Option object $excelsave = new ExcelSaveOptions(); # Save the output to XLS format $pdf->save($dataDir . "Converted_Excel.xls", $excelsave); print "Document has been converted successfully" . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate LoadOption object using SVG load option $options = new SvgLoadOptions(); # Create document object $pdf = new Document($dataDir . 'Example.svg', $options); # Save the output to XLS format $pdf->save($dataDir . "SVG.pdf"); print "Document has been converted successfully"; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # instantiate an object of SvgSaveOptions $save_options = new SvgSaveOptions(); # do not compress SVG image to Zip archive $save_options->CompressOutputToZipArchive = false; # Save the output to XLS format $pdf->save($dataDir . "Output.svg", $save_options); print "Document has been converted successfully" . PHP_EOL; }
public static function run($dataDir = null) { # Open the target document $pdf1 = new Document($dataDir . 'input1.pdf'); # Open the source document $pdf2 = new Document($dataDir . 'input2.pdf'); # Add the pages of the source document to the target document $pdf1->getPages()->add($pdf2->getPages()); # Save the concatenated output file (the target document) $pdf1->save($dataDir . "Concatenate_output.pdf"); print "New document has been saved, please check the output file" . PHP_EOL; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # get the page at particular index of Page Collection $pdf_page = $pdf->getPages()->get_Item(1); # create a new Document object $new_document = new Document(); # add page to pages collection of new document object $new_document->getPages()->add($pdf_page); # save the newly generated PDF file $new_document->save($dataDir . "output.pdf"); print "Process completed successfully!"; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Get document information $doc_info = $doc->getInfo(); # Show document information print "Author:-" . $doc_info->getAuthor(); print "Creation Date:-" . $doc_info->getCreationDate(); print "Keywords:-" . $doc_info->getKeywords(); print "Modify Date:-" . $doc_info->getModDate(); print "Subject:-" . $doc_info->getSubject(); print "Title:-" . $doc_info->getTitle(); }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # get page collection $page_collection = $pdf->getPages(); # get particular page $pdf_page = $page_collection->get_Item(1); # set the page size as A4 (11.7 x 8.3 in) and in Aspose.Pdf, 1 inch = 72 points # so A4 dimensions in points will be (842.4, 597.6) $pdf_page->setPageSize(597.6, 842.4); # save the newly generated PDF file $pdf->save($dataDir . "output.pdf"); print "Dimensions updated successfully!" . PHP_EOL; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Adding JavaScript at Document Level # Instantiate JavascriptAction with desried JavaScript statement $javaScript = new JavascriptAction("this.print({bUI:true,bSilent:false,bShrinkToFit:true});"); # Assign JavascriptAction object to desired action of Document $doc->setOpenAction($javaScript); # Adding JavaScript at Page Level $doc->getPages()->get_Item(2)->getActions()->setOnOpen(new JavascriptAction("app.alert('page 2 is opened')")); $doc->getPages()->get_Item(2)->getActions()->setOnClose(new JavascriptAction("app.alert('page 2 is closed')")); # Save PDF Document $doc->save($dataDir . "JavaScript-Added.pdf"); print "Added JavaScript Successfully, please check the output file."; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Get document information $doc_info = $doc->getInfo(); $doc_info->setAuthor("Aspose.Pdf for java"); $doc_info->setCreationDate(new Date()); $doc_info->setKeywords("Aspose.Pdf, DOM, API"); $doc_info->setModDate(new Date()); $doc_info->setSubject("PDF Information"); $doc_info->setTitle("Setting PDF Document Information"); # save update document with new information $doc->save($dataDir . "Updated_Information.pdf"); print "Update document information, please check output file."; }
public static function run($dataDir = null) { # Create PDF document $pdf_document = new Document($dataDir . 'input1.pdf'); # get page collection $page_collection = $pdf_document->getPages(); # get particular page $pdf_page = $page_collection->get_Item(1); #get page properties print "ArtBox : Height = " . $pdf_page->getArtBox()->getHeight() . ", Width = " . $pdf_page->getArtBox()->getWidth() . ", LLX = " . $pdf_page->getArtBox()->getLLX() . ", LLY = " . $pdf_page->getArtBox()->getLLY() . ", URX = " . $pdf_page->getArtBox()->getURX() . ", URY = " . $pdf_page->getArtBox()->getURY() . PHP_EOL; print "BleedBox : Height = " . $pdf_page->getBleedBox()->getHeight() . ", Width = " . $pdf_page->getBleedBox()->getWidth() . ", LLX = " . $pdf_page->getBleedBox()->getLLX() . ", LLY = " . $pdf_page->getBleedBox()->getLLY() . ", URX = " . $pdf_page->getBleedBox()->getURX() . ", URY = " . $pdf_page->getBleedBox()->getURY() . PHP_EOL; print "CropBox : Height = " . $pdf_page->getCropBox()->getHeight() . ", Width = " . $pdf_page->getCropBox()->getWidth() . ", LLX = " . $pdf_page->getCropBox()->getLLX() . ", LLY = " . $pdf_page->getCropBox()->getLLY() . ", URX = " . $pdf_page->getCropBox()->getURX() . ", URY = " . $pdf_page->getCropBox()->getURY() . PHP_EOL; print "MediaBox : Height = " . $pdf_page->getMediaBox()->getHeight() . ", Width = " . $pdf_page->getMediaBox()->getWidth() . ", LLX = " . $pdf_page->getMediaBox()->getLLX() . ", LLY = " . $pdf_page->getMediaBox()->getLLY() . ", URX = " . $pdf_page->getMediaBox()->getURX() . ", URY = " . $pdf_page->getMediaBox()->getURY() . PHP_EOL; print "TrimBox : Height = " . $pdf_page->getTrimBox()->getHeight() . ", Width = " . $pdf_page->getTrimBox()->getWidth() . ", LLX = " . $pdf_page->getTrimBox()->getLLX() . ", LLY = " . $pdf_page->getTrimBox()->getLLY() . ", URX = " . $pdf_page->getTrimBox()->getURX() . ", URY = " . $pdf_page->getTrimBox()->getURY() . PHP_EOL; print "Rect : Height = " . $pdf_page->getRect()->getHeight() . ", Width = " . $pdf_page->getRect()->getWidth() . ", LLX = " . $pdf_page->getRect()->getLLX() . ", LLY = " . $pdf_page->getRect()->getLLY() . ", URX = " . $pdf_page->getRect()->getURX() . ", URY = " . $pdf_page->getRect()->getURY() . PHP_EOL; print "Page Number :- " . $pdf_page->getNumber() . PHP_EOL; print "Rotate :-" . $pdf_page->getRotate() . PHP_EOL; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # loop through all the pages $pdf_page = 1; $total_size = $pdf->getPages()->size(); #for (int pdfPage = 1; pdfPage<= pdfDocument1.getPages().size(); pdfPage++) while ($pdf_page <= $total_size) { # create a new Document object $new_document = new Document(); # get the page at particular index of Page Collection $new_document->getPages()->add($pdf->getPages()->get_Item($pdf_page)); # save the newly generated PDF file $new_document->save($dataDir . "page_#{$pdf_page}.pdf"); $pdf_page++; } print "Split process completed successfully!"; }
public static function run($dataDir = null) { # Instantiate Document object $doc = new Document(); # Add a page to pages collection of PDF file $page = $doc->getPages()->add(); # Instantiate HtmlFragment with HTML contents $title = new HtmlFragment("<fontsize=10><b><i>Table</i></b></fontsize>"); # set MarginInfo for margin details $margin = new MarginInfo(); $margin->setBottom(10); $margin->setTop(200); # Set margin information $title->setMargin($margin); # Add HTML Fragment to paragraphs collection of page $page->getParagraphs()->add($title); # Save PDF file $doc->save($dataDir . "html.output.pdf"); print "HTML added successfully" . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Document object $doc = new Document($dataDir . 'input1.pdf'); # get particular page $pdf_page = $doc->getPages()->get_Item(1); # create text fragment $text_fragment = new TextFragment("main text"); $text_fragment->setPosition(new Position(100, 600)); $font_repository = new FontRepository(); $color = new Color(); # set text properties $text_fragment->getTextState()->setFont($font_repository->findFont("Verdana")); $text_fragment->getTextState()->setFontSize(14); # create TextBuilder object $text_builder = new TextBuilder($pdf_page); # append the text fragment to the PDF page $text_builder->appendText($text_fragment); # Save PDF file $doc->save($dataDir . "Text_Added.pdf"); print "Text added successfully" . PHP_EOL; }
public static function run($dataDir = null) { # Open the target document $pdf = new Document($dataDir . 'input1.pdf'); # create TextAbsorber object to extract text $text_absorber = new TextAbsorber(); # accept the absorber for all the pages $pdf->getPages()->accept($text_absorber); # In order to extract text from specific page of document, we need to specify the particular page using its index against accept(..) method. # accept the absorber for particular PDF page # pdfDocument.getPages().get_Item(1).accept(textAbsorber); #get the extracted text $extracted_text = $text_absorber->getText(); # create a writer and open the file $writer = new FileWriter(new File($dataDir . "extracted_text.out.txt")); $writer->write($extracted_text); # write a line of text to the file # tw.WriteLine(extractedText); # close the stream $writer->close(); print "Text extracted successfully. Check output file." . PHP_EOL; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Get access to first page of PDF file $toc_page = $doc->getPages()->insert(1); # Create object to represent TOC information $toc_info = new TocInfo(); $title = new TextFragment("Table Of Contents"); $title->getTextState()->setFontSize(20); #title.getTextState().setFontStyle(Rjb::import('com.aspose.pdf.FontStyles.Bold')) # Set the title for TOC $toc_info->setTitle($title); $toc_page->setTocInfo($toc_info); # Create string objects which will be used as TOC elements $titles = array("First page", "Second page"); $i = 0; while ($i < 2) { # Create Heading object $heading2 = new Heading(1); $segment2 = new TextSegment(); $heading2->setTocPage($toc_page); $heading2->getSegments()->add($segment2); # Specify the destination page for heading object $heading2->setDestinationPage($doc->getPages()->get_Item($i + 2)); # Destination page $heading2->setTop($doc->getPages()->get_Item($i + 2)->getRect()->getHeight()); # Destination coordinate $segment2->setText($titles[$i]); # Add heading to page containing TOC $toc_page->getParagraphs()->add($heading2); $i += 1; } # Save PDF Document $doc->save($dataDir . "TOC.pdf"); print "Added TOC Successfully, please check the output file."; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); if (preg_match('/pdfaid:part/', $doc->getMetadata())) { $doc->getMetadata()->removeItem("pdfaid:part"); } if (preg_match('/dc:format/', $doc->getMetadata())) { $doc->getMetadata()->removeItem("dc:format"); } # save update document with new information $doc->save($dataDir . "Remove_Metadata.pdf"); print "Removed metadata successfully, please check output file." . PHP_EOL; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Get different document properties # Position of document's window - Default: false print "CenterWindow :- " . $doc->getCenterWindow() . PHP_EOL; # Predominant reading order; determine the position of page # when displayed side by side - Default: L2R print "Direction :- " . $doc->getDirection() . PHP_EOL; # Whether window's title bar should display document title. # If false, title bar displays PDF file name - Default: false print "DisplayDocTitle :- " . $doc->getDisplayDocTitle() . PHP_EOL; #Whether to resize the document's window to fit the size of #first displayed page - Default: false print "FitWindow :- " . $doc->getFitWindow() . PHP_EOL; # Whether to hide menu bar of the viewer application - Default: false print "HideMenuBar :-" . $doc->getHideMenubar() . PHP_EOL; # Whether to hide tool bar of the viewer application - Default: false print "HideToolBar :-" . $doc->getHideToolBar() . PHP_EOL; # Whether to hide UI elements like scroll bars # and leaving only the page contents displayed - Default: false print "HideWindowUI :-" . $doc->getHideWindowUI() . PHP_EOL; # The document's page mode. How to display document on exiting full-screen mode. print "NonFullScreenPageMode :-" . $doc->getNonFullScreenPageMode() . PHP_EOL; # The page layout i.e. single page, one column print "PageLayout :-" . $doc->getPageLayout() . PHP_EOL; #How the document should display when opened. print "pageMode :-" . $doc->getPageMode() . PHP_EOL; }