1.使用composer引入第三方类库
composer require smalot/pdfparser
2.目录结构
pdfparser
-vendor
-Index.php
-index.html
3.php中引入自动加载
<?php
require 'vendor/autoload.php';
/**
*
*/
class Index
{
public function demo()
{
//实例化类库
$parser = new \Smalot\PdfParser\Parser();
if ($_FILES['file']) {
$document = $parser->parseFile($_FILES['file']['tmp_name']);
$pages = $document->getPages();
foreach ($pages as $key => $value) {
echo $value->getText() . "<br>";
}
}
}
}
$index = new Index();
$index->demo();
4.html上传文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>解析pdf</title>
<link rel="stylesheet" href="">
</head>
<body>
<form action="index.php/demo" method="post" enctype="multipart/form-data" >
<input type="file" id="edit-file" name="file" size="60" class="form-file">
<button type="submit">提交</button>
</form>
</body>
</html>
5.效果
pdf原文件内容
解析后效果,图片没有解析出来