Dear PodofoTeams??

Thanks for replying to my question.
Yes, I used the utf8 encoding method, but I still cannot input the correct 
Chinese characters into the PDF. During the debugging process, I found that the 
printed fontname is suruma. I don??t know if this is caused by the failure of 
my related font library installation.


This code is from Createtiontest.cpp??


    pFont = pDocument->CreateFont( "Arial Unicode MS", new 
PdfIdentityEncoding( 0, 0xffff, true ) );
    printf("GOT: %s\n", pFont->GetFontMetrics()->GetFontname() 
);
&nbsp; &nbsp; PdfString sJap(reinterpret_cast<const 
pdf_utf8*&gt;("??Po\tDoFo???????????????Z????????????"));
&nbsp; &nbsp; const long&nbsp; &nbsp; &nbsp;lUtf8BufferLen = 256;
&nbsp; &nbsp; pdf_utf8 pUtf8Buffer[lUtf8BufferLen];
&nbsp; &nbsp; 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};//po\tdofo????????


&nbsp; &nbsp; PdfString sCHN(str);


&nbsp; &nbsp; PdfString::ConvertUTF16toUTF8( sJap.GetUnicode(), 
sJap.GetUnicodeLength(), pUtf8Buffer, lUtf8BufferLen&nbsp; );
&nbsp; &nbsp; printf("UNIC: %s\n", pUtf8Buffer );


&nbsp; &nbsp; pFont-&gt;SetFontSize( 18.0 );
&nbsp; &nbsp; pPainter-&gt;SetFont( pFont );
&nbsp; &nbsp; pPainter-&gt;DrawText( 100.0, 100.0, sJap );
&nbsp; &nbsp; pPainter-&gt;DrawText( 200.0, 200.0, sCHN );





The message typed in the terminal by this code??


This test tests the PdfWriter and PdfDocument classes.
It creates a new PdfFile from scratch.
---
PoDoFo DataType Size Information:
---
sizeof variant=24
sizeof object=56
sizeof reference=16
---


Drawing the first page with various lines.
GOT: Suruma
UNIC: ??Po      DoFo???????????????Z????????????
Drawing the second page with various rectangle and triangles.
Drawing some text.
Embedding Font
!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!
Drawing some images.
Drawing on the page!
Drawing some circles and ellipsis.
Drawing some XObject's.
<</ID[<2CDA11A34E27D74294B3341065281964&gt;<2E3A232DA26DAD40B4BA526B7F172E8A&gt;]/Info
 28 0 R/Root 1 0 R/Size 35&gt;&gt;
Fixing references in 75 0 R by 74
Fixing references in 76 0 R by 74
Fixing references in 79 0 R by 74
Fixing references in 80 0 R by 74
Fixing references in 81 0 R by 74
Fixing references in 82 0 R by 74
Fixing references in 83 0 R by 74
Fixing references in 84 0 R by 74
Fixing references in 85 0 R by 74
Fixing references in 86 0 R by 74
Fixing references in 87 0 R by 74
Fixing references in 88 0 R by 74
Fixing references in 89 0 R by 74
Fixing references in 90 0 R by 74
Fixing references in 91 0 R by 74
Fixing references in 92 0 R by 74
Fixing references in 93 0 R by 74
Fixing references in 94 0 R by 74
Fixing references in 97 0 R by 74
Fixing references in 98 0 R by 74
Fixing references in 99 0 R by 74
Fixing references in 100 0 R by 74
Fixing references in 101 0 R by 74
Fixing references in 102 0 R by 74
Fixing references in 103 0 R by 74
Fixing references in 104 0 R by 74
Fixing references in 105 0 R by 74
Fixing references in 106 0 R by 74
Fixing references in 107 0 R by 74
Fixing references in 108 0 R by 74
<</ID[<2CDA11A34E27D74294B3341065281964&gt;<2E3A232DA26DAD40B4BA526B7F172E8A&gt;]/Info
 28 0 R/Root 1 0 R/Size 35&gt;&gt;
Fixing references in 109 0 R by 108
Fixing references in 110 0 R by 108
Fixing references in 113 0 R by 108
Fixing references in 114 0 R by 108
Fixing references in 115 0 R by 108
Fixing references in 116 0 R by 108
Fixing references in 117 0 R by 108
Fixing references in 118 0 R by 108
Fixing references in 119 0 R by 108
Fixing references in 120 0 R by 108
Fixing references in 121 0 R by 108
Fixing references in 122 0 R by 108
Fixing references in 123 0 R by 108
Fixing references in 124 0 R by 108
Fixing references in 125 0 R by 108
Fixing references in 126 0 R by 108
Fixing references in 127 0 R by 108
Fixing references in 128 0 R by 108
Fixing references in 131 0 R by 108
Fixing references in 132 0 R by 108
Fixing references in 133 0 R by 108
Fixing references in 134 0 R by 108
Fixing references in 135 0 R by 108
Fixing references in 136 0 R by 108
Fixing references in 137 0 R by 108
Fixing references in 138 0 R by 108
Fixing references in 139 0 R by 108
Fixing references in 140 0 R by 108
Fixing references in 141 0 R by 108
Fixing references in 142 0 R by 108
Drawing using PdfTable.
Drawing using PdfPainterMM.
Drawing using PdfPainter MultilineText.
Drawing using Font Subset.
Setting document informations.





This is a screenshot of the PDF


Env: linux (ubuntu18.04)
Lib: freetype2.10.0, fontconfig2.13.91, podofo0.9.7



Although I cannot use the drawtext() function or the DrawMultiLineText() 
function to write Chinese, I found that the annotation_freetext can be used to 
write Chinese Correctly, but it cannot be previewed or sent to the printer for 
printing. The same after using SetFlags(0x0004).The code is the 
CreateUnicodeAnnotationFreeText() function in test/Creationtest/Creationtest.cpp


thank you very much






best wishes
Ning


------------------ ???????? ------------------
??????:                                                                         
                                               "Christopher Creutzig"           
                                                                         
<ccreu...@mathworks.com&gt;;
????????:&nbsp;2021??8??2??(??????) ????2:25
??????:&nbsp;"ning"<ningning...@foxmail.com&gt;;"podofo-users"<podofo-users@lists.sourceforge.net&gt;;

????:&nbsp;RE: [Podofo-users] drawtext()function can not add CJK text to PDF



  
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?
 
&nbsp;
 
Could you try using something like this, just to make sure the encoding gets 
through correctly?
 
&nbsp;
 
pdf_utf8 const str[] = {0xe3,0x80,0x8c,0x50,0x6f,0x5c,0x74,0x44,0x6f,0x46,0x6f,
 
&nbsp; 
0xe3,0x80,0x8d,0xe4,0xb8,0xad,0xe6,0x96,0x87,0xe6,0xb5,0x8b,0xe8,0xaf,0x95,0x00};
 
PdfString sJap(str);
 
&nbsp;
 
&nbsp;
 
Cheers,
 
Christopher
 
The MathWorks GmbH | Friedlandstr.18 | 52064 Aachen | District Court Aachen | 
HRB 8082 | Managing Directors: Bertrand Dissler, Steven D. Barbo, Jeanne 
O??Keefe
 
&nbsp;
 
&nbsp;
  
From: ning <ningning...@foxmail.com&gt; 
 Sent: Sunday, August 1, 2021 13:53
 To: podofo-users <podofo-users@lists.sourceforge.net&gt;
 Subject: [Podofo-users] drawtext()function can not add CJK text to PDF
 
 
&nbsp;
  
Deatr podofoteams:
 
  
&nbsp;
 
  
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:
 
  
&nbsp;
 
   
&nbsp; &nbsp; pFont = pDocument-&gt;CreateFont( "Arial Unicode MS", new 
PdfIdentityEncoding( 0, 0xffff, true ) );
 
  
&nbsp; &nbsp; printf("GOT: %s\n", pFont-&gt;GetFontMetrics()-&gt;GetFontname() 
);
 
  
&nbsp; &nbsp; PdfString sJap(reinterpret_cast<const 
pdf_utf8*&gt;("??Po\tDoFo??????????"));
 
  
&nbsp; &nbsp; const long&nbsp; &nbsp; &nbsp;lUtf8BufferLen = 256;
 
  
&nbsp; &nbsp; pdf_utf8 pUtf8Buffer[lUtf8BufferLen];
 
  
&nbsp;
 
  
&nbsp;
 
  
&nbsp; &nbsp; PdfString::ConvertUTF16toUTF8( sJap.GetUnicode(), 
sJap.GetUnicodeLength(), pUtf8Buffer, lUtf8BufferLen&nbsp; );
 
  
&nbsp; &nbsp; printf("UNIC: %s\n", pUtf8Buffer );
 
  
&nbsp;
 
  
&nbsp; &nbsp; pFont-&gt;SetFontSize( 18.0 );
 
  
&nbsp; &nbsp; pPainter-&gt;SetFont( pFont );
 
  
&nbsp; &nbsp; pPainter-&gt;DrawText( 100.0, 100.0, sJap );
 
 
  
&nbsp;
 
  
In addition to this, I also used
 
  
&nbsp;
 
  
const PdfEncoding* pp = PdfEncodingFactory::GlobalIdentityEncodingInstance();
 
PdfFont* pFont = document.CreateFont("SimHei", true, true, false, 
pp);//Helvetica
 
painter.SetFont( pFont );
 
double w = pPage-&gt;GetPageSize().GetWidth();
 
double h = pPage-&gt;GetPageSize().GetHeight();
 
PdfString str((pdf_utf8* )"????podofo???????????????????????????? \n  \n");
 
painter.DrawMultiLineText( 0, 0, w, h, str);
 
  
&nbsp;
 
  
&nbsp;
 
  
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
 
  
&nbsp;
 
  
best wishes
 
  
ning
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to