Pdf Tm command sometimes mis interpetted
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Hiya,
First of all thanks for the amazing work you have done so far... I dug in to the source and quickly it became clear that this is indeed allot of work... (Also when I look up the PDF reference, damn... thats allot of reading).
However the current problem. Sometimes in my PDF this comes along:
[(%)-3(DW_)-3(S)4(TA)] TJ
[65] => /F1 9 Tf
1 0 0 1 105.74 495.07 Tm
1 g
1 G
-0.027 Tc[(MP%)] TJ
[66] => /F1 9 Tf
1 0 0 1 128.42 495.07 Tm
0 g
0 G
The text of both Tj objects are on the same line and right begin each other (in a PDF viewer you would see %DW_STAMP%). However as it is converted from MS Office to PDF we all know MS sometimes doesn't do everything quite nice....
In above example the last part of "%DW_STAMP%" ("MP%") is located in a own Tj object. How it comes there.. I have no idea... but then again I think it is because there is another letter spacing involved in the second Tj.
The code checks up on the "Tm" object to see if a Tab is needed:
(PDFObject.php)
if ($current_position_tm['x'] !== false) {
$delta = abs(floatval($x) - floatval($current_position_tm['x']));
if ($delta > 10) {
$text .= "\t";
}
}
This is where it goes wrong cause the script presumes a tab because the Tm X coordinates are way above 10, but that is because there is text in front of it and not a tab.
Because of that the output result of the text is currently "%DW_STA\tMP%". If i comment out the $text .= "\t"; everything works fine for me :-) although myself cannot figure out a solution for this...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in PDFObject.php at the shown Tm position check and trace how adjacent Tj objects update the current text position. Reproduce the supplied PDF sequence, including the separate “MP%” object, and compare the extracted output with the viewer’s text. Done means adjacent text is not separated by an unintended tab while genuine spacing remains distinguishable.
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