can't parse fdpf file from 1.86 version of FPDF and works fine with FPDF 1.81
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
The error we have in our logs comes from when we parse the data of the pages. We are using a PDF generated by the latest version of FPDF, version 1.86. However, the last version where this error did not occur is 1.81. Therefore, we would like to have, if possible, an idea of what could be causing this error:
Undefined array key 0 in /var/www/clients/client1/web10/web/application/library/php/pdfparser-2.5.0/src/Smalot/PdfParser/Page.php on line 284.
Even with version 2.9.0 of your parser, the error persists. Therefore, I am attaching my PHP parsing code below:
private static function getXandYofPDFText(string $stringtosearch, string $pdfLink, int $documentID){
if (!is_string($stringtosearch) || empty($stringtosearch)) {
throw new Exception(ErrorCodesHelper::get("INVALID_PARAMETERS",["stringtosearch"]));
}
if (!is_string($pdfLink) || empty($pdfLink)) {
throw new Exception(ErrorCodesHelper::get("INVALID_PARAMETERS",["pdfLink"]));
}
if (!is_int($documentID)) {
throw new Exception(ErrorCodesHelper::get("INVALID_PARAMETERS",["documentID"]));
}
if ($documentID <= 0) {
throw new Exception(ErrorCodesHelper::get("INVALID_PARAMETERS",["documentID"]));
}
$parser = new \Smalot\PdfParser\Parser();
$globalArray = array();
$pdf = $parser->parseContent( @file_get_contents( $pdfLink ) );
if( $pdf === null )
{
throw new Exception(ErrorCodesHelper::get("DOCUSIGN_API_CALL_ERROR",["Impossible de parser le document suivant : ".$pdfLink]));
}
$compteurpage = 1;
$pages = $pdf->getPages();
if( $pages === null )
{
throw new Exception(ErrorCodesHelper::get("DOCUSIGN_API_CALL_ERROR",["Impossible de parser les pages du document suivant : ".$pdfLink]));
}
foreach( $pages as $pagenumber )
{
// print_r($pagenumber);
/**
* Récupération du texte et des informations associées (ancres, textes, coordonnées du début de la ligne depuis en bas à gauche, etc.)
*/
$dataTm = $pagenumber->getDataTm();
if( $dataTm == null )
{
throw new Exception(ErrorCodesHelper::get("DOCUSIGN_API_CALL_ERROR",["Impossible de parser la data des pages pour le document suivant : ".$pdfLink]));
}
$compteurindex = 0;
foreach( $dataTm as $a )
{
if ( str_contains( $a[ 1 ], $stringtosearch ) )
{
/**
* Je récupère les coordonnées X et Y, le numéro de la page, le numéro d'ordre du signataire et le numéro d'ordre du document.
*/
$line = $dataTm[ (string)$compteurindex ];
$x = (int)$line[ 0 ][ 4 ];
$y = 859 - (int)$line[ 0 ][ 5 ];
$array = [ $x, $y, $compteurpage, $documentID ];
@array_push( $globalArray, $array );
}
$compteurindex++;
}
$compteurpage++;
}
return $globalArray;
}
```
Thank you for providing us with prompt assistance for our production solution.
Best regards,
GLENAT Group
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/Smalot/PdfParser/Page.php line 284 and review how getDataTm() processes page data. Reproduce the report with PDFs generated by FPDF 1.86 and 1.81, then compare the failing page data and confirm the behavior with the parser versions mentioned; done means the reported undefined array key is explained and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100