PHP Smalot PdfParser 获取特定部分

发布于 2025-01-18 10:13:47 字数 253 浏览 0 评论 0原文

我需要有关 PHP Smalot\PdfParser 的帮助。 https://github.com/smalot/pdfparser

有谁知道如何获取或访问某些部分。

例子。发票并希望访问项目/产品对象部分,因为对象/数组

getText 方法有效,但检索发票上的所有文本。

多谢!

I need help about PHP Smalot\PdfParser. https://github.com/smalot/pdfparser

Does anybody know how to get or access certain section.

Example. Invoice and want to get access to items/products object section as Object/Array

getText method works but retrieves all the text on invoice.

Thanks alot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2025-01-25 10:13:47

你可以使用这样的循环:

$metaData = $pdf->getDetails(); //Gets PDF metadata
$xtargetTextCoordinate = "12.345" ///////////USE YOUR OWN
$ytargetTextCoordinate = "678.90" ///////////USE YOUR OWN

//Going through each PDF's page...

for ($x=0 ; $x < $metaData['Pages']; $x++ ){ 
    //Reset variables
    $streamOfThisPage = [];
    $streamOfThisPage = $pdf->getPages()[$x]->getDataTm(); 
    $targetText= "";

    //Going through each key element of this page...
    foreach($streamOfThisPage as $arrayEle){  
        if( ($arrayEle[0][4] == $xtargetTextCoordinate ) && ($arrayEle[0][5] == $ytargetTextCoordinate ) ){  //X & Y depend of your document structure...
          $targetText = "";

          //Remove unecessary data if any
          $thisRowWords = explode(" " , $arrayEle[1] );
          $referencePeriod = $thisRowWords[0];
          foreach($thisRowWords as $position => $word){
              $targetText = $targetText . $word . " ";
          }
    }
 }
 echo $targetText;

You could use some loop like this:

$metaData = $pdf->getDetails(); //Gets PDF metadata
$xtargetTextCoordinate = "12.345" ///////////USE YOUR OWN
$ytargetTextCoordinate = "678.90" ///////////USE YOUR OWN

//Going through each PDF's page...

for ($x=0 ; $x < $metaData['Pages']; $x++ ){ 
    //Reset variables
    $streamOfThisPage = [];
    $streamOfThisPage = $pdf->getPages()[$x]->getDataTm(); 
    $targetText= "";

    //Going through each key element of this page...
    foreach($streamOfThisPage as $arrayEle){  
        if( ($arrayEle[0][4] == $xtargetTextCoordinate ) && ($arrayEle[0][5] == $ytargetTextCoordinate ) ){  //X & Y depend of your document structure...
          $targetText = "";

          //Remove unecessary data if any
          $thisRowWords = explode(" " , $arrayEle[1] );
          $referencePeriod = $thisRowWords[0];
          foreach($thisRowWords as $position => $word){
              $targetText = $targetText . $word . " ";
          }
    }
 }
 echo $targetText;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文