【发布时间】:2015-01-13 17:37:14
【问题描述】:
我在 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中有
波兰语:ņÃ3dÅo
我尝试更改源字符串的编码(使用示例代码中的注释行),但都失败了。
谁能解释我如何使用 PoDoFo 库创建包含非 ascii 字符的 PDF 文档?
【问题讨论】:
-
两个明显的错误。您期望 PDF 渲染器能够解析 UTF8(无论您是否知道,您都在使用它)。其次,您希望内置的 Helvetica 包含波兰语字符——请参阅 stackoverflow.com/questions/26631815/… 了解更多信息。
-
@Jongware 我已经修改了我的代码,并尝试添加带有波兰语字符的嵌入字体:Liberation-Serif,这是代码:PdfFont* pFont = document.CreateFontSubset("LiberationSerif", false, false , PdfEncodingFactory::GlobalWinAnsiEncodingInstance(), "fonts/LiberationSerif-Regular.ttf");而且没有成功...
标签: c++ pdf encoding utf-8 podofo