Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php FPDF和x2B;关联数组键值列_Php_Arrays_Pdf_Fpdf - Fatal编程技术网

Php FPDF和x2B;关联数组键值列

Php FPDF和x2B;关联数组键值列,php,arrays,pdf,fpdf,Php,Arrays,Pdf,Fpdf,我正在尝试使用创建一个PDF。我有这样一个数组: array (size=27) 'JobTitle' => string 'test-job' (length=8) 'lastName' => string 'zaezaeza' (length=8) 'firstName' => string 'zaezaeaz' (length=8) 'street' => string 'azezaeza' (length=8) 'streetNr' => string '5

我正在尝试使用创建一个PDF。我有这样一个数组:

array (size=27)
'JobTitle' => string 'test-job' (length=8)
'lastName' => string 'zaezaeza' (length=8)
'firstName' => string 'zaezaeaz' (length=8)
'street' => string 'azezaeza' (length=8)
'streetNr' => string '54' (length=2)
'place' => string 'zaezaeza' (length=8)
'postalCode' => string '9870' (length=4)
'country' => string 'zeazeza' (length=7)
'mobile' => string '056154871' (length=9)
'email' => string 'aez@dqd.com' (length=11)
'placeOfBirth' => string 'azzazae' (length=7)
'nationality' => string 'zaezzae' (length=7)
'driversLicence' => string 'yes' (length=3)
'driversLicenceCategory' => string 'b' (length=1)
'ownCar' => string 'yes' (length=3)
'celibate' => string 'celibate' (length=8)
'LowerSecondaryStudies' => string 'degreeTitle: zaeaz
                                   educationAuthority: zaezaezaeza
                                   graduationYear: 2014' (length=75)
'dutch' => string 'No selections' (length=13)
'french' => string '' (length=0)
'english' => string '' (length=0)
'german' => string '' (length=0)
'computerKnowledge' => string 'zaezaza' (length=7)
'interestsCareer' => string 'azezaeza' (length=8)
'strongPoints' => string 'zaeazeza' (length=8)
'contact' => string 'employees: true
                     employeesWho: zaezaeza' (length=41)
'worklocation' => string 'merelbeke: true' (length=17)
'motivationSolicitation' => string 'zaezaezaeza' (length=11)
现在,我想在我的pdf中输出以下内容:


但我真的被困在如何创建这个表。我已经阅读了fpdf的教程,但并没有从中得到任何启示。有人能帮我吗?

要用这个库创建表,您可以这样做

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

class PDF extends FPDF
{
// Load data
function LoadData($file)
{
    // Read file lines
    $lines = file($file);
    $data = array();
    foreach($lines as $line)
        $data[] = explode(';',trim($line));
    return $data;
}

// Simple table
function BasicTable($header, $data)
{
    // Header
    foreach($header as $col)
        $this->Cell(40,7,$col,1);
    $this->Ln();
    // Data
    foreach($data as $row)
    {
        foreach($row as $col)
            $this->Cell(40,6,$col,1);
        $this->Ln();
    }
}

// Better table
function ImprovedTable($header, $data)
{
    // Column widths
    $w = array(40, 35, 40, 45);
    // Header
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C');
    $this->Ln();
    // Data
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR');
        $this->Cell($w[1],6,$row[1],'LR');
        $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
        $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
        $this->Ln();
    }
    // Closing line
    $this->Cell(array_sum($w),0,'','T');
}

// Colored table
function FancyTable($header, $data)
{
    // Colors, line width and bold font
    $this->SetFillColor(255,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
    // Header
    $w = array(40, 35, 40, 45);
    for($i=0;$i<count($header);$i++)
        $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
    $this->Ln();
    // Color and font restoration
    $this->SetFillColor(224,235,255);
    $this->SetTextColor(0);
    $this->SetFont('');
    // Data
    $fill = false;
    foreach($data as $row)
    {
        $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
        $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
        $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
        $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
        $this->Ln();
        $fill = !$fill;
    }
    // Closing line
    $this->Cell(array_sum($w),0,'','T');
}
}

$pdf = new PDF();
// Column headings
$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. (thousands)');
// Data loading
$data = $pdf->LoadData('countries.txt');
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable($header,$data);
$pdf->AddPage();
$pdf->ImprovedTable($header,$data);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?>



谢谢,您现在知道如何更改行单元格中的填充吗?也许在函数“行”中,您需要相应地设置x和y的位置。我会检查它
<?php
require('mc_table.php');

$pdf=new PDF_MC_Table();
$pdf->AddPage();
$pdf->SetFont('Arial','',14);
//Table with 27 rows and 2 columns since you have 27 values 
$pdf->SetWidths(array(30,60));

$pdf->Row(array('Key','Value'));
$pdf->Row(array('JobTitle','test-job'));
$pdf->Row(array()); //Do the same thing as above
.
.
.
.
//Do it for 27 times since you have 27 values
//Or store them in array and use a loop
$pdf->Output();
?>