微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何通过FPDI将外部pdf文件作为附加页面添加到TCPF

如何解决如何通过FPDI将外部pdf文件作为附加页面添加到TCPF

我正在使用TCPDF从PHP文件创建PDF文件。一切正常。现在,我想使用服务器上现有的.pdf文件添加其他页面

最好的方法是使用FPDI afaik。

但是我找不到任何有关如何在TCPDF中设置FPDI来添加页面的文档或工作示例。我所看到的就是我如何使用外部pdf作为标题或背景等。

喜欢这个 https://www.setasign.com/products/fpdi/about/

我在TCPDF中拥有什么

use setasign\Fpdi\Tcpdf\Fpdi;

// require_once('tcpdf/config/lang/eng.PHP');
require_once('TCPDF-main/tcpdf.PHP');
require_once('FPDI/src/autoload.PHP');

// Extend the TCPDF class to create custom Footer
class MYPDF extends TCPDF {

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica','I',8);
        // Page number
        $this->Cell(0,10,'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(),false,'C','','T','M');
    }
}

// add external PDF with FPDI (not working)

$pdf = new MYPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',true);

$pageCount = $pdf->setSourceFile("hiking.pdf");
$tplIdx = $pdf->importPage(1,'/flyer');

$pdf->addPage();
$pdf->useTemplate($tplIdx,90);

$pdf->Output();


// create new PDF document with TCPDF (working)

$pdf = new MYPDF(PDF_PAGE_ORIENTATION,true);

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(true);

$pdf->AddPage();
ob_start(); //Start new output buffer

//Write page 1
$html = include('mytour.PHP');

$html = ob_get_contents();

$pdf->writeHTML($html,0);

// reset pointer to the last page
$pdf->lastPage();
ob_end_clean();

// ---------------------------------------------------------

$cdate = date("y-d-m");
$ctime = date("H-i-s");

//Close and output PDF document
$output1 = "mytour.pdf";
$pdf->Output($output1,'I');

我收到的错误 PHP致命错误:未捕获错误调用未定义方法MYPDF :: setSourceFile()

赞赏有关操作方法的任何提示

解决方法

只需按照here中所述扩展正确的类:

import pandas as pd

def weekinmonth(dates):
    """Get week number in a month.
    
    Parameters: 
        dates (pd.Series): Series of dates.
    Returns: 
        pd.Series: Week number in a month.
    """
    firstday_in_month = dates - pd.to_timedelta(dates.dt.day - 1,unit='d')
    return (dates.dt.day-1 + firstday_in_month.dt.weekday) // 7 + 1
    

df = pd.DataFrame(pd.date_range(' 1/ 1/ 2000',periods = 100,freq ='D'),columns=['Date'])
weekinmonth(df['Date'])

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。