ArtiGrid
v1.5

PDF


<?php
    $grid = new ArtiGrid();

    // Get PDF object
    $pdf = $grid->getPDFObject();

    // Sample invoice data
    $invoiceData = [
        "client_name" => "John Smith",
        "invoice_number" => "INV20260316",
        "invoice_date" => "2026-03-16",
        "due_date" => "2026-03-30",
        "notes" => "This is a sample invoice generated with ArtiGrid."
    ];

    $items = [
        ["description" => "Product A", "quantity" => 2, "unit_price" => 1500],
        ["description" => "Product B", "quantity" => 1, "unit_price" => 3000],
        ["description" => "Service C", "quantity" => 3, "unit_price" => 1200]
    ];

    // Calculate totals
    $totalAmount = 0;
    $rowsHtml = "";
    foreach ($items as $index => $item) {
        $amount = $item['quantity'] * $item['unit_price'];
        $totalAmount += $amount;
        $rowsHtml .= "<tr style='background-color:#f2f2f2;'>
            <td style='width:5%;text-align:center;'>".($index+1)."</td>
            <td style='width:50%;'>".$item['description']."</td>
            <td style='width:15%;text-align:center;'>".$item['quantity']."</td>
            <td style='width:15%;text-align:right;'>$ ".number_format($item['unit_price'],0,",",".")."</td>
            <td style='width:15%;text-align:right;'>$ ".number_format($amount,0,",",".")."</td>
        </tr>";
    }

    // Format total separately
    $totalFormatted = number_format($totalAmount, 0, ".", ",");

    // Full HTML invoice
    $html = <<<EOD
    <h1 style="text-align:center;">Invoice</h1>

    <table style="width:100%;font-size:12px;margin-bottom:20px;">
    <tr>
        <td style="width:50%;">Client:<br><strong>{$invoiceData['client_name']}</strong></td>
        <td style="width:50%;">Invoice No.:<br><strong>{$invoiceData['invoice_number']}</strong></td>
    </tr>
    <tr>
        <td>Invoice Date:<br>{$invoiceData['invoice_date']}</td>
        <td>Due Date:<br>{$invoiceData['due_date']}</td>
    </tr>
    </table>

    <table style="width:100%;border-collapse: collapse;font-size:11px;" border="1">
    <tr style="background-color:#d9d9d9;">
        <th style="width:5%;">#</th>
        <th style="width:50%;">Description</th>
        <th style="width:15%;">Quantity</th>
        <th style="width:15%;">Unit Price</th>
        <th style="width:15%;">Amount</th>
    </tr>
    $rowsHtml
    <tr style="background-color:#e1e1e1;">
        <td colspan="4" style="text-align:right;"><strong>Total</strong></td>
        <td style="text-align:right;"><strong>\$ $totalFormatted</strong></td>
    </tr>
    </table>

    <br>
    <p><strong>Notes:</strong><br>{$invoiceData['notes']}</p>
    EOD;

    // Set UTF-8 font and add a page
    $pdf->SetFont('dejavusans', '', 12, '', true);
    $pdf->AddPage();

    // Write HTML
    $pdf->WriteHTML($html);

    // Output PDF directly in browser
    $pdf->Output("invoice_demo.pdf", "I");
    exit;
?>