首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PoDoFo c++ PDF库,波兰字符

PoDoFo c++ PDF库,波兰字符
EN

Stack Overflow用户
提问于 2015-01-13 17:37:14
回答 3查看 1.8K关注 0票数 2

我在PoDoFo库中编码波兰字符时遇到了问题。

此代码生成单词'Łódź‘的无效编码。

代码语言:javascript
复制
#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中有

波兰语单词:†

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

有人能解释一下如何使用PoDoFo库创建包含非ascii字符的PDF文档吗?

EN

回答 3

Stack Overflow用户

发布于 2015-04-20 09:15:07

代码语言:javascript
复制
#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;
}

这个密码对我有用。

票数 1
EN

Stack Overflow用户

发布于 2018-06-26 18:53:48

使用PdfIdentityEncoding修复显示抛光字符,但使用这种编码的字符间距是错误的。

票数 0
EN

Stack Overflow用户

发布于 2019-05-10 01:34:41

就我的西班牙倾斜工作而言:

pFont = document.CreateFont( "Arial");PdfString pString(reinterpret_cast("máma mía");

在其他方面,特殊字符可能打印错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27928112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档