smalot / smalot/pdfparser

Your online demo behave different than library on the same file

Open
#235 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug missing or incomplete functionality needs more info
Dominant language
PHP
Stars
2.7k
Forks
579
Avg merge
2m
Merged PRs (30d)
1

Description

I tried to upload a PDF of a customer order where each row details is complex because some data are on multiple text rows, and each row has a lot of columns with different details.

Your online demo is great. Every order row is parsed one column at once, so inside each 'cell' of text, all words are keep together even if spanned on multiple text rows. Great, really !

I am using your library on php 7.2 in this way

public function filePdfUploaded(Request $request)
    {
        $pdf_file           = $request->file('pdf'); 
        $original_file_name = $pdf_file->getClientOriginalName();
        $pdf_path           = storage_path('app/').  $pdf_file->storeAs('pdf', $original_file_name);

        $parser = new \Smalot\PdfParser\Parser();
        $pdf    = $parser->parseFile($pdf_path);
        
        $pages  = $pdf->getPages();
        // Loop over each page to extract text.
        foreach ($pages as $page) {
            echo "<HR /><PRE>" . $page->getText() . "</PRE>";
        }
        
    }

But the result is that it outputs the parsed text one entire column at time, so Insetead of

order number - quantity - detail --
order number - quantity - detail --
order number - quantity - detail --
order number - quantity - detail --

I got

order number
order number
order number
order number
quantity
quantity
quantity
quantity
detail
detail
detail
detail

Is there any options to set to have parsed text ordered as in your online demo?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the discrepancy from the shown Parser()->parseFile() and page->getText() entry points using the referenced order PDF, comparing library output with the online demo. Trace how page text is ordered and determine whether an option can produce row-wise ordering; done means matching demo output or documenting that the behavior is unsupported.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.