在 PHP 中获取 PDF 文件的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36809580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:56:55  来源:igfitidea点击:

Get content of PDF file in PHP

phpparsingpdf

提问by Berk Kaya

I have a FlipBook jquery page and too many ebooks(pdf format) to display on it. I need to keep these PDF's hidden so that I would like to get its content with PHP and display it with my FlipBook jquery page. (instead of giving whole pdf I would like to give it as parts).

我有一个动画书 jquery 页面和太多的电子书(pdf 格式),无法在上面显示。我需要隐藏这些 PDF,以便我想用 PHP 获取它的内容并用我的 FlipBook jquery 页面显示它。(而不是提供整个pdf,我想将其作为部分提供)。

Is there any way i can get whole content of PDF file with PHP? I need to seperate them according to their pages.

有什么办法可以用 PHP 获取 PDF 文件的全部内容?我需要根据他们的页面将它们分开。

回答by Umair Shah Yousafzai

You can use PDF Parser (PHP PDF Library) to extract each and everything from PDF's.

您可以使用 PDF Parser(PHP PDF 库)从 PDF 中提取所有内容。

PDF Parser Library Link: http://www.pdfparser.org/

PDF 解析器库链接http: //www.pdfparser.org/

Online Demo Link:http://www.pdfparser.org/demo

在线演示链接:http : //www.pdfparser.org/demo

Documentation Link:http://www.pdfparser.org/documentation

文档链接:http : //www.pdfparser.org/documentation

Sample Code:

示例代码:

<?php

// Include Composer autoloader if not already done.
include 'vendor/autoload.php';

// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
$pdf    = $parser->parseFile('document.pdf');

$text = $pdf->getText();
echo $text;

?>

Regarding another part of your Question:

关于你问题的另一部分:

How To Convert Your PDF Pages Into Images:

如何将您的 PDF 页面转换为图像:

You need ImageMagickand GhostScript

你需要ImageMagickGhostScript

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
?>

The [0]means page 1.

[0]手段page 1