duangu4980
2018-10-11 18:09
浏览 85
已采纳

PHP - 检查pdf是否包含给定文本 - TcpdfFpdi / pdftk / fpdi

I have a pdf document and I want to check if a specific text occurs (which are tags that I put in while generating the pdf) in the document, however using these libraries (tcpdfFpdi, pdftk or fdpi) I couldn't figure out if it's possible or how to do it.

$str = "{hello}";

$pdf = new TcpdfFpdi();
$pdf->setSourceFile($filePath);

$pdf->searchForText($str); // something like this which returns boolean

If I try without any library to dd(file_get_contents($filePath)), it returns a very long output and doesn't seem to contain the file I want so I think it's better to use one of those libraries.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duancaozen6066 2018-10-11 18:21
    已采纳

    Just an idea…

    It's no actual PHP solution but you could use tools like pdftotext which I know from this post (where a PDF file is converted into a string to count its words): https://superuser.com/a/221367/535203

    You can install it and play around with that command and call it from within your PHP application.

    As far as I remember (long time ago since I used pdftotext) the output text is not exaclty the PDF's content but to search a few tags in it it's at least a good try.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题