smalot / smalot/pdfparser

How to get images and text in order as in PDF?

Open
#705 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
PHP
Stars
2.7k
Forks
579
Avg merge
2m
Merged PRs (30d)
1

Description

  • PDFParser Version: 2.9
Description:

I want to extract the PDF then save text to db and image to storage, but the order matters, if i take page 1, when i get an image, i need to get text coming after that.

PDF input

PDF containing some text then images in each pages,

Expected output & actual output

I need to extract the image and text in order as in the PDF
How to do That ?

Code

Code I'm using for extracting the image, but text is not available here

$parser = new Parser();
$pdf = $parser->parseFile(public_path('paper.pdf'));
$objects = $pdf->getObjects();
foreach ($objects as $key => $object) {
      echo '<img src="data:image/jpg;base64,'. base64_encode($object->getContent()) .'" />';
}

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

Start with the Parser, parseFile(), getObjects(), and each object's getContent() call shown in the issue, using paper.pdf as the input. Determine whether the library exposes text and images in document order; done means extracting both while preserving their sequence on each page.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.