我在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中有
波兰语单词:†
我试图更改源代码字符串的编码(在示例代码中使用注释行),但都失败了。
有人能解释一下如何使用PoDoFo库创建包含非ascii字符的PDF文档吗?
发布于 2015-04-20 09:15:07
#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;
}这个密码对我有用。
发布于 2018-06-26 18:53:48
使用PdfIdentityEncoding修复显示抛光字符,但使用这种编码的字符间距是错误的。
发布于 2019-05-10 01:34:41
就我的西班牙倾斜工作而言:
pFont = document.CreateFont( "Arial");PdfString pString(reinterpret_cast("máma mía");
在其他方面,特殊字符可能打印错误。
https://stackoverflow.com/questions/27928112
复制相似问题