Skip to content

Latest commit

 

History

History

PDFRotate

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

PDFRotateTrait

GitHub license Author

This script allows to perform a rotation around a given center.

The rotation affects all elements which are printed after the method call (with the exception of clickable areas)

Remarks:

  • Only the display is altered. The GetX() and GetY() methods are not affected, nor the automatic page break mechanism.
  • Rotation is not kept from page to page. Each page begins with a null rotation.

Requires

Require use of PDFTransformTrait

Usage

The method to set a rotation is:

/**
 * Prints a character string with rotation
 *
 * @param float $x Abscissa of the origin.
 * @param float $y Ordinate of the origin.
 * @param string $txt String to print.
 * @param float $angle Angle in degrees.
 * @return void
 */
PDFRotateTrait::RotatedText(float $x, float $y, string $txt, float $angle);

/**
 * Puts an image with rotation
 *
 * @param string $file Path or URL of the image.
 * @param float $x Abscissa of the upper-left corner.
 * @param float $y Ordinate of the upper-left corner.
 * @param float $w Width of the image in the page.
 * @param float $h Height of the image in the page.
 * @param float $angle Angle in degrees.
 * @return void
 */
PDFRotateTrait::RotatedImage (string $file, float $x, float $y, float $w, float $h, float $angle)

Example

<?php
declare(strict_types=1);

require dirname(dirname(__DIR__)) . '/fpdf/fpdf.php';
require dirname(__DIR__) . '/PDFTransform/PDFTransformTrait.php';
require __DIR__ . '/PDFRotateTrait.php';

use FPDF\Scripts\PDFTransform\PDFTransformTrait;
use FPDF\Scripts\PDFRotate\PDFRotateTrait;

$pdf = new class extends FPDF {
  use PDFTransformTrait;
  use PDFRotateTrait;
};

$pdf->AddPage();
$pdf->SetFont('Arial', '', 20);
$pdf->RotatedImage('circle.png', 85, 60, 40, 16, 45);
$pdf->RotatedText(100, 60, 'Hello!', 45);

$pdf->Output('F', __DIR__ . '/example.pdf');

Result