Skip to content
Home Blog Web Design Creating PDF Files with PHP

Creating PDF Files with PHP

  • Web Design
Blueprint Digital
Blueprint Digital

Insights from the Blueprint Digital team.

FPDF is a PHP class which allows web developers to generate PDF files with pure PHP code. The class can be downloaded for free and modified to suit one’s needs. FPDF contains several practical features including:

  • Page header and footer management
  • Automatic page break, line break, and text justification
  • Image support (JPEG, PNG and GIF)
  • Color & font flexibility
  • Links
  • Tables and multiple columns
  • Various output options

A Basic PDF Made with PHP

The following code generates a PDF, as illustrated in the image below.

<?php
require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(50,10,'There and Back Again');
$pdf->Output();
?>

As the name suggest, the AddPage() function adds a new page to the document. Programmers can specify the orientation and size of the page.

The SetFont() function sets the font family, style (bold, italic, underline, or normal), and size (in pts). Every piece of text that comes after this function will inherit the defined arguments.

The Cell() function prints a rectangular area with optional dimensions (width & height), character string, borders, line breaks, text alignment, and background color. By default, unless the parameters specify otherwise, the cell will extend to fill the width of the page. After the call, if the cell’s specified width is less than the width of the page, the current position moves to the immediate right of the cell (similar to an inline element in HTML) or to the next line, depending on the parameter for the function’s call. In this example, the only parameters that have been specified are width (50 mm), height (10 mm), and the character string.

Finally, the Output() function sends the document to a given destination. By default, such as in this example, the document will send to the browser, which displays the PDF.

Ready to Dominate Online and Grow Your Business?

Schedule time to connect with Blueprint about your online goals, or request a free review of marketing campaigns.

Related Posts

What Is Automated Lead Follow-Up and How Does It Work

What Is Automated Lead Follow-Up and How Does It Work

A new lead fills out a form, then waits. If the phone stays silent for a day, that lead has usually moved on to whoever answered first. Automated lead follow-up closes the gap. It is a marketing automation system that responds to every new inquiry within minutes, then continues the conversation through scheduled texts, emails,[...]
Free Advertising for Nonprofits Through Google Ad Grants

Free Advertising for Nonprofits Through Google Ad Grants

Advertising is usually the first line cut from a nonprofit budget, and the one that quietly costs the most to lose. Donors still search, scroll, and read, whether or not the cause has money to meet them there. Free advertising for nonprofits means promoting a cause without paying for placements, and it is how organizations[...]
Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Every marketing team has handed sales a list of leads that went nowhere. After a few of those lists, sales stops trusting them, works its own referrals instead, and the two teams settle into a standing argument about lead quality. Underneath the argument is a simpler problem: nobody has written down what a good lead[...]
Previous
Next

Partner with BLUEPRINT to reach your online goals, grow your business and reshape your story.

Get in touch with BLUEPRINT

Reach out to request a discovery call, a free campaign review, or for all other inquiries.

Subscribe to our newsletter