kartik-v / yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
http://demos.krajee.com/mpdf
Other
161 stars 150 forks source link

Combining/Merging multiple PDF/DOC/DOCX files into one PDF #26

Closed sandy0201 closed 8 years ago

sandy0201 commented 8 years ago

Hi,

Is there a way to combine/merge several PDF/DOC/DOCX files into one PDF file and then render the PDF file for download? Or is there any possible way to integrate mpdf with pdftk?

Thank you. Kind regards.

kartik-v commented 8 years ago

You may want to post this query with the mpdf1 author... not sure if there is a direct way to do this.

StarNeit commented 7 years ago

Hello.

Is there a way to add contents to existing PDF file like mPDF do?

I used this function in mPDF, but I want to know if i can do merge with this yii2-mpdf.

private function merge_PDFs( $files, $path ){

    $pdf = new mPDF('', '', 0, '', 15, 15, 6, 12, 9, 9, 'P');
    $pdf->enableImports = true;
    foreach( $files as $file ){
        $pdf->SetImportUse();

        $pagecount = $pdf->SetSourceFile($file);
        for ($i=1; $i<=($pagecount); $i++) {
            $pdf->AddPage();
            $import_page = $pdf->ImportPage($i);
            $pdf->UseTemplate($import_page);
        }
    }

    $pdf_name = date('Y-m-d_His') . '.pdf';
    $pdf_path = $path . $pdf_name;

    //Make sure path exists
    if (!file_exists($path)) {
        mkdir($path, 0777);
    }

    $pdf->Output($pdf_path, 'F');
    unset($pdf);
    return $pdf_path;

}

Thank you.