2

Sorry my English, i have a problem with cyrillic symbols in PDF. I use PoDoFo library version 0.9.7 with fontconfig in Windows and Linux.

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();

I see it page for Polish but it not help for me!

On screenshot whats give my example:

enter image description here

Depish
  • 131
  • 5
  • Try saving the source file in utf8 encoding. If you do this and this does not help, the rendering font does not have Cyrillic glyphs and the answer you found is correct but you should change the font. – 273K Nov 20 '21 at 17:08
  • @S.M. How can I save the document in the UTF-8 encoding? I did not find such a function in Podofo – Depish Nov 20 '21 at 19:51
  • @KJ Can you please make simple works example for me? I suffer from this a few days, and I do not have any ideas. – Depish Nov 20 '21 at 21:40
  • @KJ, I build an example above, he gives the same incorrect result. I try Liberation fonts, Courier, Arial and result bad =( – Depish Nov 21 '21 at 10:09

1 Answers1

1

I set path to font and it works!

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

And if you want auto search, you can try this:

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;
};
Depish
  • 131
  • 5