Example 28
Description
There are situations where the library can’t create a report. In these cases an exception is thrown.
One problem is an endless loop because of a circle dependency in the report structure.
A problem is also if a frame should be kept together but the size of the complete frame is bigger than the space on a page.
Another problem is when there is no space left in frame to put another frame into it. In the example the first text uses the whole width so the second text does not get any space.
If a FixposFrame uses offset values which are outside the printable area and the frame may not overlay other frames an exception is thrown.
If the file which name is passed to an ImageFrame does not exist or is not a valid image file an exception is thrown.
Output
The messages of the four Exception will be shown on the screen:
Exception: Endless recursion loop in the report structure. in C:\xampp\htdocs\src\Report.php:124 Stack trace: #0 C:\xampp\htdocs\examples\example_028.php(55): Adi\ReportLib\Report->output(‘C:\\xampp\\htdocs…’, ‘I’) #1 {main}
Exception: Too big keepTogether frame! in C:\xampp\htdocs\src\ReportFrame.php:501 Stack trace: #0 C:\xampp\htdocs\src\SerialFrame.php(138): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #1 C:\xampp\htdocs\src\SerialFrame.php(195): Adi\ReportLib\SerialFrame->sizePrintFrames(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect), true, false) #2 C:\xampp\htdocs\src\ReportFrame.php(492): Adi\ReportLib\SerialFrame->doCalcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #3 C:\xampp\htdocs\src\ReportFrame.php(536): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #4 C:\xampp\htdocs\src\Report.php(275): Adi\ReportLib\ReportFrame->print(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #5 C:\xampp\htdocs\src\Report.php(321): Adi\ReportLib\Report->printAPage(Object(Adi\ReportLib\Renderer)) #6 C:\xampp\htdocs\src\Report.php(206): Adi\ReportLib\Report->onPrintPage(Object(Adi\ReportLib\Renderer)) #7 C:\xampp\htdocs\src\Report.php(126): Adi\ReportLib\Report->printReport(Object(Adi\ReportLib\Renderer), ‘C:\\xampp\\htdocs…’, ‘I’) #8 C:\xampp\htdocs\examples\example_028.php(72): Adi\ReportLib\Report->output(‘C:\\xampp\\htdocs…’, ‘I’) #9 {main}
Exception: No space left in frame for another frame! in C:\xampp\htdocs\src\ReportFrame.php:511 Stack trace: #0 C:\xampp\htdocs\src\SerialFrame.php(138): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #1 C:\xampp\htdocs\src\SerialFrame.php(195): Adi\ReportLib\SerialFrame->sizePrintFrames(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect), true, false) #2 C:\xampp\htdocs\src\ReportFrame.php(492): Adi\ReportLib\SerialFrame->doCalcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #3 C:\xampp\htdocs\src\SerialFrame.php(138): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #4 C:\xampp\htdocs\src\SerialFrame.php(195): Adi\ReportLib\SerialFrame->sizePrintFrames(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect), true, false) #5 C:\xampp\htdocs\src\ReportFrame.php(492): Adi\ReportLib\SerialFrame->doCalcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #6 C:\xampp\htdocs\src\ReportFrame.php(536): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #7 C:\xampp\htdocs\src\Report.php(275): Adi\ReportLib\ReportFrame->print(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #8 C:\xampp\htdocs\src\Report.php(321): Adi\ReportLib\Report->printAPage(Object(Adi\ReportLib\Renderer)) #9 C:\xampp\htdocs\src\Report.php(206): Adi\ReportLib\Report->onPrintPage(Object(Adi\ReportLib\Renderer)) #10 C:\xampp\htdocs\src\Report.php(126): Adi\ReportLib\Report->printReport(Object(Adi\ReportLib\Renderer), ‘C:\\xampp\\htdocs…’, ‘I’) #11 C:\xampp\htdocs\examples\example_028.php(86): Adi\ReportLib\Report->output(‘C:\\xampp\\htdocs…’, ‘I’) #12 {main}
Exception: Non overlay FixposFrame is outside the printable area in C:\Develop\ReportLib\src\FixposFrame.php:146 Stack trace: #0 C:\Develop\ReportLib\src\ReportFrame.php(492): Adi\ReportLib\FixposFrame->doCalcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #1 C:\Develop\ReportLib\src\SerialFrame.php(138): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #2 C:\Develop\ReportLib\src\SerialFrame.php(195): Adi\ReportLib\SerialFrame->sizePrintFrames(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect), true, false) #3 C:\Develop\ReportLib\src\ReportFrame.php(492): Adi\ReportLib\SerialFrame->doCalcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #4 C:\Develop\ReportLib\src\ReportFrame.php(536): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #5 C:\Develop\ReportLib\src\Report.php(275): Adi\ReportLib\ReportFrame->print(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #6 C:\Develop\ReportLib\src\Report.php(321): Adi\ReportLib\Report->printAPage(Object(Adi\ReportLib\Renderer)) #7 C:\Develop\ReportLib\src\Report.php(206): Adi\ReportLib\Report->onPrintPage(Object(Adi\ReportLib\Renderer)) #8 C:\Develop\ReportLib\src\Report.php(126): Adi\ReportLib\Report->printReport(Object(Adi\ReportLib\Renderer), ‘C:\\Develop\\Repo…’, ‘I’) #9 C:\Develop\ReportLib\examples\example_028.php(98): Adi\ReportLib\Report->output(‘C:\\Develop\\Repo…’) #10 {main}
Exception: Image file does not exist. in C:\Develop\ReportLib\src\ImageFrame.php:215 Stack trace: #0 C:\Develop\ReportLib\src\ReportFrame.php(469): Adi\ReportLib\ImageFrame->doBeginPrint(Object(Adi\ReportLib\Renderer)) #1 C:\Develop\ReportLib\src\ReportFrame.php(483): Adi\ReportLib\ReportFrame->beginPrint(Object(Adi\ReportLib\Renderer)) #2 C:\Develop\ReportLib\src\SerialFrame.php(138): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #3 C:\Develop\ReportLib\src\SerialFrame.php(195): Adi\ReportLib\SerialFrame->sizePrintFrames(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect), true, false) #4 C:\Develop\ReportLib\src\ReportFrame.php(486): Adi\ReportLib\SerialFrame->doCalcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #5 C:\Develop\ReportLib\src\ReportFrame.php(531): Adi\ReportLib\ReportFrame->calcSize(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #6 C:\Develop\ReportLib\src\Report.php(277): Adi\ReportLib\ReportFrame->print(Object(Adi\ReportLib\Renderer), Object(Adi\ReportLib\Rect)) #7 C:\Develop\ReportLib\src\Report.php(325): Adi\ReportLib\Report->printAPage(Object(Adi\ReportLib\Renderer)) #8 C:\Develop\ReportLib\src\Report.php(207): Adi\ReportLib\Report->onPrintPage(Object(Adi\ReportLib\Renderer)) #9 C:\Develop\ReportLib\src\Report.php(126): Adi\ReportLib\Report->printReport(Object(Adi\ReportLib\Renderer), ‘C:\\Develop\\Repo…’, ‘I’) #10 C:\Develop\ReportLib\examples\example_028.php(109): Adi\ReportLib\Report->output(‘C:\\Develop\\Repo…’) #11 {main}
<?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); // 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."; $errorText = ""; // Endless loop because of circle reference in the structure $box1 = $body->AddBox(); $box2 = $box1->AddBox(); $box2->addFrame($body); try { $report->output(__DIR__ . "/example_028.pdf"); } catch (Exception $e) { $errorText .= $e; $errorText .= "<br><br><br>"; $body->clearFrames(); } // Exception because of a frame that has to be kept together but is to height for a page. $box = $body->AddBox(); $box->setKeepTogether(true); $vc = $box->AddVContainer(); for ($i = 0; $i < 20; $i++) { $vc->AddText("Paragraph number " . $i+1, $tsNormal); $vc->AddText($text, $tsNormal); $vc->AddVDistance(2.0); } try { $report->output(__DIR__ . "/example_028.pdf"); } catch (Exception $e) { $errorText .= $e; $errorText .= "<br><br><br>"; $body->clearFrames(); } // Exception because there is no space for a frame $hc = $body->AddHContainer(); $hc->AddText($text, $tsNormal); $hc->AddText($text, $tsNormal); try { $report->output(__DIR__ . "/example_028.pdf"); } catch (Exception $e) { $errorText .= $e; $errorText .= "<br><br><br>"; $body->clearFrames(); } // Exception because of FixposFrame offsets outside printable area $f = new ReportLib\FixposFrame(0.0, 0.0); $f->AddHLine(); $report->getBody()->AddFrame($f); try { $report->output(__DIR__ . "/example_028.pdf"); } catch (Exception $e) { $errorText .= $e; $errorText .= "<br><br><br>"; $body->clearFrames(); } // Exception because of Image does not exist $f = new ReportLib\ImageFrame(""); $report->getBody()->AddFrame($f); try { $report->output(__DIR__ . "/example_028.pdf"); } catch (Exception $e) { $errorText .= $e; $errorText .= "<br><br><br>"; $body->clearFrames(); } echo $errorText;