PoDoFo c ++ PDF库,抛光字符 [英] PoDoFo c++ PDF library, polish characters

查看:211
本文介绍了PoDoFo c ++ PDF库,抛光字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PoDoFo 库中编码抛光字符有问题。

I have a problem with encoding polish characters in PoDoFo library.

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

This code generates invalid encoding of word 'Łó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

Polish word: ņÃ3dÅo

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

I've tried to change encoding of source string (using commented lines in sample code), but all failed.

有人可以向我解释如何使用PoDoFo库创建包含非ASCII字符的PDF文档?

Can somebody explain me how to create PDF document containing non-ascii characters using PoDoFo library?

推荐答案

#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;
}

此代码适用于我。

这篇关于PoDoFo c ++ PDF库,抛光字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆