2

对不起,我的英语,我对 PDF 中的西里尔符号有疑问。我在 Windows 和 Linux 中使用 PoDoFo 库版本 0.9.7 和 fontconfig。

PdfMemDocument document;
document.Load("anyfile.pdf", true);
/***/
PdfFont *fontPtr = fontPtr = document.CreateFont("Arial", false, false, PdfEncodingFactory::GlobalIdentityEncodingInstance());
PdfPainter painter;
painter.SetPage(document.GetPage(0));
/***/
PdfString str(reinterpret_cast<const pdf_utf8*>("Next text is russian words: 'Пример текста на русском.'"));
// i use plog loging lib and it:
// LOG_INFO << str.GetStringUtf8(); // out correct string
/***/
painter.DrawTextAligned(40, 400, 800, str.GetStringUtf8(), PoDoFo::EPdfAlignment::ePdfAlignment_Left);
painter.FinishPage();
document.Close();

我看到它是波兰语的页面,但对我没有帮助!

在屏幕截图上给出了我的例子:

在此处输入图像描述

4

1 回答 1

1

我设置了字体路径,它可以工作!

document.CreateFontSubset("LiberationSans-Regular", false
                                      , false, false, pEncoding, "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf");

如果你想自动搜索,你可以试试这个:

PdfFontConfigWrapper ftWrapper;
auto createFont = [&ftWrapper](PdfMemDocument& document, const std::string& fontName, bool bold, bool italic, const PdfEncoding* pEncoding) -> PdfFont* {
    auto fontPath = PdfFontCache::GetFontConfigFontPath(static_cast<FcConfig*>(ftWrapper.GetFontConfig()), fontName.c_str(), true, false);
    PdfFont *fontPtr = document.CreateFontSubset(fontName.c_str(), bold, italic, false, pEncoding, fontPath.c_str());

    return fontPtr;
};
于 2021-11-21T10:24:51.463 回答