2

我在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 文档吗?

4

3 回答 3

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

这段代码对我有用。

于 2015-04-20T09:15:07.883 回答
0

在我的情况下,西班牙波浪号与:

PdfFont* pFont = document.CreateFont("Arial"); PdfString pString(reinterpret_cast("máma mia"); ...

在其他方式特殊字符可能会被错误打印..

于 2019-05-10T01:34:41.330 回答
0

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

于 2018-06-26T18:53:48.993 回答