Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF only being partly read. #474

Closed
bclarkson72 opened this issue Oct 27, 2021 · 7 comments · Fixed by #634
Closed

PDF only being partly read. #474

bclarkson72 opened this issue Oct 27, 2021 · 7 comments · Fixed by #634
Labels
bug fix missing or incomplete functionality For something which is not a bug, but more like an incomplete feature.

Comments

@bclarkson72
Copy link

Have many PDF invoices that are able to be read fine by the library. But the odd one just does not return the full document

Reads Fine.pdf
Bad Read.pdf

I cannot see any difference in the files at all.

@k00ni k00ni added missing or incomplete functionality For something which is not a bug, but more like an incomplete feature. bug labels Oct 27, 2021
@k00ni
Copy link
Collaborator

k00ni commented Oct 27, 2021

Maybe related to #473 and #471.

Was it always this way or did it work in the past?

@bclarkson72
Copy link
Author

TBH only started with these invoice PDFs recently - previous files have been fine but noticed issues when trying to parse these particular client files. Was using an old version but upgraded to recent build and issues the same.

@bclarkson72
Copy link
Author

Found problem - ET present in textCleaned so screwing with preg_match_all:

The following change gets around the problem but don't think it is a suitable fix.

public function getSectionsText(?string $content): array
{
    $sections = [];
    $content = ' '.$content.' ';
    $textCleaned = $this->cleanContent($content, '_');
	$textCleaned = str_replace("PET","TEP",$textCleaned); //Added this as ET was present in other lines so screwed up the preg_match_all
	//echo $textCleaned;
    // Extract text blocks.
    if (preg_match_all('/(\sQ)?\s+BT[\s|\(|\[]+(.*?)\s*ET(\sq)?/s', $textCleaned, $matches, \PREG_OFFSET_CAPTURE)) {

@bclarkson72
Copy link
Author

Output from cleanContent which shows ET :

58.03 288.9 485.01 10.01 re
f
58.03 242.8 485.01 10.01 re
f
58.03 242.8 485.01 10.01 re
f
BT
0 g
0 Tr
/FTxkPETkkj 8 Tf
1 0 0 1 535.55 627.4 Tm
[_________________________________________________________________________]TJ
ET
q
0 38.88 -24 0 42.1 452.40002 cm
/IMcGhHwtqz Do

@bclarkson72
Copy link
Author

This change seems to be the solution as ET should always be followed by newline?

if (preg_match_all('/\s+BT[\s|(|[]+(.?)\sET\n/s', $textCleaned, $matches, PREG_OFFSET_CAPTURE)) {

@k00ni k00ni added the fix label Oct 29, 2021
@k00ni
Copy link
Collaborator

k00ni commented Oct 29, 2021

If you think its a sustainable solution please send us a pull request and we can discuss details there.

@k00ni
Copy link
Collaborator

k00ni commented Jul 12, 2022

@bclarkson72 can you please test if #533 fixes your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix missing or incomplete functionality For something which is not a bug, but more like an incomplete feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants