Closed bdeonovic closed 1 year ago
The font enconding mapping to unicode used in PDF has issues. Please share the file to investigate.
The encoding cmaps have ranges lo:hi defined in them. It seems for some reason in the mapping file you have high value lesser than low value. Hence, this assertion error.
A few comments:
U ovoj je knjizi riječ pretežito o hobitima i iz nje će čitatelj doznati štošta o njihovu značaju i nešto malo o njihovoj povijesti.
but the extract function seems to have a problem with the accent marks. I get this:
U ovoj je knjizi rijee zna Crvene knjige o Zapadnoj pokrajini koji su ve objelodanjeni pod naslovom Hobit.
which doesn't have accent marks and skips a bunch of text.
Thoughts?
I would believe you have some issues related to the font encoding in the file. If I open the file in Adobe Reader and select and copy the text I see exactly below. Which is close to what you are observing. This happens when the font toUnicode c-maps are not properly transferred. The extract text works on the same principle of copying and pasting text from a PDF file.
1 O hobitima U ovoj je knjizi rije e zna Crvene knjige o Zapadnoj pokrajini koji su ve objelodanjeni pod naslovom Hobit.
I will need to investigate the original file with the C-Map to realize why the file does not get transmitted properly. Please share it here, if possible. If there are security concerns you can mail me at: sambitdash at gmail
email sent
@bdeonovic Sorry for my delay in looking into the file. The CMap file in the PDF is not aligned to the spec. Figure-6 in the attached spec.
That's the reason some readers behave differently. While I will try to repair the cmap for a special case, this is not the correct approach. Code space ranges are rectangular regions in the byte plane and not numbers.
/Registry (BKABIP+TT5+0) /Ordering (T42UV) /Supplement 0 >> def
/CMapName /BKABIP+TT5+0 def
/CMapType 2 def
1 begincodespacerange <00fb> <0108> endcodespacerange
2 beginbfchar
<00ff> <0111>
<0108> <0110>
endbfchar
2 beginbfrange
<00fb> <00fc> <0106>
<00fd> <00fe> <010C>
endbfrange
endcmap CMapName currentdict /CMap defineresource pop end end
is the CMap. As per the CMap spec the codespace range should have 2 elements.
2 begincodespacerange
<00fb> <00ff>
<0100> <0108>
endcodespacerange
A few comments:
- I printed one page of the pdf (print to pdf on windows) which was causing the error so I could post it here as an example. However, when I tried to run the extract on this 1 page example the extract worked.
- The extract doesn't correctly extract the text. The first sentence should be:
U ovoj je knjizi riječ pretežito o hobitima i iz nje će čitatelj doznati štošta o njihovu značaju i nešto malo o njihovoj povijesti.
but the extract function seems to have a problem with the accent marks. I get this:
U ovoj je knjizi rijee zna Crvene knjige o Zapadnoj pokrajini koji su ve objelodanjeni pod naslovom Hobit.
which doesn't have accent marks and skips a bunch of text.
Thoughts?
On Page-6 of the document you shared, I get:
U ovoj je knjizi riječ pretežito o hobitima i iz nje će čitatelj doznati štošta o njihovu
značaju i nešto malo o njihovoj povijesti.
This is what you are expecting. While I have introduced a workaround in the code, this is not the code as per spec.
What does this error mean?