通过 PHP 提取 PDF

如何使用 PHP via Java 库从 PDF 中提取文本和图像

使用解析器最受欢迎的动作

如何使用 PHP via Java 库解析 PDF

要提取 PDF 文件,我们将使用 Aspose.PDF for .NET API,这是一款功能丰富、功能强大且易于使用的文档操作 API,适用于 php-java 平台。打开 NuGet 软件包管理器,搜索 Aspose.pdf 并安装。您也可以使用包管理器控制台中的以下命令。

通过 PHP 解析 PDF


你需要 Aspose.PDF 库 才能在你的环境中试用代码。

  1. 使用 Document 实例加载 PDF。
  2. 创建 TextabSorber 对象来提取文本。
  3. 接受所有页面的吸收剂。
  4. 获取提取的文本
  5. 创建写入器并打开文件,向文件写入一行文本

提取 PDF 文件-PHP

此示例代码显示如何提取 PDF 文档

Input file:

File not added

Output format:

PDF

Output file:


    // Create a new Document object from the input PDF file.
    $document = new Document($inputFile);

    // Create a new TextAbsorber object to extract text from the document.
    $textAbsorber = new TextAbsorber();

    // Extract text from the document.
    $textAbsorber->visit($document);

    // Get the extracted text content.
    $content = $textAbsorber->getText();

    // Save the extracted text to the output file.
    file_put_contents($outputFile, $content);

    $document->close();

关于 Aspose.PDF for PHP via Java API

我们的.NET 库可以将任何支持的下载格式的文档合并为任何支持的保存格式。.NET 的 Aspose.PDF 库提供了相当通用的解决方案,可以帮助你解决合并文档的任务。Aspose.PDF 支持最多的流行文档格式,用于加载和保存。请注意以下事实:当前部分仅描述流行的合并。当前页面提供有关将 {{FILETYPE}} 合并到 {{FILERESULT}} 的信息。但是,合并文件有多种组合。有关支持格式的完整列表,请参阅 支持的文件格式 部分。