java - 使用 android pdf writer lib 对元音变音进行编码

标签 java android pdf encoding character-encoding

我正在使用Android PDF Writer我仍然很困惑。我的 PDF 渲染器必须使用变音符号(“ß”、“Ä”、“Ü”)写入单词,但它们在 pdf 中无法正确显示。

我认为问题出在 String 类的方法 getBytes(String encoding) 上。

PDFWriter pdfWriter = new PDFWriter(PaperSize.A4_WIDTH, PaperSize.A4_HEIGHT);
pdfWriter.setFont(StandardFonts.SUBTYPE, StandardFonts.SANS_SERIF, StandardFonts.MAC_ROMAN_ENCODING);
// only write some strings into the pdfwriter
parseData(pdfWriter);
outputToFile(filename, pdfWriter.asString(), "UTF-8");

当我检查 pdfWriter.asString() 时,出现变音符号。

private void outputToFile(String fileName, String pdfContent, String encoding) {
    File newFile = new File(fileName);
    Log.v(Constants.LOG_TAG, newFile.getAbsolutePath());
    try {
        newFile.createNewFile();
        try {
            FileOutputStream pdfFile = new FileOutputStream(newFile);
            pdfFile.write(pdfContent.getBytes("UTF8"));
            pdfFile.close();
        } catch(FileNotFoundException e) {
            //
        }
    } catch(IOException e) {
        //
    }
}

也许 getBytes() 方法有问题?

最佳答案

答案就在您眼前:您的 PDF 不使用 UTF-8,因此 PDF 查看器会尝试将您的 UTF-8 编码文件解码为 MacRoman。

要快速修复,您可以在一侧使用 StandardEncodings.WIN_ANSI_ENCODING"WINDOWS-1252""ISO-8859-1" > 另一方面。

关于java - 使用 android pdf writer lib 对元音变音进行编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28564230/

相关文章:

android - 从 WebView 播放 youtube 视频

r - 如何仅以一个pdf保存ggforce::facet_grid_paginate的输出?

c# - webBrowser 控件中的 PDF 文档在关闭应用程序时导致 'The memory could not be "read"' 错误

java - Android - 解析图像 url 的 Twitter JSON

java - 扫描仪 Try Catch 语句导致 java.util.InputMismatchException

java - 从 LinkedList 的构造函数调用非最终 addAll 方法

java - 获取 SWT 元素的父 Part

android - 如何在android中以编程方式录制当前屏幕 Activity 的视频

android - 在Android.mk中使用Make的 'wildcard'函数

css - 在 Safari 上无边框打印