PoDoFo库c ++将文本修改为pdf

时间:2017-03-20 11:50:01

标签: c++ pdf chars polish podofo

This solution 不适合我。 还有其他选择吗?

修改

我有这个:

string font = "resources//fonts//FreeSans.ttf";
PdfStreamedDocument document(output_pdf_name.c_str());
PdfPainter painter;
PdfPage* page;
page = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
painter.SetPage(page);
const PdfEncoding *pEncoding = PdfEncodingFactory::GlobalIdentityEncodingInstance();
PdfFont *f1 = document.CreateFont(font.c_str(), true, true, pEncoding);

PdfString eNtext("English text");
PdfString pLtext("Łódź stół");

painter.SetFont(f1);
painter.DrawText(100.0, page->GetPageSize().GetHeight() - 100.0, eNtext);
painter.DrawText(100.0, page->GetPageSize().GetHeight() - 150.0, pLtext);
painter.FinishPage();
document.Close();

我在输出pdf

中看到了这一点

Image1

如果我设置

string font = "resources//fonts//FreeSans.ttf";
PdfFont *f1 = document.CreateFont(font.c_str());
PdfString pLtext("\u0141\u00F3d\u017A st\u00F3\u0142");

我得到了

Image3

希望,这将有助于找到答案。

1 个答案:

答案 0 :(得分:0)

此代码适用于我:

PdfStreamedDocument document(output_pdf_name.c_str());
PdfPainter painter;
PdfPage* page;
page = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
painter.SetPage(page);

PdfString eNtext("English text");
PdfString pLtext(L"Łódź stół");
PdfFont* pFont = document.CreateFont("TIMES NEW ROMAN", false, new PdfIdentityEncoding(0, 0xffff, true));


painter.SetFont(pFont);
painter.DrawText(100.0, page->GetPageSize().GetHeight() - 100.0, eNtext);
painter.DrawText(100.0, page->GetPageSize().GetHeight() - 150.0, pLtext);
painter.FinishPage();
document.Close();

这是最重要的部分:

PdfString pLtext(L"Łódź stół");
PdfFont* pFont = document.CreateFont("TIMES NEW ROMAN", false, new PdfIdentityEncoding(0, 0xffff, true));

祝你好运!