PHP PDF解析器读取的内容显示为两行,需要修复它

7z5jn7bk  于 2023-02-15  发布在  PHP
关注(0)|答案(1)|浏览(173)

我用pdfparser来读取PDF内容。但一个地址行显示为两行。在这段时间里,它显示为两个新行。我想得到完整的地址作为一行。PDF文件是动态的。根据地址长度,它显示为多行。
我需要适当的解决方案来阅读的内容作为一行。我会附上PDF地址行在这里供参考。

我想你能理解我的要求。

我的pdf阅读代码是

$fileName = basename($_FILES["file"]["name"]); 
$fileType = pathinfo($fileName, PATHINFO_EXTENSION); 

// Allow certain file formats 
$allowTypes = array('pdf'); 
if(in_array($fileType, $allowTypes)){ 
   // Include autoloader file 
   include 'vendor/autoload.php';
             
   // Initialize and load PDF Parser library 
   $parser = new \Smalot\PdfParser\Parser(); 
             
   // Source PDF file to extract text 
   $file = $_FILES["file"]["tmp_name"]; 
             
   // Parse pdf file using Parser library 
   $pdf = $parser->parseFile($file); 
             
   // Extract text from PDF 
   $text = $pdf->getText(); 
             
   // Add line break 
   $pdfText = nl2br($text);
}else{ 
  $statusMsg = '<p>Sorry, only PDF file is allowed to upload.</p>'; 
}

阅读pdf内容后,显示如下

我怎样才能把相关的内容作为一行

oprakyz7

oprakyz71#

$pdf文本= nl 2br($文本);将此行替换为$pdftext = str_replace(“\t”,“在此插入br标记”,$text);

相关问题