How to Generate PDF with Full-Width Rows in WordPress Using FPDF

Introduction

Do you want to create custom PDF files directly from your WordPress site? Whether it’s for reports, invoices, or downloadable summaries, generating PDFs with full-width rows and borders is a common requirement. In this guide, we’ll show you how to use FPDF (a lightweight PHP library) to generate professional PDFs inside WordPress.

Why Generate PDF in WordPress?

PDFs are one of the most reliable formats for sharing documents. In WordPress, you may need them for:

  • Generating invoices automatically

  • Exporting reports or forms

  • Offering downloadable eBooks or guides

  • Creating structured session summaries or compliance reports

Instead of relying on third-party plugins, you can control everything with PHP and FPDF.

Step 1: Install FPDF in WordPress

  1. Download the FPDF library.

  2. Upload it into your WordPress directory:

    /wp-content/plugins/custom-pdf/fpdf.php
    
  3. Create a custom plugin or add the code in your theme’s functions.php.

Step 2: Create a WordPress Shortcode for PDF Download

Add this code to your plugin file (e.g., custom-pdf.php):

<?php
/**
 * Plugin Name: Custom PDF Generator
 */
require_once plugin_dir_path(__FILE__) . 'fpdf.php';

add_shortcode('generate_pdf', function() {
    if (isset($_GET['download_pdf'])) {
        $pdf = new FPDF();
        $pdf->AddPage();

        // Title
        $pdf->SetFont('Arial','B',12);
        $pdf->Cell(0,10,"Brief Summary of Session",0,1,'L',true);

        // Sample JSON data
        $point6f = '[{"PointA_title":"k1 Brief of Session"},{"PointA_title":"k2 Brief of Session"}]';
        $datapoint6f = json_decode($point6f, true);

        $pdf->SetFont('Arial','',10);
        $fullWidth = $pdf->GetPageWidth() - $pdf->lMargin - $pdf->rMargin;

        foreach ($datapoint6f as $item) {
            $pdf->MultiCell($fullWidth, 6, utf8_decode($item['PointA_title']), 1, 'L');
            $pdf->Ln(2);
        }

        $pdf->Output('D', 'session-summary.pdf'); // Force download
        exit;
    }

    return '<a href="?download_pdf=1" class="button">Download PDF</a>';
});

Now add [generate_pdf] anywhere in your post or page to display a Download PDF button.

Step 3: Generate Full-Width Rows with Borders

The key part is this snippet:

$fullWidth = $pdf->GetPageWidth() - $pdf->lMargin - $pdf->rMargin;
$pdf->MultiCell($fullWidth, 6, utf8_decode($item['PointA_title']), 1, 'L');

 

  • GetPageWidth() → total width of the page.

  • $pdf->lMargin and $pdf->rMargin → left and right margins.

  • MultiCell() → ensures text wraps properly inside a bordered full-width cell.

The result:

+---------------------------------+
| k1 Brief of Session             |
+---------------------------------+
| k2 Brief of Session             |
+---------------------------------+

Step 4: Test the Output

  1. Go to the page where you added [generate_pdf].

  2. Click the Download PDF button.

  3. Your PDF will download with each session displayed in its own bordered full-width row.

Advanced Tips

  • Pull data dynamically from WordPress posts or custom fields (ACF/Meta).

  • Customize fonts, colors, and headers for branding.

  • Extend with TCPDF if you need more advanced features like QR codes, tables, or images.

Conclusion

Generating PDFs inside WordPress doesn’t have to be complicated. With FPDF, you can create structured documents like invoices, reports, and summaries with full-width rows and consistent borders. Add a simple shortcode, and you’re ready to offer downloadable PDFs on your website.

Previous Article

PDF in WordPress using FPDF : Custom PDF Generator

Next Article

FPDF : Table with MultiCells

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨