简体   繁体   English

FPDF表格彼此相邻

[英]FPDF tables next to each other

日历年视图

I'm trying to create a calendar PDF with FPDF like the image above, but my tables are displayed among themselves. 我正在尝试使用FPDF创建日历PDF(如上图所示),但是我的表格却在彼此之间显示。 Here's what I get: 这是我得到的:

在此处输入图片说明

I'm using this script: http://www.fpdf.org/en/script/script50.php which allows me to convert HTML tables to PDF. 我正在使用以下脚本: http : //www.fpdf.org/en/script/script50.php ,该脚本使我可以将HTML表转换为PDF。

I am very grateful if someone has an idea how I can implement this or someone knows another tool for this problem. 如果有人对如何实现此想法有所了解,或者有人知道解决此问题的另一种工具,我将不胜感激。

You can use the setXY function to move your current position on the page everytime you start drawing a table. 每次开始绘制表格时,都可以使用setXY函数在页面上移动当前位置。 After every table row, the current position will go all the way back to the left margin instead of your previous X position, but you can use SetLeftMargin to solve that. 在每个表格行之后,当前位置将一直返回到左边距,而不是您以前的X位置,但是您可以使用SetLeftMargin解决该问题。

The example below uses the script that you linked to. 下面的示例使用您链接到的脚本。 You can tweak the numbers or do some smarter size calculations. 您可以调整数字或进行一些更智能的尺寸计算。 I printed the same table 12 times to keep the example code short. 为了使示例代码简短,我将同一张表打印了12次。

<?php
require('html_table.php');
$pdf = new PDF('L');
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);

$html = '<table border="1">
<tr><td width="100" height="50">cell 1</td><td width="100" height="50">cell 2</td></tr>
<tr><td width="100" height="50">cell 3</td><td width="100" height="50">cell 4</td></tr>
</table>';

// 'origin' is the top left of the January table:
$originX = 10;
$originY = 50;
for ($i = 0; $i < 12; $i++) {
    // Move 70mm to the right after every month:
    $x = $originX + ($i % 4) * 70;
    // Move 60mm down after every 4 months:
    $y = $originY + floor($i / 4) * 60;
    $pdf->SetLeftMargin($x);
    $pdf->SetXY($x, $y);
    $pdf->WriteHTML($html);
}
$pdf->Output();
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM