smalot / smalot/pdfparser

Rect value for some PDF form fields doesn't contain floating point numbers but rather strings like #Obj#32_0

Open
#738 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  • PHP Version: 8.1.2-1ubuntu2.18
  • PDFParser Version: 2.11.0
Description:

The attached PDF contains 3x form fields. The Rect key for one of those form fields contains 4x floating point numbers, presumably representing the coordinates of that form field on the PDF, however, the other two form fields contain strings - #Obj#32_0 - #Obj#35_0. idk what these strings means and if there's a way to get coordinates from those strings it's unclear to me what that method might be.

PDF input

test.pdf

Expected output
Array
(
    [P] => Array
        (
            [Type] => Page
            [Rotate] => 0
        )

    [T] => incomeName1
    [Rect] => Array
        (
            [0] => 205.35
            [1] => 717.601
            [2] => 540.298
            [3] => 740.74
        )

    [F] => 4
    [Type] => Annot
    [Subtype] => Widget
    [DA] => /Helv 12 Tf 0 g
    [MK] => Array
        (
        )

    [FT] => Tx
)
Actual output
Array
(
    [P] => Array
        (
            [Type] => Page
            [Rotate] => 0
        )

    [T] => PatientsIncomeSS
    [Rect] => Array
        (
            [0] => #Obj#32_0
            [1] => #Obj#33_0
            [2] => #Obj#34_0
            [3] => #Obj#35_0
        )

    [F] => 4
    [Type] => Annot
    [Subtype] => Widget
    [DA] => /Helv 12 Tf 0 g
    [MK] => Array
        (
        )

    [FT] => Tx
)
Code
<?php
include('vendor/autoload.php');

$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('test.pdf');

$objects = $pdf->getObjects();
foreach ($objects as $obj) {
    print_r($obj->getDetails());
}

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 issue with the linked test.pdf and the shown Parser, parseFile(), getObjects(), and getDetails() calls. Trace how the affected form fields' Rect values are represented and compare them with the field that already contains floating-point coordinates. Done means the reported fields expose usable coordinate values or the limitation is clearly documented.

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.