【问题标题】:TCPDF Remove white space / bottom marginTCPDF 删除空白/底部边距
【发布时间】:2017-08-02 12:35:57
【问题描述】:

我已经阅读了大约 5 篇关于此的帖子,并毫无乐趣地尝试了代码修复,所以我发布了我自己的,希望这不会冒犯。

我正在尝试制作一个有 2 列的页面,并且正在使用 MultiCell() - 我对此很满意,并成功地删除了顶部/左右两侧的边距。

从图片中可以看出,页面底部有一个空间,它将文本框的底部推到下一页。

谁能帮帮我,我已经尝试了几个小时了!这是我的代码:

// create new PDF document
$pageLayout = array( 139 , 76 );
$pdf = new TCPDF('l', 'mm', $pageLayout, true, 'UTF-8', false, true);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('Online Ticket Seller Ticket');
$pdf->setPrintFooter(false);
$pdf->setPrintHeader(false);
$pdf->SetMargins(PDF_MARGIN_LEFT-15, PDF_MARGIN_TOP-29, PDF_MARGIN_RIGHT-16);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->SetFont('helvetica', '', 10, '', true);
// add a page
$pdf->AddPage();
$pdf->SetFillColor(255, 255, 255);

$pdf->setCellPaddings(1, 1, 1, 1);
$pdf->setCellMargins(0, 0, 0, 0);

// set some text for example
$txt1 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, 

sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 
incididunt ut labore et dolore magna aliqua.';
$txt2 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';

// Multicell test
$pdf->MultiCell(38, 75, '[LEFT] '.$txt1, 1, 'L', 0, 0, '', '', true);
$pdf->MultiCell(101, 75, '[RIGHT] '.$txt2, 1, 'L', 0, 0, '', '', true);

//Close and output PDF document
$pdf->Output('example_005.pdf', 'I');

非常感谢。

我读过的页面(没有解决我的问题):

【问题讨论】:

  • 我已将您的链接添加到您的问题中。干杯。

标签: php margin tcpdf


【解决方案1】:

注意:

以下答案太大而不能成为评论,但不足以成为真正的答案,它更适合查询问题中给出的一些信息。

另请注意(来自我的评论)

您能否向我们展示您已经阅读和尝试过哪些问题以及哪些问题没有解决您的问题,否则我们只会将您链接/建议您已经尝试过但失败的问题。干杯


你的问题是Here's my code

$pdf->SetMargins(PDF_MARGIN_LEFT-15, PDF_MARGIN_TOP-29, PDF_MARGIN_RIGHT-16);

这是非常错误的,你想这样设置值:

$pdf->SetMargins(15, 29, 16);

在语法上更正确。

您还可以尝试使用 the documentation 中的值 $keepmargins

参数
$left (float) 左边距。
$top (float) 上边距。
$right (float) 右边距。默认值为左侧。
$keepmargins (boolean) 如果 true 覆盖默认页边距

所以:

 $pdf->SetMargins(15, 29, 16,true);

【讨论】:

  • 谢谢@martin,我已按照您的建议调整了页边距,并在上面的评论中添加了指向我已阅读的页面的链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-18
  • 2013-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-18
相关资源
最近更新 更多