Example 9

Description

The example prints a paragraph of text 20 times each followed by a 2mm distance before the next paragraph. A page break is needed at about paragraph number 13 and the text of this paragraph will be split to the next page.
After the 20 text paragraphs a manual page break is inserted and then a paragraph of text. The format of the page has not been changed, so it is still A4 in portrait mode.
After the last text a manually added page break has been inserted. The orientation has been changed to landscape and the left and right margins are set to 30mm, the top margin is set to 20mm. This settings will be used from this page on until one other format is set again.
With the current format the example prints a paragraph of text 10 times, so that a page break is needed. The text of paragraph number 10 will be split to the next page. The next page uses the same settings.
Then a manual page break is added. The format is now A5 in landscape mode with default margins. To show that a text paragraph is added.
Now the format is set to A5 in portrait mode with another manually added page break. The left and right margins will be mirrored. To show that effect, a text will be printed 10 times to force an automatic page break

Output

<?php

include_once "../src/Report.php";

use Adi\ReportLib as ReportLib;

// Create report instance
//  default format A4, portrait with margins left = 20mm, top = 10mm, right = 10mm and bottom = 10mm
$report = new ReportLib\Report();

// Get ref to the report body
$body = $report->getBody();

// Get the default text style
$tsNormal = ReportLib\TextStyles::getTextStyle(ReportLib\TextStyles::NORMAL);
$tsBold = ReportLib\TextStyles::getTextStyle(ReportLib\TextStyles::BOLD);

// Text paragraph
$text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.\n";

// Add a paragraph of text 20 times to the report body
$body->AddVDistance(5.0);
for ($i = 0; $i < 20; $i++) {
    $body->AddText("Paragraph number " . $i+1, $tsNormal);
    $body->AddText($text, $tsNormal);
    $body->AddVDistance(2.0);
}

// Add a manual page break - keep the format settings
$body->AddPageBreak();
$body->AddText($text, $tsNormal);

// Add a manual page break - change the settings to landscape and adjust the margins
$pageFormat = new ReportLib\PageFormat('A4', 'L', 30.0, 20.0, 30.0);
$pb = $body->AddPageBreak($pageFormat);

// Add a paragraph of text 10 times to the report body
for ($i = 0; $i < 10; $i++) {
    $body->AddText("Paragraph number " . $i+1, $tsNormal);
    $body->AddText($text, $tsNormal);
    $body->AddVDistance(3.0);
}

// Add a manual page break - change the settings to A5 landscape and use default margins
$pageFormat = new ReportLib\PageFormat('A5', 'L');
$pb = $body->AddPageBreak($pageFormat);
$body->AddVDistance(5.0);
$body->AddText($text, $tsNormal);

// Add a manual page break - change the settings to  A5 portrait and adjust the margins - mirror the left and right margins
$pageFormat = new ReportLib\PageFormat('A5', 'P', 20.0, 10.0, 10.0, 10.0, true);
$pb = $body->AddPageBreak($pageFormat);

// Add a paragraph of text 10 times to the report body to force an automatic page break
for ($i = 0; $i < 10; $i++) {
    $body->AddText("Paragraph number " . $i+1, $tsNormal);
    $body->AddText($text, $tsNormal);
    $body->AddVDistance(3.0);
}

// Produce the output of the report
//  uses the same params as TCPDF (F = File, I = Preview etc.)
$report->output(__DIR__ . "/example_009.pdf", 'I');