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

以下是系统的工作方式:</ p>


  1. 管理员 上传一个多页PDF文件,其中每个页面都包含每个用户的
    unique代码。</ li>
  2. 系统应将文件拆分为单独的页面。</ li>
  3. 用户 登录。系统将其ID作为变量(PDF文件中存在的唯一代码)。</ li>
  4. 系统仅向每个用户显示包含其ID的页面。</ li>
    </ ol>

    我不是要求任何代码,只是一些PDF库的名称可以完成我正在寻找的东西:)</ p>

    提前致谢。</ p>
    </ div>

展开原文

原文

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.

doqau82086
doqau82086 请看一下主题,特别是标有4的段落。
大约一年之前 回复

1个回答

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/');
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐