<?php /** * Html2Pdf Library - example * * HTML => PDF convertor * distributed under the LGPL License * * isset($_GET['vuehtml']) is not mandatory * it allow to display the result in the HTML format * * @package Html2pdf * @author Laurent MINGUET <*****@*****.**> * @copyright 2016 Laurent MINGUET */ require_once dirname(__FILE__) . '/../vendor/autoload.php'; use Spipu\Html2Pdf\Html2Pdf; use Spipu\Html2Pdf\Html2PdfException; // get the HTML ob_start(); require dirname(__FILE__) . '/res/exemple01.php'; $content = ob_get_clean(); // convert to PDF try { $html2pdf = new Html2Pdf('P', 'A4', 'fr'); $html2pdf->writeHTML($content, isset($_GET['vuehtml'])); $html2pdf->Output('exemple01.pdf'); } catch (Html2PdfException $e) { echo $e; exit; }
public function testExtensionTag() { $tag = Phake::mock('Spipu\\Html2Pdf\\Tag\\TagInterface'); Phake::when($tag)->getName()->thenReturn('test_tag'); $extension = Phake::mock('Spipu\\Html2Pdf\\Extension\\ExtensionInterface'); Phake::when($extension)->getName()->thenReturn('test'); Phake::when($extension)->getTags()->thenReturn(array($tag)); $this->html2pdf->addExtension($extension); $this->html2pdf->writeHTML('<test_tag/>'); Phake::verify($tag)->open; Phake::verify($tag, Phake::times(2))->close; // TODO Html2Pdf should probably call this only one time }
/** * test * * @return void * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('<g />'); $object->Output('test.pdf', 'S'); }
/** * test: The image src is unknown * * @return void * @expectedException \Spipu\Html2Pdf\Exception\ImageException */ public function testCase() { $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('Hello World <img src="' . dirname(__FILE__) . '/res/wrong.png" />'); $object->Output('test.pdf', 'S'); }
/** * test: The image src is unknown * * @return void * @expectedException \Spipu\Html2Pdf\Exception\ImageException */ public function testCase() { $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('<div style="background-image: url(' . dirname(__FILE__) . '/res/wrong.png)">Hello World</div>'); $object->Output('test.pdf', 'S'); }
/** * test: the file extension must be PDF * * @return void * @expectedException \Spipu\Html2Pdf\Exception\Html2PdfException */ public function testCase() { $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('<p>Hello World</p>'); $object->Output('test.bad', 'S'); }
/** * test: The HTML tag code provided is invalid * * @return void * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testInvalidCode() { $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('<az1-r_h>Hello</az1-r_h>'); $object->Output('test.pdf', 'S'); }
/** * test: The image src is unknown * * @return void */ public function testCase() { $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('Hello World <img src="' . dirname(__FILE__) . '/res/logo.png" />'); $result = $object->Output('test.pdf', 'S'); $this->assertContains('PhpUnit Test', $result); }
/** * test: the file extension must be PDF * * @return void */ public function testCase() { $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('Hello World'); $result = $object->Output('test.pdf', 'S'); $this->assertContains('PhpUnit Test', $result); }
/** * test * * @return void * @expectedException \Spipu\Html2Pdf\Exception\TableException */ public function testCase() { $sentence = 'Hello World ! '; $sentences = ''; for ($k = 0; $k < 100; $k++) { $sentences .= $sentence; } $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML('<table><tr><td style="width: 28mm">' . $sentences . '</td></tr></table>'); $object->Output('test.pdf', 'S'); }
/** * test * * @return void * @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException */ public function testCase() { $html = ' <page> <draw style="width:150mm; height:100mm;"> <path style="fill:#770000; stroke:#AA0033;" d="n 20mm,40mm a16mm,8mm 0,0,0 16mm,8mm" /> </draw> </page>'; $object = new Html2Pdf(); $object->pdf->SetTitle('PhpUnit Test'); $object->writeHTML($html); $object->Output('test.pdf', 'S'); }
<?php /** * Html2Pdf Library - example * * HTML => PDF converter * distributed under the LGPL License * * @package Html2pdf * @author Laurent MINGUET <*****@*****.**> * @copyright 2016 Laurent MINGUET */ require_once dirname(__FILE__) . '/../vendor/autoload.php'; use Spipu\Html2Pdf\Html2Pdf; use Spipu\Html2Pdf\Exception\Html2PdfException; use Spipu\Html2Pdf\Exception\ExceptionFormatter; try { ob_start(); include dirname(__FILE__) . '/res/exemple02.php'; $content = ob_get_clean(); $html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', array(15, 5, 15, 5)); $html2pdf->pdf->SetDisplayMode('fullpage'); $html2pdf->writeHTML($content); $html2pdf->Output('exemple02.pdf'); } catch (Html2PdfException $e) { $formatter = new ExceptionFormatter($e); echo $formatter->getHtmlMessage(); }