【问题标题】:PoDoFo c++ PDF library, cyrilic charactersPoDoFo c++ PDF库,西里尔字符
【发布时间】:2021-12-31 00:08:09
【问题描述】:

对不起,我的英语有问题,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();

我看到了page for Polish,但这对我没有帮助!

在截图上给出我的例子:

【问题讨论】:

  • 尝试以utf8编码保存源文件。如果您这样做并且没有帮助,则渲染字体没有西里尔字形,并且您找到的答案是正确的,但您应该更改字体。
  • @S.M.如何以 UTF-8 编码保存文档?我在Podofo中没有找到这样的功能
  • @KJ 你能为我做一个简单的作品例子吗?我受了这几天的苦,我没有任何想法。
  • @KJ,我在上面构建了一个示例,他给出了同样的错误结果。我尝试了 Liberation 字体、Courier、Arial 和结果不好 =(

标签: c++ pdf encoding utf-8 podofo


【解决方案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;
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多