PoDoFo c++ PDF 库,波兰字符

PoDoFo c++ PDF library, polish characters

本文关键字:字符 c++ PDF PoDoFo      更新时间:2023-10-16

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

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

这段代码对我有用。

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

在我的西班牙语波浪号的情况下,请使用:

PdfFont* pFont = document。创建字体( "Arial");PdfString pString(reinterpret_cast("máma mía");...

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