gpt4 book ai didi

c++ - PoDoFo c++ PDF库,润色字符

转载 作者:行者123 更新时间:2023-11-30 05:49:01 33 4
gpt4 key购买 nike

我在 PoDoFo 中编码波兰语字符时遇到问题图书馆。

此代码生成单词“Łódź”的无效编码

#include <podofo/podofo.h>

using namespace PoDoFo;

int main(int argc, char *argv[], char *env[]) {
PdfStreamedDocument document("polish.pdf");
PdfPainter painter;
PdfPage* pPage;


pPage = document.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
painter.SetPage( pPage );
PdfFont* pFont = document.CreateFont("Helvetica");
// PdfFont* pFont = document.CreateFont("Helvetica", new PdfIdentityEncoding(0, 0xffff, true) );
PdfString pString("Polish word: Łódź");
// PdfString pString(reinterpret_cast<const pdf_utf8*>("Polish word: Łódź"));

painter.SetFont( pFont );
painter.DrawText( 100.0, pPage->GetPageSize().GetHeight()-100.0, pString );
painter.FinishPage();
document.Close();

return 0;
}

在输出pdf中有

Polish word: ņÃ3dÅo

我尝试更改源字符串的编码(使用示例代码中的注释行),但都失败了。

谁能解释一下如何使用 PoDoFo 库创建包含非 ASCII 字符的 PDF 文档?

最佳答案

#include <podofo/podofo.h>

using namespace PoDoFo;

int main(int argc, char *argv[], char *env[]) {
PdfStreamedDocument document("polish.pdf");
PdfPainter painter;
PdfPage* pPage;


pPage = document.CreatePage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ) );
painter.SetPage( pPage );
const PdfEncoding* pEncoding = new PdfIdentityEncoding(); // required for UTF8 characters
PdfFont *pFont = document.CreateFont("LiberationSerif", false, false, pEncoding ); // LiberationSerif has polish characters
PdfString pString(reinterpret_cast<const pdf_utf8*>("Polish word: Łódź")); // Need to cast input string into pdf_utf8
painter.SetFont( pFont );
painter.DrawText( 100.0, pPage->GetPageSize().GetHeight()-100.0, pString );
painter.FinishPage();
document.Close();

return 0;
}

这段代码对我有用。

关于c++ - PoDoFo c++ PDF库,润色字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27928112/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com