将多个PDF文件合并成一个PHP文件 [英] Merge multiple PDF files into one in PHP

查看:1932
本文介绍了将多个PDF文件合并成一个PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想合并多个PDF档案到一个。 PDF文件在不同的网站上,因此应首先下载并合并为一个。

I would like to merge multiple PDF files to one. The PDF files are on different sites so they should first be downloaded and merged to one.

我们使用PHP和Codeigniter。有人知道我的问题的解决方案吗?

We work with PHP and Codeigniter. Does somebody know an solution for my problem?

推荐答案

是的。我已经合并pdf的。
获取 fpdf fpdi 库,并将它们放入代码igniter第三方文件夹。
那么它只是一个阅读fpdfi的手册并合并文档的问题。
使用它来设置库

yes. i have merged pdf's. Get the fpdf and fpdi libraries and put them in to the code igniter third party folder. then it is just a matter of reading the manual for fpdfi and merging the documents. use this to set up the libraries

 require_once("application/third_party/fpdf/fpdf.php");//http://www.fpdf.org/
 require_once("application/third_party/fpdi/FPDI_Protection.php");//http://www.setasign.de/products/pdf-php-solutions/fpdi/

,那么这段代码应该能够让你了解它的工作原理。注意我已经编辑了这一部分为了清楚。此示例流PDF文件。您可以轻松地将文件保存到其他位置。

then this snippet of code should give you an idea of how it works. note i have edited sections of this for clarity. this example streams the pdf file. you could just as easily save the file elsewhere.

    $files = array(<file full paths here>);

$pdf = new FPDI_Protection();
if ($data->password)
{
    $pdf->setProtection(array(),$data->password);
}
for ($i = 0; $i < count($files); $i++ )
{
    $pagecount = $pdf->setSourceFile($files[$i]);
    for($j = 0; $j < $pagecount ; $j++)
    {
        $tplidx = $pdf->importPage(($j +1), '/MediaBox'); // template index.
        $pdf->addPage('L','A4');// orientation can be P|L
        $pdf->useTemplate($tplidx, 0, 0, 0, 0, TRUE);                   
    }
    unlink($files[$i]); // you may not want to unlink the files!
}

$dt = new DateTime(NULL, new DateTimeZone($data->user->timezone));
    // set the metadata.
$pdf->SetAuthor($data->user->user_name);
$pdf->SetCreator('website name!');
$pdf->SetTitle('PDF, created: '.$dt->format(MYHMRS_DATETIME_FRIENDLY));
$pdf->SetSubject('PDF subject !');
$pdf->SetKeywords('website name!'.", keywords! ".$data->user->user_name);
$output = $pdf->Output('', 'S');
$name = "PDF".'-'.$dt->format('ymd').'.pdf';

$this->output
    ->set_header("Content-Disposition: filename=$name;")
    ->set_content_type('Application/pdf')
    ->set_output($output);

,以获取其他网站的pdf文件,首先确保您可以这样做,使用cURL的问题。 (复制URL)。有一个代码信息库可以执行此操作,也可以使用 PHP库

as for getting pdfs from other sites, firstly make sure you are allowed to do this, then it is matter of using cURL. (copy URL). there is a codeigniter library to do this, or you can use the PHP library.

这篇关于将多个PDF文件合并成一个PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆