You are telling the compiler to simply interpret the memory of the string as
UTF-8. Are you sure that is the encoding your compiler is using?
Could you try using something like this, just to make sure the encoding gets
through correctly?
pdf_utf8 const str[] = {0xe3,0x80,0x8c,0x50,0x6f,0x5c,0x74,0x44,0x6f,0x46,0x6f,
0xe3,0x80,0x8d,0xe4,0xb8,0xad,0xe6,0x96,0x87,0xe6,0xb5,0x8b,0xe8,0xaf,0x95,0x00};
PdfString sJap(str);
Cheers,
Christopher
The MathWorks GmbH | Friedlandstr.18 | 52064 Aachen | District Court Aachen |
HRB 8082 | Managing Directors: Bertrand Dissler, Steven D. Barbo, Jeanne O’Keefe
From: ning <[email protected]>
Sent: Sunday, August 1, 2021 13:53
To: podofo-users <[email protected]>
Subject: [Podofo-users] drawtext()function can not add CJK text to PDF
Deatr podofoteams:
I recently used podofo to add text to the PDF, but found that the correct
Chinese cannot be added to the PDF under linux (ubuntu). The code I used is the
following paragraph:
pFont = pDocument->CreateFont( "Arial Unicode MS", new PdfIdentityEncoding(
0, 0xffff, true ) );
printf("GOT: %s\n", pFont->GetFontMetrics()->GetFontname() );
PdfString sJap(reinterpret_cast<const pdf_utf8*>("「Po\tDoFo」中文测试"));
const long lUtf8BufferLen = 256;
pdf_utf8 pUtf8Buffer[lUtf8BufferLen];
PdfString::ConvertUTF16toUTF8( sJap.GetUnicode(), sJap.GetUnicodeLength(),
pUtf8Buffer, lUtf8BufferLen );
printf("UNIC: %s\n", pUtf8Buffer );
pFont->SetFontSize( 18.0 );
pPainter->SetFont( pFont );
pPainter->DrawText( 100.0, 100.0, sJap );
In addition to this, I also used
const PdfEncoding* pp = PdfEncodingFactory::GlobalIdentityEncodingInstance();
PdfFont* pFont = document.CreateFont("SimHei", true, true, false,
pp);//Helvetica
painter.SetFont( pFont );
double w = pPage->GetPageSize().GetWidth();
double h = pPage->GetPageSize().GetHeight();
PdfString str((pdf_utf8* )"测试podofo显示中文文本显示是否为乱码! \n \n");
painter.DrawMultiLineText( 0, 0, w, h, str);
After I use this code, I cannot find these words in the PDF, so I seek your
help and hope to get a reply, thank you
best wishes
ning
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users