Home > Back-end >  Foxit pdfium how to write text in the PDF file, especially Chinese characters
Foxit pdfium how to write text in the PDF file, especially Chinese characters

Time:10-23

InitPdfDll (GetCurrentPath + 'pdfium. DLL);
If SaveDialog1. Execute=false then the Exit;
PDFFN:=SaveDialog1. FileName;//'C: \ Users \ lenovo \ Desktop \ test1 PDF';

TXT:='abc123, SSS is a';//+ st. Text;//Encode (edit1. Text, IndyTextEncoding_UTF16LE);//'day I test 123 abcd ha';

Hpdfdoc:=FPDF_CreateNewDocument;//FPDF_LoadDocument (pansichar (pdffn0), pansichar ("));//(' C: \ Users \ lenovo \ Desktop \ light - manual - COM - dotNET - CS. PDF ');//FPDF_CreateNewDocument
Try
Hpdfpage:=FPDFPage_New (hpdfdoc, 0, 700, 800);//FPDF_LoadPage (hpdfdoc, 1);//

Ho:=FPDFPageObj_NewTextObj (hpdfdoc, 'Arial, 20);//hpdfdoc, 'SimSun, 40

FPDFText_SetText (ho, PChar (TXT));
FPDFPageObj_SetFillColor (ho, $FFFF0000);
FPDFPageObj_Transform (ho, 1, 0, 0, 1, 200, 200);
FPDFPage_InsertObject (hpdfpage, ho);


FPDFPage_GenerateContent (hpdfpage);
FPDF_ClosePage (hpdfpage);
Hpdfpage:=0;
The deletefile (PansiChar (PDFFN));
If PdfSaveAs0 (hpdfdoc PDFFN)=false then
Raise the exception. The create (' PDF file save failed);
Showmessage (" ok ");
The finally
FPDF_CloseDocument (hpdfdoc);
Hpdfdoc:=0;
end;
So what also don't show, all under the code can be here at http://www.dxmylove.com/download/foxitpdf.zip

CodePudding user response:

Ho:=FPDFPageObj_NewTextObj (hpdfdoc, 'Arial, 20);//hpdfdoc, 'SimSun, 40
The first parameter should be handle to page hpdfpage

CodePudding user response:

Is hpdfdoc

CodePudding user response:

Use FPDFText_LoadFont load font file can be achieved, but the fonts are embedded in the PDF file in file is bigger, libharu support zip compression but pdfium don't know how to implement,
How to use the system font instead of embedding, at the same time, the generated files under other systems without the corresponding font can be automatically mapped to step Chinese fonts also know how to achieve, look at the interface function should be adjustable FPDF_AddInstalledFont,
  • Related