Decode to wrong character
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
- PHP Version: 8.1.13
- PDFParser Version: 2.5.0
Description:
In my pdf file, there are strings with the character Đ, for example: "Địa chỉ". The characters 'ị' 'a' 'c' 'h' 'ỉ' are encoded with 2 bytes, while the character 'Đ' is encoded with 3 bytes. I learned this through checking the pdf file. However, I don't understand why the character 'Đ' is encoded with 3 bytes. pdfparser didn't detect this and therefore decodes 2 bytes at a time, resulting in incorrect decoding for all the characters.
PDF input
Expected output & actual output
Expected output: Địa chỉ
Actual output: non-readable text
Bytes sequence: 01 5c 62 04 cf 00 44 00 03 00 46 00 4b 04 cd
01 5c 62 => can't decode
04 cf => ị
00 44 => a
00 03 => space
00 46 => c
00 4b => h
04 cd => ỉ
Code
$parser = new Parser();
$document = $parser->parseFile($file);
$data = $document->getText();
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 at Parser::parseFile and reproduce the decoding failure with the provided 1C23TAZ_0000178321.pdf file and the example code. Trace how the byte sequence for “Địa chỉ” is decoded, then verify that document->getText() returns the expected readable text without breaking the other characters.
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
- Needs clarification
- Newbie friendliness
- 30/100