使用PHP按某些关键字解析PDF文件并将其拆分为多个PDF文件
我希望能够使用 PHP 和 symfony 4 框架使用某些关键字解析 PDF 文件,并根据搜索的关键字将其拆分为多个 PDF 文件。
我做了一些研究,发现很多使用 PHP 解析 PDF 文件的方法,但解析和分割 PDF 文件的方法很少。
我可以访问哪些网站?我可以使用的库吗?
这是我用来从 pdf 文件中提取整个文本的代码。但我的目的是从pdf中提取特定段落,例如我想提取从“hello”一词开始到“world”一词的段落。
public function extract(): Response {
$parser = new \Smalot\PdfParser\Parser();
$CV = $parser->parseFile('C:\Users\lenovo\Desktop\papiers\CV\CVmolkahchaichi.pdf');
// Retrieve all pages from the pdf file.
$details = $CV->getDetails();
$pages = $CV->getPages();
// Loop over each page to extract text.
foreach ($pages as $page) {
echo $page->getText();
foreach ($details as $property => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
echo $property . ' => ' . $value . "<br/>";
}
return new Response();
}
I'd like to be able to parse a PDF file using PHP and symfony 4 framework using certain keywords and split it into multiple PDF files at the keywords searched for.
I did some research and I found a lot of ways to parse PDF files using PHP but very few to parse and split the PDF file.
any web-sites I could go to? libraries I could use?
this is the code I used to extract the whole text from a pdf file. But my purpose is to extract specific paragraphes from the pdf, for example I want to extract the paragraph that starts from the word 'hello' to the word 'world'.
public function extract(): Response {
$parser = new \Smalot\PdfParser\Parser();
$CV = $parser->parseFile('C:\Users\lenovo\Desktop\papiers\CV\CVmolkahchaichi.pdf');
// Retrieve all pages from the pdf file.
$details = $CV->getDetails();
$pages = $CV->getPages();
// Loop over each page to extract text.
foreach ($pages as $page) {
echo $page->getText();
foreach ($details as $property => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
echo $property . ' => ' . $value . "<br/>";
}
return new Response();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论