little details of fpdf library

so i have generated the pdf file using php and fpdf but i face some problems which am not able to fix the, first of all the checkbox always doesnt fit the line, and second i can not find a way to make table responsive according to the inserted data, here am gonna share the code and screen of the pdf file

pdf file image

here is what i have tried so far

<?php
require('api/fpdf186/fpdf.php');

class PDF extends FPDF
{
    // Header function
    function Header()
    {
        $this->SetFillColor(173, 216, 230); // Light blue
        $this->Rect(10, 10, 190, 20, 'F');
        $this->SetFont('Arial', 'B', 16);
        $this->Cell(0, 10, 'Medical Report', 0, 1, 'C');
        $this->SetFont('Arial', 'I', 10);
        $this->Cell(0, 5, 'Patient Details and Doctor Summary', 0, 1, 'C');
        $this->Ln(10); // Gap after header
    }

    // Section Header with gap below
    function SectionHeader($title)
    {
        $this->Ln(5); // Gap after section header
        $this->SetFont('Arial', 'B', 12);
        $this->SetFillColor(230, 230, 230); // Light gray background
        $this->Cell(190, 8, $title, 0, 1, 'L', true);
        $this->Ln(5); // Gap after section header
    }

    // Form Field (label + underline for data)
    function FormField($label, $width)
    {
        $this->SetFont('Arial', '', 11);
        $this->Cell($width, 8, $label, 0, 0, 'L'); // Label
        $this->Cell(190 - $width, 8, '', 'B'); // Underline for data
        $this->Ln(8); // Line break after each field
    }

    // Checkbox function to draw checkboxes
    function DrawCheckbox($label, $x, $y, $checked = false)
    {
        // Draw the checkbox (a square)
        $this->Rect($x, $y, 5, 5); // Draw the square

        // Mark it as checked or not
        if ($checked) {
            $this->SetXY($x + 1, $y);
            $this->Cell(5, 5, 'X', 0, 0, 'C');
        }

        // Label next to the checkbox
        $this->SetXY($x + 8, $y);
        $this->Cell(10, 5, $label, 0, 1, 'L');
    }

    // Diagnosis Table Header (responsive width)
    function DiagnosisTableHeader($widths)
    {
        $this->SetFont('Arial', 'B', 11);
        $this->SetFillColor(200, 200, 200); // Light gray background
        $this->Cell($widths[0], 8, 'Diagnosis', 1, 0, 'C', true); 
        $this->Cell($widths[1], 8, 'Result', 1, 0, 'C', true);
        $this->Ln();
    }

    // Diagnosis Table Row (responsive width)
    function DiagnosisTableRow($diagnosis, $result, $widths)
    {
        $this->SetFont('Arial', '', 11);
        $this->Cell($widths[0], 8, $diagnosis, 1);
        $this->Cell($widths[1], 8, $result, 1);
        $this->Ln();
    }

    // Prescription Table Header (responsive width)
    function PrescriptionTableHeader($widths)
    {
        $this->SetFont('Arial', 'B', 11);
        $this->SetFillColor(200, 200, 200); // Light gray background
        $this->Cell($widths[0], 8, 'Medicine Name', 1, 0, 'C', true); 
        $this->Cell($widths[1], 8, 'Dosage', 1, 0, 'C', true);
        $this->Cell($widths[2], 8, 'Explanation', 1, 0, 'C', true);
        $this->Cell($widths[3], 8, 'Availability', 1, 0, 'C', true);
        $this->Ln();
    }

    // Prescription Table Row (responsive width)
    function PrescriptionTableRow($medicine, $dosage, $explanation, $availability, $widths)
    {
        $this->SetFont('Arial', '', 11);
        $this->Cell($widths[0], 8, $medicine, 1);
        $this->Cell($widths[1], 8, $dosage, 1);
        $this->Cell($widths[2], 8, $explanation, 1);
        $this->Cell($widths[3], 8, $availability ? '[x]' : '[ ]', 1, 0, 'C');
        $this->Ln();
    }

    // Calculate maximum widths based on content
    function CalculateMaxWidths($data, $defaultWidths)
    {
        $widths = $defaultWidths;
        foreach ($data as $row) {
            foreach ($row as $key => $value) {
                $textWidth = $this->GetStringWidth($value) + 4; // Extra padding
                if ($textWidth > $widths[$key]) {
                    $widths[$key] = $textWidth;
                }
            }
        }
        return $widths;
    }

    // MultiCell wrapper to handle long text
    function MultiCellWrapped($width, $height, $text)
    {
        $this->MultiCell($width, $height, $text, 1);
    }
}

// Create PDF instance
$pdf = new PDF();
$pdf->AddPage();

// Part A: Patient's Information Section
$pdf->SectionHeader('Patient Information');

// Title field with checkboxes
$pdf->Cell(30, 8, 'Title:', 0, 0, 'L');
$pdf->DrawCheckbox('Mr', 45, $pdf->GetY(), true); // Checked by default
$pdf->DrawCheckbox('Mrs', 65, $pdf->GetY(), false);
$pdf->Ln(8); // Line break after checkboxes

// Full Name
$pdf->FormField('Full Name', 40);

// Birth Date
$pdf->FormField('Birth Date', 40);

// Address
$pdf->FormField('Address', 40);

// Diagnosis Table Data
$diagnosisData = [
    ['Fracture', 'Positive'],
    ['Concussion', 'Negative'],
    ['Bruising Bruising Bruising Bruising Bruising Bruising Bruising Bruising', 'Severe bruising around the leg area due to the impact of the accident Severe bruising around the leg area due to the impact of the accident Severe bruising around the leg area due to the impact of the accident Severe bruising around the leg area due to the impact of the accident']
];

// Calculate responsive widths for Diagnosis table
$defaultWidthsDiagnosis = [70, 120]; // Default width proportions
$diagnosisWidths = $pdf->CalculateMaxWidths($diagnosisData, $defaultWidthsDiagnosis);

// Diagnosis Table
$pdf->SectionHeader('Diagnosis');
$pdf->DiagnosisTableHeader($diagnosisWidths);
foreach ($diagnosisData as $row) {
    $pdf->DiagnosisTableRow($row[0], $row[1], $diagnosisWidths);
}

// Prescription Table Data
$prescriptionData = [
    ['Ibuprofen', '200mg', 'Take twice a day', true],
    ['Amoxicillin', '500mg', 'Take three times a day', false],
    ['Paracetamol', '500mg', 'Take as needed for pain', true]
];

// Calculate responsive widths for Prescription table
$defaultWidthsPrescription = [60, 40, 50, 30]; // Default width proportions
$prescriptionWidths = $pdf->CalculateMaxWidths($prescriptionData, $defaultWidthsPrescription);

// Prescription Table
$pdf->SectionHeader('Prescriptions');
$pdf->PrescriptionTableHeader($prescriptionWidths);
foreach ($prescriptionData as $row) {
    $pdf->PrescriptionTableRow($row[0], $row[1], $row[2], $row[3], $prescriptionWidths);
}

// Doctor's Explanation
$pdf->SectionHeader('Doctor's Explanation');
$pdf->MultiCellWrapped(190, 10, 'The patient has sustained multiple injuries from the accident. Treatment will continue for a period of six weeks and further diagnostics may be required to ensure a complete recovery.');

// Output the PDF
$pdf->Output();
?>

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật