smalot / smalot/pdfparser

Possible startxrefPreg extension

Open
#756 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Some PDFs in a project could not be read by the parser.

After a closer examination of the binary data, it was noticed that there is often a space before the reference byte.

After a brief search on the Internet, I could not find any information as to whether this space may be included or not. Perhaps someone here who is more familiar with the subject knows more.

By inserting an optional space in the RegEx at this point, the PDF is recognized again.

RegEx would then look like the following:

'/(?<=[\r\n])startxref[\s]*[\r\n]+[\s]*([0-9]+)[\s]*[\r\n]+%%EOF/i'

https://github.com/smalot/pdfparser/blob/f44ada017eac4f607ffeb1caca96a2347d48f38f/src/Smalot/PdfParser/RawData/RawDataParser.php#L884-L891

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 in src/Smalot/PdfParser/RawData/RawDataParser.php around lines 884-891 and inspect the startxref regular expression. Check how the parser handles a space before the reference byte, then verify that PDFs with this spacing are recognized without breaking existing inputs. No specific test file or fixture is mentioned.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.