Example 26

Description

The width of BoxFrames can be defined in percent of the surrounding frame.
This example looks like example 22 but the widths of the BoxFrames are defined in percent.
The first two frames use 60% and 40% of the width. Then there are three columns with a third of the space. The QR code uses 25%, the image 40% and the text 45% (but limited by the width of the page).
Frames added to a BoxFrame can only use the space of the box, therefore uses the QR-code only the given space and not the defined 100mm.
To show the effect the same report structure is printed on three pages with different page formats and margins.
Nothing has to be changed on the structure, and it is printed correctly on every page.

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();

for ($i = 0; $i < 3; $i++) {

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

    // Add two boxes with text in them
    $sf->AddTextInBox("40.0%", $text, $tsNormal);
    $sf->AddTextInBox("60.0%", $text, $tsBold);

    $body->AddVDistance(10.0);

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

    // First column
    $box = $sf->AddBox("33.33%");
    $box->setPaddingRight(2.0);
    $box->AddText($text, $tsNormal, false, 'J');

    // Second column
    $box = $sf->AddBox("33.33%");
    $box->AddText($text, $tsNormal, false, 'J');
    $box->setPaddingLeft(1.0);
    $box->setPaddingRight(1.0);

    // Third column
    $box = $sf->AddBox("33.33%");
    $box->AddText($text, $tsNormal, false, 'J');
    $box->setPaddingLeft(2.0);
    $body->AddVDistance(10.0);

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

    // First column with a QR-code
    $box = $sf->AddBox("25.0%");
    $box->AddBarcode("reportlib.adiuvaris.ch", "QRCODE", 100.0, 100.0);
    $box->setMarginRight(5.0);

    // Second column with an image
    $box = $sf->AddBox("40.0%");
    $im = $box->AddImage("image.jpg", true, 50.0, 30.0);
    $im->setHAlignment('C');

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


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

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

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

    if ($i == 0) {
        $pageFormat = new ReportLib\PageFormat('A4', 'P', 40.0, 15.0, 30.0, 15.0);
        $body->AddPageBreak($pageFormat);
    } else if ($i == 1) {
        $pageFormat = new ReportLib\PageFormat('A4', 'L', 30.0, 30.0, 20.0, 15.0);
        $body->AddPageBreak($pageFormat);
    }
}

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