Example 22

Description

The ‘body’ that has been used in all examples is in fact a vertical SerialFrame. Each frame added to the body will be printed just below the preceding one (in the flow of the document).
First there is a horizontal SerialFrame added to the body with a left aligned text in a box with a width of 50mm. Right to the first frame follows a bold text in box of width 120m. The texts are close because there is no padding.
Then a second horizontal SerialFrame is added to the body and will be printed therefore below the first one. Three columns of justified text in separate boxes, each with a width of 55mm. The columns have a distance of 4mm.
A SerialFrame can also hold other frame types which is shown in the next section. On the left side there is a barcode followed by a distance of 5mm. Then follows an image and on the right side there is a 50mm width box with text.
BoxFrames and SerialFrames can also be used to create aligned labels and texts. The labels have a fixed width of 25mm and are right aligned. The texts will use the rest of the width of the surrounding frame and are left aligned

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 NORMAL 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";

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

// Text in box in a horizontal SerialFrame
$sf = $body->AddHContainer();

// Add two boxes with text in them
$sf->AddTextInBox(50.0, $text, $tsNormal);
$sf->AddTextInBox(120.0, $text, $tsBold);
$body->AddVDistance(10.0);


// Three columns of justified text in boxes
$sf = $body->AddHContainer();

// First column
$box = $sf->AddBox(55.0);
$box->AddText($text, $tsNormal, false, 'J');
$sf->AddHDistance(4.0);

// Second column
$box = $sf->AddBox(55.0);
$box->AddText($text, $tsNormal, false, 'J');
$sf->AddHDistance(4.0);

// Third column
$box = $sf->AddBox(55.0);
$box->AddText($text, $tsNormal, false, 'J');
$body->AddVDistance(10.0);


// Three columns with an image and a barcode and some text
$sf = $body->AddHContainer();

// First column with a QR-code
$sf->AddBarcode("reportlib.adiuvaris.ch", "QRCODE",40.0, 40.0);
$sf->AddHDistance(5.0);

// Second column with an image
$box = $sf->AddImage("image.jpg", true, 50.0, 30.0);
$sf->AddHDistance(5.0);

// Third column with text
$sf->AddTextInBox(60.0, $text, $tsNormal);
$body->AddVDistance(10.0);


// Labels with text
$sf = $body->AddHContainer();

// First line with label and text
$sf->AddTextInBox(25.0, "Label 1: ", $tsNormal, 'R');
$sf->AddText("Text for Label 1", $tsBold);

// Second line with label and text
$sf = $body->AddHContainer();
$sf->AddTextInBox(25.0, "Another Label: ", $tsNormal, 'R');
$sf->AddText("Text for the second label", $tsBold);

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