dongre6227 2019-06-30 08:03
浏览 964

在PHP中拆分PDF文件,读取它并返回结果

Here's how the system should work:

  1. Admin uploads a multi-page PDF file, in which every page contains a unique code for every user.
  2. The system should split the file into separate pages.
  3. User logs in. The system gets his ID as a variable (the unique code which exists in PDF file).
  4. The system shows every user only those pages which contain their ID.

I'm not asking for any code, just the name of some PDF libraries which can do the exact thing I'm looking for :)

Thanks in advance.

  • 写回答

1条回答

  • dpiz9879 2019-06-30 20:22
    关注

    You may try this function to split all of the pages from a larger PDF file into single-page PDF files.

    Installation

    composer require setasign/fpdi-fpdf
    

    Code

    use setasign\Fpdi\Fpdi;
    
    /**
     * Split all of the pages from a larger PDF file into single-page PDF files.
     *
     * @param string $filename The filename of the PDF to split
     * @param string $directory The output directory for the new PDF files
     *
     * @return void
     */
    function split_pdf(string $filename, string $directory)
    {
        $pdf = new Fpdi();
        $pageCount = $pdf->setSourceFile($filename);
        $file = pathinfo($filename, PATHINFO_FILENAME);
    
        // Split each page into a new PDF
        for ($i = 1; $i <= $pageCount; $i++) {
            $newPdf = new Fpdi();
            $newPdf->addPage();
            $newPdf->setSourceFile($filename);
            $newPdf->useTemplate($newPdf->importPage($i));
    
            $newFilename = sprintf('%s/%s_%s.pdf', $directory, $file, $i);
            $newPdf->output($newFilename, 'F');
        }
    }
    

    Usage

    split_pdf('test.pdf', 'split/');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题