SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Último

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
[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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 

Último (20)

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
[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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 

Destacado

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
 

Destacado (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

Notas del editor

  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