Rotate PDF using PHP

Change PDF page orientation. Use Aspose.PDF for PHP via Java to modify PDF documents programmatically

Rotate PDF Pages with PHP

In order to rotate PDF file, we’ll use Aspose.PDF for PHP via Java API which is a feature-rich, powerful and easy-to-use document manipulation tool in php-java. Install Tomcat 9.0 version on any location, add Aspose.PDF.war, for more details check the GitHub page.

How to Rotate PDF documents


You need Aspose.PDF for PHP via Java to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Move page upper in order to compensate changing page size.
  3. Set old and new page height.
  4. Setting the page rotation angle.
  5. Save the output PDF file.

If you want to rotate PDF files for your tasks, this solution can help. With this powerful Aspose.PDF PHP via Java library, you can update or change the page orientation of pages while keeping its quality. This professional tool uses PHP to rotate PDF effectively. The following example demonstrates how to rotate PDF document in PHP:

Rotate PDF - PHP

This sample code shows how to Rotate PDF Pages - PHP

Input file:

File not added

Output format:

PDF

Output file:

// Open document
$document = new Document($inputFile);                
$pages = $document->getPages();
$pagesSize = java_values($pages->size());
    
// Loop through all the pages
for ($pageCount = 1; $pageCount <= $pagesSize; $pageCount++) {
    $page = $pages->get_Item($pageCount);
    
    $page->setRotate((new Rotation())->On90);
}

// Save output document
$document->save($outputFile);
$document->close();
$responseData = "Page rotated successfully.";

About Aspose.PDF for PHP via Java API

Aspose.PDF for PHP via Java is a powerful API designed to assist developers in creating, manipulating, and converting PDF documents programmatically. Aspose.PDF allows developers to create PDF documents from scratch or convert other document formats (such as HTML, XML, and images) to PDF. This is useful for generating reports, invoices, or any document type. It also recommends viewing a Documentation.