Exception

November 4, 2018 · View on GitHub

back

Exceptions

All the specific Html2Pdf exceptions are under the namespace \Spipu\Html2Pdf\Exception;

ExceptionError CodeAdditional InfoDescription
Html2PdfException0Occurs for every generic error during the process
HtmlParsingException 1
  • getInvalidTag
  • getHtmlLine
Occurs if the html is no valid
ImageException2
  • getImage
Occurs if the asked image does not exist
LongSentenceException3
  • getSentence
  • getWidthBox
  • getLength
Occurs is a sentence is too long and does not fit in the current box
TableException4Occurs if the content of a TD does not fit on only one page

Exception Format

An exception formatter can be used to display the exceptions: \Spipu\Html2Pdf\Exception\ExceptionFormatter.

It takes the current exception as a parameter of the constructor.

It provides 2 methods

  • getMessage()
  • getHtmlMessage();

Usage example:

try {
    use Spipu\Html2Pdf\Html2Pdf;
    use Spipu\Html2Pdf\Exception\Html2PdfException;
    use Spipu\Html2Pdf\Exception\ExceptionFormatter;

    $html2pdf = new Html2Pdf('P', 'A4', 'fr');
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($htmlContent);
    $html2pdf->output();
} catch (Html2PdfException $e) {
    $html2pdf->clean();

    $formatter = new ExceptionFormatter($e);
    echo $formatter->getHtmlMessage();
}

back