本文介绍了从PDF复制粘贴在原始文件上是乱码,但在使用CutePDF打印pdf时已修复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,其中包含希腊语。尝试从中复制和粘贴文本时,会出现,导致轻微乱码。我说轻微而不是的原因是,虽然粘贴的输出在希腊语中没有意义,但它由有效的希腊字符组成。此外,该问题的一个有趣方面是并非所有字符都映射错误。例如,如果您比较此原始文本条

I have this PDF file, which is in Greek. A known problem occurs when trying to copy and paste text from it, resulting in slight gibberish. The reason I say slight instead of total, is that while the pasted output does not make sense in Greek, it is comprised of valid greek characters. Also, an interesting aspect to the problem is that not all characters are mapped wrong. For example, if you compare this original strip of text

ΕΞ. ΕΠΕΙΓΟΝ – ΑΜΕΣΗ ΕΦΑΡΜΟΓΗ
ΝΑ ΣΤΑΛΕΙ ΚΑΙ ΜΕ Ε-ΜΑIL



与粘贴一个从PDF:

with the pasted one from the PDF:

ΔΞ. ΔΠΔΙΓΟΝ – ΑΜΔ΢Η ΔΦΑΡΜΟΓΗ
ΝΑ ΢ΣΑΛΔΙ ΚΑΙ ΜΔ Δ-ΜΑIL



你会发现一些角色被正确粘贴,而其他角色则没有。值得一提的是,错误的字符被反射映射错误,例如Ε变为Δ,反之亦然。

当我使用例如打开PDF时Adobe,并使用PDF编写器打印,在本例中为CutePDF,复制和粘贴时的输出是正确的!

When I open the PDF using e.g. Adobe, and print it using a PDF writer, in this case CutePDF, the output when copying and pasting is correct!

鉴于上述情况,我的问题如下:

Given the above, my questions are the following:


  1. 什么是这种行为的根本原因是什么?

  2. 如何将解决方案集成到基于java的工作流程中,以便随机导入PDF文件?

编辑:一些拼写错误

推荐答案

一些基本情况:

通过从字体中选择字形来显示PDF格式的文本。字形是一个或多个字符的直观表示。字形选择使用字符代码完成。对于文本提取,您需要知道哪些字符与字符代码相对应。

Displaying text in PDF is done by selecting glyphs from a font. A glyph is the visual representation of one or more characters. Glyph selection is done using character codes. For text extraction, you need to know which characters correspond with a character code.

在这种情况下,这是使用 ToUnicode CMap实现的。

In this case, this is achieved using a ToUnicode CMap.

在本文档中,文本片段的第一个字母E显示如下:

In this document, the first letter of the text snippet, E, is displayed like this:

[0x01FC,...] TJ

ToUnicode CMap包含此条目:

The ToUnicode CMap contains this entry:

4 beginbfrange
<01f9> <01fc> <0391>
...
endbfrange

这意味着字符代码 0x01F9 0x01FA 0x01FB 0x01FC 映射到Unicode U + 0x391 U + 0x392 U分别为+ 0x393 U + 0x394

This means that character codes 0x01F9, 0x01FA, 0x01FB and 0x01FC are mapped to Unicode U+0x391, U+0x392, U+0x393 and U+0x394 respectively.

是希腊三角洲Δ,在复制/粘贴时显示。

U+0394 is the Greek delta, Δ, that shows up when copy/pasting.

下一个字母是使用字符代码 0x0204 绘制的。相关的 ToUnicode 条目为< 0200> < 020B> < 039a> ,将其正确映射到

The next letter is painted using character code 0x0204. The relevant ToUnicode entry is <0200> <020b> <039a>, which maps it correctly to U+039E

所以,你得到轻微的乱码,因为只有部分Unicode映射是错误的。有时这是故意的,例如防止数据挖掘。我之前在财务报告中看过它。

So, you're getting slight gibberish, because only some of the Unicode mapping is wrong. Sometimes this is done on purpose, e.g. to prevent data mining. I have seen it before in financial reports.

这篇关于从PDF复制粘贴在原始文件上是乱码,但在使用CutePDF打印pdf时已修复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 06:48
查看更多