raykolbe / DOMPDFModule

A Zend Framework module for Dompdf
MIT License
61 stars 62 forks source link

Configure DomPdf instantiation with service #2

Closed juriansluiman closed 12 years ago

juriansluiman commented 12 years ago

Now the DomPdf class is instantiated directly (see https://github.com/raykolbe/DOMPDFModule/blob/master/src/DOMPDFModule/View/Renderer/PdfRenderer.php#L38). But for example we always use DomPdf with these configuration options:

$domPdf = new DomPdf();
$domPdf->load_html(utf8_decode($html));
$domPdf->set_paper('a4', 'portrait');
$domPdf->set_base_path(realpath($path));
$domPdf->render();

If you configure the DomPdf as a service, I can overwrite the service with these properties and then be more flexible in my pdf rendering.

raykolbe commented 12 years ago

If I understand you correctly, you'd like to use your own instance of DOMPDF in DOMPDFModule?

Would it make more sense to change the DOMPDF package (https://github.com/raykolbe/dompdf) to incorporate a DOMPDF service here? This would allow consumers the ability to use just the DOMPDF package without relying on Zend\View and everything that comes with that.

raykolbe commented 12 years ago

I have added support for specifying paper size, paper orientation, and base path on an individual PdfModel instance basis.

This is as of commit b77aa55d1c.

You can accomplish this by returning PdfModel such as:

        return new PdfModel(
            array('model' => $model),
            array(
                'paperSize'         => 'a4',
                'paperOrientation'  => 'landscape',
                'basePath'          => '/'
            )
        );

or you can manually call setPaperSize, setPaperOrientation, setBasePath on PdfModel before returning it.

Can you elaborate a little more as to why you use utf8_decode($html)?

juriansluiman commented 12 years ago

@raykolbe thanks for the modifications, great! Whether this would suit best in the DomPdf module or this module, I don't know but I think this fix is good enough.

Re utf-8: we had many problems with Unicode support in previous versions of DomPdf. The code was a simple copy/paste, but in the latest DomPdf versions there is a proper fix for this. So don't bother that ;)