How to set chinese font style

956 views
Skip to first unread message

Bin Yang

unread,
Oct 25, 2018, 5:02:20 AM10/25/18
to pdfium
Hi,

I want to create pdf document. 
When create text I use FPDFPageObj_NewTextObj and the second parameter is font style string. However, I don't know how to set a chinese font style like "宋体"。
I saw there is another api FPDFPageObj_CreateTextObj and either don't know how to set a chinese font.

Thanks, 
Bin

Lei Zhang

unread,
Nov 2, 2018, 2:42:42 PM11/2/18
to actua...@gmail.com, pdf...@googlegroups.com
See the FPDFEditEmbeddertest.AddCIDFontText test case [1] for an
example with Japanese. Roughly:

1) Use FPDFText_LoadFont() to load a font that has Chinese characters.
2) Create a text object with the font using FPDFPageObj_CreateTextObj().
3) Use FPDFText_SetText() to write some characters.
4) Insert the text object into a page with FPDFPage_InsertObject().

[1] https://pdfium.googlesource.com/pdfium.git/+/0e8346b5/fpdfsdk/fpdf_edit_embeddertest.cpp#2386
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To post to this group, send email to pdf...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/7356a30d-a329-4993-8322-bb5fbe611f6c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Bin Yang

unread,
Nov 7, 2018, 5:36:18 AM11/7/18
to pdfium
I try to follow the workflow about the sample code. I need to indclude following header files.
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/page/cpdf_formobject.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/fx_system.h"

However, I got many compiler errors : 
safe_conversions_impl.h(227): warning C4003: “max” has unenough parameters
safe_conversions_impl.h(229): note: see the reference of "pdfium::base::internal::NarrowingRange<Dst,Src,Bounds>"

Is anyone know why?

Thanks,
Bin

Lei Zhang

unread,
Nov 14, 2018, 2:14:57 PM11/14/18
to Lisandero Yang, pdf...@googlegroups.com
My suggestion would be to not use PDFium internal code. Instead, find
some other way to get the font data.
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To post to this group, send email to pdf...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/fae04697-c31b-4ae2-a104-5f25d946c953%40googlegroups.com.

Bin Yang

unread,
Nov 14, 2018, 8:50:41 PM11/14/18
to pdfium
I added a new function in the fpdf_edit.h which is in public folder and implement it in fpdfedittext.cpp file.  It is the way I can only do now since I can't fiind the way to create "uint8_t* data” in the FPDFText_LoadFont. I don't know is there any example to get the font data directly with public functions?

Lei Zhang

unread,
Nov 14, 2018, 9:02:10 PM11/14/18
to Lisandero Yang, pdf...@googlegroups.com
Get the font data from an external source. You can open and read in a
.ttf file, for instance.
On Wed, Nov 14, 2018 at 5:50 PM Bin Yang <actua...@gmail.com> wrote:
>
> I added a new function in the fpdf_edit.h which is in public folder and implement it in fpdfedittext.cpp file. It is the way I can only do now since I can't fiind the way to create "uint8_t* data” in the FPDFText_LoadFont. I don't know is there any example to get the font data directly with public functions?
>
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To post to this group, send email to pdf...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/90b7893e-4c5b-4319-8293-73d34313b3a1%40googlegroups.com.

Bin Yang

unread,
Nov 20, 2018, 8:57:50 PM11/20/18
to pdfium
So do you mean first read the ttf file with other lib (like window API) as font data byte and then load the font.? 
I found  when I call the FPDFText_LoadFontByName then the size of pdf file will increase 8M. Is there any other method not to inrease the pdf size so much?

Lei Zhang

unread,
Nov 27, 2018, 2:45:27 PM11/27/18
to Lisandero Yang, pdf...@googlegroups.com
There is no function called FPDFText_LoadFontByName. Did you mean
FPDFText_LoadFont? Did the size of the PDF increase by 8 MB because
you loaded an 8 MB font?
On Tue, Nov 20, 2018 at 5:57 PM Bin Yang <actua...@gmail.com> wrote:
>>
>> So do you mean first read the ttf file with other lib (like window API) as font data byte and then load the font.?
>
> I found when I call the FPDFText_LoadFontByName then the size of pdf file will increase 8M. Is there any other method not to inrease the pdf size so much?
>
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To post to this group, send email to pdf...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/4863bf80-7706-4ecf-bdc1-845344c0db54%40googlegroups.com.

Bin Yang

unread,
Nov 28, 2018, 4:08:41 AM11/28/18
to pdfium
Yes I use FPDFText_LoadFont and I load simsun font. So you mean the simsun font size is about 8M. It is indeed much big.  Can I just use the font in operation system?

Lei Zhang

unread,
Nov 28, 2018, 5:52:22 PM11/28/18
to Lisandero Yang, pdf...@googlegroups.com
I checked a Windows 10 machine and "SimSun Regular" is 17 MB there. Is
yours smaller? You tell me.

It sounds like what you are trying to say is you only want to load the
porition of the font that's in use. e.g. the SimSun font has many
characters, but your document just says "你好" so you only need to embed
2 characters. This process is called font subsetting and it is out of
the scope of PDFium. You will need separate software to do the font
subsetting before loading the reduced font data with
FPDFText_LoadFont(). Chromium uses sfntly to do this, but may switch
to HarfBuzz in the future.
On Wed, Nov 28, 2018 at 1:08 AM Bin Yang <actua...@gmail.com> wrote:
>
> Yes I use FPDFText_LoadFont and I load simsun font. So you mean the simsun font size is about 8M. It is indeed much big. Can I just use the font in operation system?
>
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To post to this group, send email to pdf...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/fa557668-2921-46cd-9562-53b513a539c3%40googlegroups.com.

Bin Yang

unread,
Dec 11, 2018, 9:29:48 PM12/11/18
to pdfium
Hi Lei,

Thanks.
It seems the font subsetting process should be implemented before font loading. I will try the workflow later.
Besides, is it possible to share the same font data for many pdf files. Then the overall size of these pdf files is smaller.
I don't know why FPDFPageObj_NewTextObj don't load font data to pdf file without chinese text. So for the english text the pdf file use the font data outside of the pdf file?


Thanks,
Bin 
Reply all
Reply to author
Forward
0 new messages