Your SlideShare is downloading. ×
0
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Building PHP Documents with CakePdf - CakeFest 2012
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Building PHP Documents with CakePdf - CakeFest 2012

6,065

Published on

Tech talk given by Jelle Henkens at CakeFest 2012 in Manchester, UK. …

Tech talk given by Jelle Henkens at CakeFest 2012 in Manchester, UK.

Integrating the CakePdf plugin to generate PDF documents in your CakePHP applications using WkHtmlToPdf.

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
  • @jellehenkens : I created the PDF version here http://www.slideshare.net/iamthom/building-php-documents-with-cakepdf-cakefest-2012-14566279. Hope it doesn't matter. If you mind of it, just call me..
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
6,065
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
87
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. BUILDING PHP DOCUMENTS WITH CAKEPDF CakeFest Manchester, 2012
    • 2. ABOUT ME• Jelle Henkens• LemonBE on IRC, @lemonit on Twitter• Belgian in the UK• Lead Developer at Geneo Software• CakePHP Core Team Developer• Founder of followmy.tv
    • 3. WHAT IS CAKEPDF• Generate PDF documents from HTML• Easily pick which library to render the PDF• PDF Encryption• Layouts, views, helpers and more• Use your own encryption / render engine
    • 4. WHY IT WAS BUILT• Massive differences in API between pdf libraries// Using DomPdf // Tcpdf examplerequire_once("dompdf_config.inc.php"); require_once(config/lang/eng.php); require_once(tcpdf.php);$html = <html><body>. $html = <p>Put your html here.</p>. <html><body>. </body></html>; <p>Put your html here.</p>. </body></html>;$dompdf = new DOMPDF();$dompdf->set_paper(A4, landscape); $tcpdf = new TCPDF(portrait, mm,$dompdf-> A4);$dompdf->load_html($html); $tcpdf->AddPage();$dompdf->render(); $tcpdf->writeHTML($html);$pdfData = $dompdf->output(); $pdfData = $tcpdf->Output(, S);
    • 5. WHY IT WAS BUILT• And now with CakePdf// Using DomPdf // Tcpdf exampleApp::uses(CakePdf, CakePdf.Pdf); App::uses(CakePdf, CakePdf.Pdf);$html = $html = <html><body>. <html><body>. <p>Put your html here.</p>. <p>Put your html here.</p>. </body></html>; </body></html>;$cakePdf = new CakePdf(array( $cakePdf = new CakePdf(array( engine => CakePdf.DomPdf, engine => CakePdf.Tcpdf, orientation => portrait, orientation => portrait, pageSize => A4 pageSize => A4)); ));$pdfData = $cakePdf->output($html); $pdfData = $cakePdf->output($html);
    • 6. WHY IT WAS BUILT• And now with CakePdf// Using DomPdf // Tcpdf exampleApp::uses(CakePdf, CakePdf.Pdf); App::uses(CakePdf, CakePdf.Pdf);$html = $html = <html><body>. <html><body>. <p>Put your html here.</p>. <p>Put your html here.</p>. </body></html>; </body></html>;$cakePdf = new CakePdf(array( $cakePdf = new CakePdf(array( engine => CakePdf.DomPdf, engine => CakePdf.Tcpdf, orientation => portrait, orientation => portrait, pageSize => A4 pageSize => A4)); ));$pdfData = $cakePdf->output($html); $pdfData = $cakePdf->output($html);
    • 7. BUILT IN RENDER ENGINES External Binary WkHtmlToPdf stable Uses WebKit DomPdf alpha PHP Based Mpdf alpha PHP Based Tcpdf alpha PHP Based
    • 8. BUILT IN RENDER ENGINES External Binary WkHtmlToPdf stable Uses WebKit DomPdf alpha PHP Based Mpdf alpha Very Nice! PHP Based Tcpdf alpha PHP Based
    • 9. CONFIGURATION SetupAdd in Config/bootstrap.phpCakePlugin::load(CakePdf, array( bootstrap => true, routes => true));Needs RequestHandlerComponentclass AppController extends Controller { public $components = array(RequestHandler);}
    • 10. CONFIGURATION Special case for CakePHP 2.1.xConfig/bootstrap.phpCakePlugin::load(CakePdf, array( bootstrap => true));Config/routes.phpRouter::parseExtensions(pdf);
    • 11. CONFIGURATION SettingsGlobal settings// Config/bootstrap.phpConfigure::write(CakePdf, array( engine => CakePdf.WkHtmlToPdf, pageSize => A4, orientation => portrait));Inside the controllerpublic function view($id) { $this->pdfConfig = array( orientation => landscape, download => true, filename => invoice-2005.pdf ); .. Rest of action logic ..}
    • 12. TO VIEW OR NOT TO VIEW• Generating PDF files with the .pdf extension in the URL • Viewing PDF documents in the browser • Download to disk • Smaller files• Stand-alone to generate raw PDF data • Email attachments • Offline processing • Larger files
    • 13. REQUESTHANDLER FLOW View in browser or download to disk• Layout file App/View/Layout/pdf/default.ctp• View file App/View/Orders/pdf/invoice.ctp• All the CakePHP goodies to your disposal • Helpers • Blocks • Elements
    • 14. STAND-ALONE FLOWApp::uses(CakePdf, CakePdf.Pdf);$CakePdf = new CakePdf(array( engine => CakePdf.Tcpdf, pageSize => A5, orientation => landscape, margin => 10));$html = <html><head></head><body><p>CakeFest is the best</p></body></html>;$rawPdfData = $CakePdf->output($html);
    • 15. ENCRYPTING PDF FILES• Protect against viewing, printing, editing and more• pdftk binary from PDFLabs• 128 bit encryption• Second pass encryption• Encrypt existing PDF documents
    • 16. PASSWORD TYPES• Owner password • Unlock protected permissions • Cannot be the same as the user password• User password • Will prompt before opening the PDF Document • Cannot exist without an owner password
    • 17. CRYPTO CONFIGURATIONAdd in Config/bootstrap.php//Default configurationConfigure::write(CakePdf, array( engine => CakePdf.WkHtmlToPdf, crypto => CakePdf.Pdftk));
    • 18. USING ENCRYPTING//Action configurationpublic function view($id) { $this->pdfConfig = array( orientation => landscape, protect => true, userPassword => foo, ownerPassword => bar, permissions => array( print ) ); .. Rest of action logic ..}
    • 19. TECHNICAL DEMO
    • 20. http://github.com/ceeram/CakePdf THANKSJelle Henkens - @lemonit - jelle.henkens@gmail.com

    ×