smalot / smalot/pdfparser

some chinese fonts mojibake

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

Nobody has claimed this yet.

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

Description

  • PHP Version:
  • PDFParser Version: v2.3.0
Description:

\Smalot\PdfParser\Parser::parseFile file_get_contents Wrong escape of characters into ”>\b“ , Should be '>’
image

So it leads to $this->tableSizes['from'] errors,Become 3 characters,cause mojibake.

now I can only modify here,
vendor/smalot/pdfparser/src/Smalot/PdfParser/Font.php
image

PDF input

FontType

Array
(
    [Name] => AAAANE+SimSun
    [Type] => Type0
    [Encoding] => Identity-H
    [BaseFont] => AAAANE+SimSun
    [DescendantFonts] => Array
        (
            [0] => Array
                (
                    [Name] => AAAANE+SimSun
                    [Type] => CIDFontType2
                    [Encoding] => Ansi
                    [BaseFont] => AAAANE+SimSun
                    [Subtype] => CIDFontType2
                )

        )

    [Subtype] => Type0
    [ToUnicode] => Array
        (
            [Filter] => FlateDecode
            [Length] => 236
        )

)
Expected output & actual output

expected output: 溪雨观酸菜鱼(临平路店)
actual output:(N�&@ >\bfFY `�S:k�)Tj

Code
        $parser = new \Smalot\PdfParser\Parser();
        $pdf = $parser->parseFile($filepath);
        $text = $pdf->getText();

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 vendor/smalot/pdfparser/src/Smalot/PdfParser/Font.php and trace the Parser::parseFile/file_get_contents path for the supplied Type0 SimSun font and its ToUnicode data. Reproduce the example and compare the extracted text with the expected Chinese string; done means the parser no longer produces mojibake for this input.

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.