SlideShare une entreprise Scribd logo
1  sur  22
PHP to pdf files May 7,2009 By Eric Michalsen [email_address]
WHAT? PHP to pdf files, dynamically cool stuff!
Why in the world would you want to do that?? pfd's are cool, fun, secure, scary, pain in the butt...
Cody says “Hmmm, I'm intrigued. Tell me more.”
Tools To Use: TCPDF www.tcpdf.org TCPDF project was started in 2002 and now it is  freely used all over the world by millions of people.  TCPDF is a Free Libre Open Source Software (FLOSS).
- no external libraries are required for the basic functions; - supports all ISO page formats; - supports custom page formats, margins and units of measure; - supports UTF-8 Unicode and Right-To-Left languages; - supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts; - supports document encryption; - includes methods to publish some (x)HTML code; - includes graphic (geometric) and transformation methods; - includes Javascript and forms support; blah blah blah... Copy/Paste from their website...
Cody says “ROCK ON! This is going to be easy!”
RTFM Follow the installation instructions. Seriously.  If I can do it, so can you! Most of the examples in this presentation are bastardized from the tcpdf.org site.
<? $dir_file = &quot;files/&quot;.$file; require_once('config/lang/eng.php'); require_once('tcpdf.php'); class MYPDF extends TCPDF  { public function LoadData($file)  { $lines=file($file); $data=array(); foreach($lines as $line)‏ { $data[]=explode(';',chop($line)); } return $data; } public function ColoredTable($header,$data)  { $this->SetFillColor(255,0,0); $this->SetTextColor(255); $this->SetDrawColor(128,0,0); $this->SetLineWidth(.3); $this->SetFont('','B'); $w=array(40,167,30,30); for($i=0;$i<count($header);$i++)‏ $this->Cell($w[$i],7,$header[$i],1,0,'C',1); $this->Ln(); $this->SetFillColor(224,235,255); $this->SetTextColor(0); $this->SetFont(''); $fill=0; foreach($data as $row)  { $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);   $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);   $this->Cell($w[2],6,$row[2],'LR',0,'R',$fill);   $this->Cell($w[3],6,$row[3],'LR',0,'R',$fill);  $this->Ln();   $fill=!$fill; } $this->Cell(array_sum($w),0,'','T'); } } $pdf = new MYPDF(PDF_PAGE_ORIENTATION,   PDF_UNIT,   PDF_PAGE_FORMAT, true);  $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(&quot;Eric Michalsen&quot;); $pdf->SetTitle(&quot;TrendEyes  www.trendeyes.com&quot;); $pdf->SetSubject(&quot;PDF Report&quot;); $pdf->SetKeywords(&quot;PDF Report&quot;); $pdf->SetHeaderData(PDF_HEADER_LOGO,    PDF_HEADER_LOGO_WIDTH,    PDF_HEADER_TITLE,    PDF_HEADER_STRING); $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);  $pdf->setLanguageArray($l);  $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFont(&quot;helvetica&quot;, &quot;&quot;, 8); $header=array('Metric','Detail','Description','Alternate'); $data=$pdf->LoadData($dir_file); $pdf->ColoredTable($header,$data); $pdf->Output(&quot;report.pdf&quot;);  ?>
“ Hey, I thought you said this would be easy!”
Step 1 :: Hello World <?PHP //////////////////////////// ///  Include the TCPDF files //////////////////////////// require_once('config/lang/eng.php'); require_once('tcpdf.php'); // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);   $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Eric Michalsen'); $pdf->SetTitle('Example 1'); $pdf->SetSubject('Western Suburb PHP Meetup'); $pdf->SetKeywords('PHP, PDF, example');  $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);  $pdf->setLanguageArray($l);  $pdf->SetFont('times', 'BI', 20); $pdf->AddPage(); $pdf->Cell(0, 10, 'Hello World', 1, 1, 'C'); $pdf->Output('example.pdf', 'I');  ?>
 
<?PHP require_once('config/lang/eng.php'); require_once('tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);  $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Eric Michalsen'); $pdf->SetTitle('example 2'); $pdf->SetSubject('Image'); $pdf->SetKeywords('TCPDF, PDF, example'); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);  $pdf->setLanguageArray($l);  $pdf->AddPage(); $pdf->setJPEGQuality(75); $pdf->Image('images/lightning.jpg', 50, 50, 100, 150, '', 'http://www.foxvalleycp.com', '', true, 150); $pdf->Output('2.pdf', 'I'); ?>
 
<?php require_once('config/lang/eng.php'); require_once('tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Eric Michalsen'); $pdf->SetTitle('example 3'); $pdf->SetSubject('hmmmm...pie'); $pdf->SetKeywords('TCPDF, PDF, example'); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setLanguageArray($l); $pdf->SetFont('helvetica', '', 14); $pdf->AddPage(); $xc = 70;  // from left $yc = 70;  // from top $r = 50;  // radius $pdf->SetFillColor(120, 120, 255); // blue $pdf->PieSector($xc, $yc, $r, 0, 90); //x,y,r,starting,ending degrees $pdf->SetFillColor(120, 255, 120); // green $pdf->PieSector($xc, $yc, $r, 90, 100); $pdf->SetFillColor(255, 120, 120); // red $pdf->PieSector($xc, $yc, $r, 130, 270); $pdf->Output('3.pdf', 'I'); ?>
 
$xc = 70;  $yc = 70;  $r = 50;  // text annotation $pdf->Annotation(100, 10, 20, 10, &quot;First LineSecond Line&quot;,  array('Subtype'=>'Text',  'Name' => 'Comment',  'T' => '90% Blue',  'Subj' => 'example',  'C' => array(255, 255, 0))); $pdf->SetFillColor(120, 120, 255); // blue $pdf->PieSector($xc, $yc, $r, 0, 90); //x,y,r,starting,ending degrees hmmm....pie ...but what does it mean? We Need Annotation Baby!
Mouse Over Fancy Stuff
$pdf->SetFillColor(120, 120, 255); // blue $pdf->PieSector($xc, $yc, $r, 0, 90); //x,y,r,starting,ending degrees $pdf->SetFillColor(120, 255, 120); // green $pdf->PieSector($xc, $yc, $r, 90, 100); $pdf->SetFillColor(255, 120, 120); // red $pdf->PieSector($xc, $yc, $r, 130, 270); $pdf->Text(100, 20, '90% is Blue'); $pdf->Text(130, 75, '10% is Green'); $pdf->Text(20, 125, '82% is Red'); ...or just plain text...
 
end
Eric Michalsen [email_address] Fox Valley Computing Professionals www.foxvalleycp.com Twitter #FVCP

Contenu connexe

Dernier

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
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
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
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...
 

Php2pdf

  • 1. PHP to pdf files May 7,2009 By Eric Michalsen [email_address]
  • 2. WHAT? PHP to pdf files, dynamically cool stuff!
  • 3. Why in the world would you want to do that?? pfd's are cool, fun, secure, scary, pain in the butt...
  • 4. Cody says “Hmmm, I'm intrigued. Tell me more.”
  • 5. Tools To Use: TCPDF www.tcpdf.org TCPDF project was started in 2002 and now it is freely used all over the world by millions of people. TCPDF is a Free Libre Open Source Software (FLOSS).
  • 6. - no external libraries are required for the basic functions; - supports all ISO page formats; - supports custom page formats, margins and units of measure; - supports UTF-8 Unicode and Right-To-Left languages; - supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts; - supports document encryption; - includes methods to publish some (x)HTML code; - includes graphic (geometric) and transformation methods; - includes Javascript and forms support; blah blah blah... Copy/Paste from their website...
  • 7. Cody says “ROCK ON! This is going to be easy!”
  • 8. RTFM Follow the installation instructions. Seriously. If I can do it, so can you! Most of the examples in this presentation are bastardized from the tcpdf.org site.
  • 9. <? $dir_file = &quot;files/&quot;.$file; require_once('config/lang/eng.php'); require_once('tcpdf.php'); class MYPDF extends TCPDF { public function LoadData($file) { $lines=file($file); $data=array(); foreach($lines as $line)‏ { $data[]=explode(';',chop($line)); } return $data; } public function ColoredTable($header,$data) { $this->SetFillColor(255,0,0); $this->SetTextColor(255); $this->SetDrawColor(128,0,0); $this->SetLineWidth(.3); $this->SetFont('','B'); $w=array(40,167,30,30); for($i=0;$i<count($header);$i++)‏ $this->Cell($w[$i],7,$header[$i],1,0,'C',1); $this->Ln(); $this->SetFillColor(224,235,255); $this->SetTextColor(0); $this->SetFont(''); $fill=0; foreach($data as $row) { $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill); $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill); $this->Cell($w[2],6,$row[2],'LR',0,'R',$fill); $this->Cell($w[3],6,$row[3],'LR',0,'R',$fill); $this->Ln(); $fill=!$fill; } $this->Cell(array_sum($w),0,'','T'); } } $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(&quot;Eric Michalsen&quot;); $pdf->SetTitle(&quot;TrendEyes www.trendeyes.com&quot;); $pdf->SetSubject(&quot;PDF Report&quot;); $pdf->SetKeywords(&quot;PDF Report&quot;); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setLanguageArray($l); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFont(&quot;helvetica&quot;, &quot;&quot;, 8); $header=array('Metric','Detail','Description','Alternate'); $data=$pdf->LoadData($dir_file); $pdf->ColoredTable($header,$data); $pdf->Output(&quot;report.pdf&quot;); ?>
  • 10. “ Hey, I thought you said this would be easy!”
  • 11. Step 1 :: Hello World <?PHP //////////////////////////// /// Include the TCPDF files //////////////////////////// require_once('config/lang/eng.php'); require_once('tcpdf.php'); // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Eric Michalsen'); $pdf->SetTitle('Example 1'); $pdf->SetSubject('Western Suburb PHP Meetup'); $pdf->SetKeywords('PHP, PDF, example'); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setLanguageArray($l); $pdf->SetFont('times', 'BI', 20); $pdf->AddPage(); $pdf->Cell(0, 10, 'Hello World', 1, 1, 'C'); $pdf->Output('example.pdf', 'I'); ?>
  • 12.  
  • 13. <?PHP require_once('config/lang/eng.php'); require_once('tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Eric Michalsen'); $pdf->SetTitle('example 2'); $pdf->SetSubject('Image'); $pdf->SetKeywords('TCPDF, PDF, example'); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setLanguageArray($l); $pdf->AddPage(); $pdf->setJPEGQuality(75); $pdf->Image('images/lightning.jpg', 50, 50, 100, 150, '', 'http://www.foxvalleycp.com', '', true, 150); $pdf->Output('2.pdf', 'I'); ?>
  • 14.  
  • 15. <?php require_once('config/lang/eng.php'); require_once('tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Eric Michalsen'); $pdf->SetTitle('example 3'); $pdf->SetSubject('hmmmm...pie'); $pdf->SetKeywords('TCPDF, PDF, example'); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setLanguageArray($l); $pdf->SetFont('helvetica', '', 14); $pdf->AddPage(); $xc = 70; // from left $yc = 70; // from top $r = 50; // radius $pdf->SetFillColor(120, 120, 255); // blue $pdf->PieSector($xc, $yc, $r, 0, 90); //x,y,r,starting,ending degrees $pdf->SetFillColor(120, 255, 120); // green $pdf->PieSector($xc, $yc, $r, 90, 100); $pdf->SetFillColor(255, 120, 120); // red $pdf->PieSector($xc, $yc, $r, 130, 270); $pdf->Output('3.pdf', 'I'); ?>
  • 16.  
  • 17. $xc = 70; $yc = 70; $r = 50; // text annotation $pdf->Annotation(100, 10, 20, 10, &quot;First LineSecond Line&quot;, array('Subtype'=>'Text', 'Name' => 'Comment', 'T' => '90% Blue', 'Subj' => 'example', 'C' => array(255, 255, 0))); $pdf->SetFillColor(120, 120, 255); // blue $pdf->PieSector($xc, $yc, $r, 0, 90); //x,y,r,starting,ending degrees hmmm....pie ...but what does it mean? We Need Annotation Baby!
  • 19. $pdf->SetFillColor(120, 120, 255); // blue $pdf->PieSector($xc, $yc, $r, 0, 90); //x,y,r,starting,ending degrees $pdf->SetFillColor(120, 255, 120); // green $pdf->PieSector($xc, $yc, $r, 90, 100); $pdf->SetFillColor(255, 120, 120); // red $pdf->PieSector($xc, $yc, $r, 130, 270); $pdf->Text(100, 20, '90% is Blue'); $pdf->Text(130, 75, '10% is Green'); $pdf->Text(20, 125, '82% is Red'); ...or just plain text...
  • 20.  
  • 21. end
  • 22. Eric Michalsen [email_address] Fox Valley Computing Professionals www.foxvalleycp.com Twitter #FVCP