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 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) { # 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'); # 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) { # 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 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 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 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 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 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"); # 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) { # 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 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 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."; }