TCPDF 页面边框?

发布于 2024-10-16 22:16:27 字数 154 浏览 8 评论 0原文

我试图在 TCPDF 中生成的每个页面周围实现简单的 1px 实心红色边框。以前使用其他 PDF 脚本时,我在进行一些粗略计算后被迫绘制一个矩形,获取页面宽度和高度以及 -20px(以允许每边 10px 缩进)。但是我不确定如何使用 TCPDF 获得类似的结果。

有人有经验吗?

I'm trying to achieve simple 1px solid red border around each page generated in TCPDF. Previously using other PDF scripts I was forced to draw a rectangle after doing some rough calculations with getting the page width and height and -20px (to allow for 10px indentation on each side). However I'm unsure how I can achieve a similar result with TCPDF.

Does anyone have any experience?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蓝天白云 2024-10-23 22:16:28

开始吧(这将在当前页面周围画一条 15 点的黑线)

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();

$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));

$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());

Here you go (this will draw a black line of 15 points around the current page)

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();

$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));

$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
唯憾梦倾城 2024-10-23 22:16:28

使用矩形

$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));
$pdf->Rect(0, 0, $pdf->getPageWidth(), $pdf->getPageHeight());

Use Rect:

$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));
$pdf->Rect(0, 0, $pdf->getPageWidth(), $pdf->getPageHeight());
三寸金莲 2024-10-23 22:16:28
$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));
$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
$pdf->SetLineStyle( array( 'width' => 14, 'color' => array(255,255,255)));
$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));
$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
$pdf->SetLineStyle( array( 'width' => 14, 'color' => array(255,255,255)));
$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());
心清如水 2024-10-23 22:16:28

您可以使用 TCPDF Line 函数并在页面的每一侧创建四条线。

You can use the TCPDF Line function and create four lines around each side of the page.

玩世 2024-10-23 22:16:28

尝试这样:

public function Header()
{
    $this->writeHTMLCell($w='', $h='', $x='', $y='', $this->header, $border=0, $ln=0, $fill=0, $reseth=true, $align='L', $autopadding=true);
    
    $this->SetLineStyle( array('width'=>0.40,'color'=> array(0,0,0)));
    
    $this->Line(5,5, $this->getPageWidth()-5,5);
    
    $this->Line($this->getPageWidth()-5,5, $this->getPageWidth()-5, $this->getPageHeight()-5);
    $this->Line(5, $this->getPageHeight()-5, $this->getPageWidth()-5, $this->getPageHeight()-5);
    $this->Line(5,5,5, $this->getPageHeight()-5);
}

Try like this:

public function Header()
{
    $this->writeHTMLCell($w='', $h='', $x='', $y='', $this->header, $border=0, $ln=0, $fill=0, $reseth=true, $align='L', $autopadding=true);
    
    $this->SetLineStyle( array('width'=>0.40,'color'=> array(0,0,0)));
    
    $this->Line(5,5, $this->getPageWidth()-5,5);
    
    $this->Line($this->getPageWidth()-5,5, $this->getPageWidth()-5, $this->getPageHeight()-5);
    $this->Line(5, $this->getPageHeight()-5, $this->getPageWidth()-5, $this->getPageHeight()-5);
    $this->Line(5,5,5, $this->getPageHeight()-5);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文