簡體   English   中英

將FPDI合並到現有的TCPDF scipt中,以將exisitng pdf附加到創建的pdf中

[英]incorporating FPDI in to an exisiting TCPDF scipt to append exisitng pdf to the created pdf

我有使用TCPDF創建pdf發票的代碼,它運行良好。 現在,我需要將另一個pdf的內容添加到最后一頁。

我已經找到使用FPDI的服務器示例,但是無法弄清楚如何將其合並到下面的代碼中。

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Harlyn Enterprises');
$pdf->SetTitle('');
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT);
//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
//$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// create first page
$pdf->AddPage();
$html = "html code for page 1 in here";
$pdf->writeHTML($html, true, false, true, false, '');
// create second page
$pdf->AddPage();
$html = "html code for page 2 in here";
$pdf->writeHTML($html, true, false, true, false, '');
$pdf[$site]->lastPage();
//Close and output PDF document
ob_clean();
$file = $_SERVER["filename.pdf";
$pdf->Output($file, 'F');

任何幫助將不勝感激。

我已經知道了。 使用composer安裝FPDI-TCPDF並使用以下代碼:

require_once('tcpdf.php');
use setasign\Fpdi;
use setasign\fpdf;
require_once('vendor/setasign/fpdf/fpdf.php');
require_once('vendor/setasign/fpdi/src/autoload.php');
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
//set_time_limit(2);
//date_default_timezone_set('UTC');
//$start = microtime(true);

//$pdf = new Fpdi\TcpdfFpdi();
$pdf = new Fpdi\TcpdfFpdi('p', 'mm', 'A4');

if ($pdf instanceof \TCPDF) {
    $pdf->SetProtection(['print'], '', 'owner');
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
}

// create first page
$pdf->AddPage();
$html = "html code for page 1 in here";
$pdf->writeHTML($html, true, false, true, false, '');
// create second page
$pdf->AddPage();
$html = "html code for page 2 in here";
$pdf->writeHTML($html, true, false, true, false, '');


//Define files to add
$files = [
        'example_006.pdf',
];

// Attach each page of each pdf
foreach ($files as $file) {
    $pageCount = $pdf->setSourceFile($file);

    for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
        $pdf->AddPage();
        $pageId = $pdf->importPage($pageNo, '/MediaBox');
        $s = $pdf->useTemplate($pageId, 10, 10, 200);
    }
}

//Create PDF
$pdf[$site]->lastPage();
$pdf->Output('output.pdf','I');
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM