SlideShare ist ein Scribd-Unternehmen logo
1 von 20
BUILDING PHP DOCUMENTS
      WITH CAKEPDF
      CakeFest Manchester, 2012
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
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
WHY IT WAS BUILT
• Massive   differences in API between pdf libraries
// Using DomPdf                          // Tcpdf example

require_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');
WHY IT WAS BUILT
• And   now with CakePdf
// Using DomPdf                        // Tcpdf example

App::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);
WHY IT WAS BUILT
• And   now with CakePdf
// Using DomPdf                        // Tcpdf example

App::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);
BUILT IN RENDER ENGINES
                         External Binary
  WkHtmlToPdf   stable
                          Uses WebKit


    DomPdf      alpha      PHP Based



     Mpdf       alpha      PHP Based



     Tcpdf      alpha      PHP Based
BUILT IN RENDER ENGINES
                               External Binary
  WkHtmlToPdf   stable
                                Uses WebKit


    DomPdf      alpha            PHP Based



     Mpdf       alpha    Very Nice!
                               PHP Based



     Tcpdf      alpha            PHP Based
CONFIGURATION
                           Setup
Add in Config/bootstrap.php

CakePlugin::load('CakePdf', array(
    'bootstrap' => true,
    'routes' => true
));



Needs RequestHandlerComponent

class AppController extends Controller {
    public $components = array('RequestHandler');
}
CONFIGURATION
           Special case for CakePHP 2.1.x
Config/bootstrap.php

CakePlugin::load('CakePdf', array(
    'bootstrap' => true
));




Config/routes.php

Router::parseExtensions('pdf');
CONFIGURATION
                            Settings
Global settings
// Config/bootstrap.php
Configure::write('CakePdf', array(
    'engine' => 'CakePdf.WkHtmlToPdf',
    'pageSize' => 'A4',
    'orientation' => 'portrait'
));

Inside the controller
public function view($id) {
    $this->pdfConfig = array(
        'orientation' => 'landscape',
        'download' => true,
        'filename' => 'invoice-2005.pdf'
    );
    .. Rest of action logic ..
}
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
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
STAND-ALONE FLOW
App::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);
ENCRYPTING PDF FILES

• Protect   against viewing, printing, editing and more

• pdftk   binary from PDFLabs

• 128   bit encryption

• Second    pass encryption

• Encrypt   existing PDF documents
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
CRYPTO CONFIGURATION

Add in Config/bootstrap.php

//Default configuration
Configure::write('CakePdf', array(
    'engine' => 'CakePdf.WkHtmlToPdf',
    'crypto' => 'CakePdf.Pdftk'
));
USING ENCRYPTING
//Action configuration
public function view($id) {
    $this->pdfConfig = array(
        'orientation' => 'landscape',
        'protect' => true,
        'userPassword' => 'foo',
        'ownerPassword' => 'bar',
        'permissions' => array(
            'print'
        )
    );
    .. Rest of action logic ..
}
TECHNICAL DEMO
http://github.com/ceeram/CakePdf




              THANKS


Jelle Henkens - @lemonit - jelle.henkens@gmail.com

Weitere ähnliche Inhalte

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Empfohlen

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Empfohlen (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Building PHP Documents with CakePdf - CakeFest 2012

  • 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 example require_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 example App::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 example App::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 Setup Add in Config/bootstrap.php CakePlugin::load('CakePdf', array( 'bootstrap' => true, 'routes' => true )); Needs RequestHandlerComponent class AppController extends Controller { public $components = array('RequestHandler'); }
  • 10. CONFIGURATION Special case for CakePHP 2.1.x Config/bootstrap.php CakePlugin::load('CakePdf', array( 'bootstrap' => true )); Config/routes.php Router::parseExtensions('pdf');
  • 11. CONFIGURATION Settings Global settings // Config/bootstrap.php Configure::write('CakePdf', array( 'engine' => 'CakePdf.WkHtmlToPdf', 'pageSize' => 'A4', 'orientation' => 'portrait' )); Inside the controller public 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 FLOW App::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 CONFIGURATION Add in Config/bootstrap.php //Default configuration Configure::write('CakePdf', array( 'engine' => 'CakePdf.WkHtmlToPdf', 'crypto' => 'CakePdf.Pdftk' ));
  • 18. USING ENCRYPTING //Action configuration public function view($id) { $this->pdfConfig = array( 'orientation' => 'landscape', 'protect' => true, 'userPassword' => 'foo', 'ownerPassword' => 'bar', 'permissions' => array( 'print' ) ); .. Rest of action logic .. }
  • 20. http://github.com/ceeram/CakePdf THANKS Jelle Henkens - @lemonit - jelle.henkens@gmail.com

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n