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

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?