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

Creating PDF Files with PHP

  • Web Design
Blueprint Digital

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

Client Onboarding Process: The Key to Long-Term Revenue Growth

Client Onboarding Process: The Key to Long-Term Revenue Growth

A client relationship can feel clear, confident, and energized from the start, or it can feel scattered before the real work even begins. That difference often comes down to onboarding. The first 30 to 60 days shape how quickly clients trust your team, understand the strategy, and see where the work is headed. They are[...]
What Is a Lead Generation Agency & What Do They Actually Do?

What Is a Lead Generation Agency & What Do They Actually Do?

Growth can feel busy long before it feels predictable. A company may be getting website traffic and occasional inquiries, but still feel unsure about which opportunities are ready for a real conversation. As that question becomes harder to ignore, many leaders begin looking into what is a lead generation agency and how the right partner[...]
B2B Lead Generation Funnel: Stages, Metrics, and What to Improve

B2B Lead Generation Funnel: Stages, Metrics, and What to Improve

A company can have steady traffic, active ads, fresh content, and polished landing pages, but still struggle to turn interest into real sales conversations. The path from first click to qualified lead is not always easy to see, which is where a b2b lead generation funnel becomes useful. It shows where prospects enter, what they[...]
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