32
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-12-28 18:51:03 +00:00
tcpdf/examples/example_013.php

230 lines
6.6 KiB
PHP
Raw Normal View History

2009-09-30 09:18:36 +00:00
<?php
//============================================================+
// File name : example_013.php
// Begin : 2008-03-04
2010-08-08 10:33:06 +00:00
// Last Update : 2010-08-08
2010-04-05 18:45:48 +00:00
//
2009-09-30 09:18:36 +00:00
// Description : Example 013 for TCPDF class
// Graphic Transformations
2010-04-05 18:45:48 +00:00
//
2009-09-30 09:18:36 +00:00
// Author: Nicola Asuni
2010-04-05 18:45:48 +00:00
//
2009-09-30 09:18:36 +00:00
// (c) Copyright:
// Nicola Asuni
// Tecnick.com s.r.l.
// Via Della Pace, 11
// 09044 Quartucciu (CA)
// ITALY
// www.tecnick.com
// info@tecnick.com
//============================================================+
/**
* Creates an example PDF TEST document using TCPDF
* @package com.tecnick.tcpdf
* @abstract TCPDF - Example: Graphic Transformations
* @author Nicola Asuni
* @since 2008-03-04
*/
require_once('../config/lang/eng.php');
require_once('../tcpdf.php');
// create new PDF document
2010-04-05 18:45:48 +00:00
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
2009-09-30 09:18:36 +00:00
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 013');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
2010-05-21 16:47:01 +00:00
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 013', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
2009-03-24 18:37:18 +00:00
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
2009-09-30 09:18:36 +00:00
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
2010-05-21 16:47:01 +00:00
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
2009-09-30 09:18:36 +00:00
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
2010-04-05 18:45:48 +00:00
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
2009-09-30 09:18:36 +00:00
//set some language-dependent strings
2010-04-05 18:45:48 +00:00
$pdf->setLanguageArray($l);
2009-09-30 09:18:36 +00:00
// ---------------------------------------------------------
// set font
2010-05-21 16:47:01 +00:00
$pdf->SetFont('helvetica', 'B', 20);
2009-09-30 09:18:36 +00:00
// add a page
$pdf->AddPage();
2010-05-21 16:47:01 +00:00
$pdf->Write(0, 'Graphic Transformations', '', 0, 'C', 1, 0, false, false, 0);
// set font
$pdf->SetFont('helvetica', '', 10);
// --- Scaling ---------------------------------------------
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(50, 70, 40, 10, 'D');
$pdf->Text(50, 66, 'Scale');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
2010-05-21 16:47:01 +00:00
// Start Transformation
2009-09-30 09:18:36 +00:00
$pdf->StartTransform();
2010-05-21 16:47:01 +00:00
// Scale by 150% centered by (50,80) which is the lower left corner of the rectangle
$pdf->ScaleXY(150, 50, 80);
$pdf->Rect(50, 70, 40, 10, 'D');
$pdf->Text(50, 66, 'Scale');
// Stop Transformation
2009-09-30 09:18:36 +00:00
$pdf->StopTransform();
2010-05-21 16:47:01 +00:00
// --- Translation -----------------------------------------
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(125, 70, 40, 10, 'D');
$pdf->Text(125, 66, 'Translate');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
2010-05-21 16:47:01 +00:00
// Start Transformation
2009-09-30 09:18:36 +00:00
$pdf->StartTransform();
2010-05-21 16:47:01 +00:00
// Translate 7 to the right, 5 to the bottom
2009-09-30 09:18:36 +00:00
$pdf->Translate(7, 5);
2010-05-21 16:47:01 +00:00
$pdf->Rect(125, 70, 40, 10, 'D');
$pdf->Text(125, 66, 'Translate');
// Stop Transformation
2009-09-30 09:18:36 +00:00
$pdf->StopTransform();
2010-05-21 16:47:01 +00:00
// --- Rotation --------------------------------------------
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(70, 100, 40, 10, 'D');
$pdf->Text(70, 96, 'Rotate');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
2010-05-21 16:47:01 +00:00
// Start Transformation
2009-09-30 09:18:36 +00:00
$pdf->StartTransform();
2010-05-21 16:47:01 +00:00
// Rotate 20 degrees counter-clockwise centered by (70,110) which is the lower left corner of the rectangle
$pdf->Rotate(20, 70, 110);
$pdf->Rect(70, 100, 40, 10, 'D');
$pdf->Text(70, 96, 'Rotate');
// Stop Transformation
2009-09-30 09:18:36 +00:00
$pdf->StopTransform();
2010-05-21 16:47:01 +00:00
// --- Skewing ---------------------------------------------
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(125, 100, 40, 10, 'D');
$pdf->Text(125, 96, 'Skew');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
2010-05-21 16:47:01 +00:00
// Start Transformation
2009-09-30 09:18:36 +00:00
$pdf->StartTransform();
2010-05-21 16:47:01 +00:00
// skew 30 degrees along the x-axis centered by (125,110) which is the lower left corner of the rectangle
$pdf->SkewX(30, 125, 110);
$pdf->Rect(125, 100, 40, 10, 'D');
$pdf->Text(125, 96, 'Skew');
// Stop Transformation
2009-09-30 09:18:36 +00:00
$pdf->StopTransform();
2010-05-21 16:47:01 +00:00
// --- Mirroring horizontally ------------------------------
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(70, 130, 40, 10, 'D');
$pdf->Text(70, 126, 'MirrorH');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
2010-05-21 16:47:01 +00:00
// Start Transformation
2009-09-30 09:18:36 +00:00
$pdf->StartTransform();
2010-05-21 16:47:01 +00:00
// mirror horizontally with axis of reflection at x-position 70 (left side of the rectangle)
$pdf->MirrorH(70);
$pdf->Rect(70, 130, 40, 10, 'D');
$pdf->Text(70, 126, 'MirrorH');
// Stop Transformation
2009-09-30 09:18:36 +00:00
$pdf->StopTransform();
2010-05-21 16:47:01 +00:00
// --- Mirroring vertically --------------------------------
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(125, 130, 40, 10, 'D');
$pdf->Text(125, 126, 'MirrorV');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
2010-05-21 16:47:01 +00:00
// Start Transformation
2009-09-30 09:18:36 +00:00
$pdf->StartTransform();
2010-05-21 16:47:01 +00:00
// mirror vertically with axis of reflection at y-position 140 (bottom side of the rectangle)
$pdf->MirrorV(140);
$pdf->Rect(125, 130, 40, 10, 'D');
$pdf->Text(125, 126, 'MirrorV');
// Stop Transformation
2009-09-30 09:18:36 +00:00
$pdf->StopTransform();
2010-05-21 16:47:01 +00:00
// --- Point reflection ------------------------------------
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(70, 160, 40, 10, 'D');
$pdf->Text(70, 156, 'MirrorP');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
2010-05-21 16:47:01 +00:00
// Start Transformation
2009-09-30 09:18:36 +00:00
$pdf->StartTransform();
2010-05-21 16:47:01 +00:00
// point reflection at the lower left point of rectangle
$pdf->MirrorP(70,170);
$pdf->Rect(70, 160, 40, 10, 'D');
$pdf->Text(70, 156, 'MirrorP');
// Stop Transformation
2009-09-30 09:18:36 +00:00
$pdf->StopTransform();
2010-05-21 16:47:01 +00:00
// --- Mirroring against a straigth line described by a point (120, 120) and an angle -20°
2009-09-30 09:18:36 +00:00
$angle=-20;
$px=120;
2010-05-21 16:47:01 +00:00
$py=170;
2009-09-30 09:18:36 +00:00
2010-05-21 16:47:01 +00:00
// just for visualisation: the straight line to mirror against
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(200);
$pdf->Line($px-1,$py-1,$px+1,$py+1);
$pdf->Line($px-1,$py+1,$px+1,$py-1);
$pdf->StartTransform();
$pdf->Rotate($angle, $px, $py);
$pdf->Line($px-5, $py, $px+60, $py);
$pdf->StopTransform();
$pdf->SetDrawColor(200);
$pdf->SetTextColor(200);
2010-05-21 16:47:01 +00:00
$pdf->Rect(125, 160, 40, 10, 'D');
$pdf->Text(125, 156, 'MirrorL');
2009-09-30 09:18:36 +00:00
$pdf->SetDrawColor(0);
$pdf->SetTextColor(0);
//Start Transformation
$pdf->StartTransform();
//mirror against the straight line
$pdf->MirrorL($angle, $px, $py);
2010-05-21 16:47:01 +00:00
$pdf->Rect(125, 160, 40, 10, 'D');
$pdf->Text(125, 156, 'MirrorL');
2009-09-30 09:18:36 +00:00
//Stop Transformation
$pdf->StopTransform();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_013.pdf', 'I');
//============================================================+
2010-04-05 18:45:48 +00:00
// END OF FILE
2009-09-30 09:18:36 +00:00
//============================================================+