Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPDF_Page_TextRect Special character (German Umlaut) not display properly #27

Open
patelmaurya opened this issue Jan 16, 2013 · 9 comments

Comments

Projects
None yet
5 participants
@patelmaurya
Copy link

commented Jan 16, 2013

I am using libharu for iPad pdf functionality and i want to display german text (specially Umlaut characters) on pdf using HPDF_Page_TextRect. i have tried various combinations in code but not get success to display umlaut characters (üöäÄÜÖß).

If you have any solution for my issue please provide me.

@domfe

This comment has been minimized.

Copy link

commented Jan 16, 2013

What font are you using? Does it have those characters?
Try using an external true type font file and set haru to embed font glyphs

@patelmaurya

This comment has been minimized.

Copy link
Author

commented Jan 16, 2013

Hi i am using this kind of code where @"üöäÄÜÖß" replace with userinput values from UITextView and user may enter umlaut in text.

                HPDF_Font fontEn = HPDF_GetFont(pdf,"Helvetica-Bold", "StandardEncoding");
                HPDF_Page_SetFontAndSize(page1, fontEn, 11.0);
                HPDF_Page_TextRect (page1,10.0,460.0,530,430,
                                    [@"üöäÄÜÖß" UTF8String], HPDF_TALIGN_LEFT, NULL);
@domfe

This comment has been minimized.

Copy link

commented Jan 16, 2013

Try using this code
name=HPDF_LoadTTFontFromFile(doc, font_file_path, HPDF_TRUE);
font=HPDF_GetFont(doc, name, "UTF-8");

also see if this post fits to you
https://groups.google.com/forum/?fromgroups=#!topic/libharu/YzXoH_K3OAI

@patelmaurya

This comment has been minimized.

Copy link
Author

commented Jan 17, 2013

hi , thanks for the help...
now my code works with umlaut characters but if i want to use other then TTF font file then is it possible ?

@domfe

This comment has been minimized.

Copy link

commented Jan 17, 2013

hi.
You must use a font with umlaut chars. Don't use a Base14 font because you can't say if another machine has the same characters, specially for char with code > 127. I don't know if there's a Type1 font with umlaut chars, probably yes, however always embed the font glyphs.
You can use other encoding also, if the umlaut characters are represented in the font with one byte you can use an encoding that isn't multibyte (eg. one the ISO8859 series).

bye

@patelmaurya

This comment has been minimized.

Copy link
Author

commented Jan 17, 2013

Hi , one more issue i found that for first time if i load font from file and print the text and again try to load the another font and try to print the text with different font then its not working and error it.

code like

fontname = HPDF_LoadTTFontFromFile(pdf,[path UTF8String],HPDF_TRUE);
HPDF_UseUTFEncodings(pdf);
HPDF_SetCurrentEncoder(pdf, "UTF-8");
font = HPDF_GetFont(pdf, fontname, "UTF-8");
HPDF_Page_SetFontAndSize(page1, font,15.0);
HPDF_Page_TextRect (

again when load different font like below then not working.

fontname = HPDF_LoadTTFontFromFile(pdf,[path UTF8String],HPDF_TRUE);
HPDF_UseUTFEncodings(pdf);
HPDF_SetCurrentEncoder(pdf, "UTF-8");
font = HPDF_GetFont(pdf, fontname, "UTF-8");
HPDF_Page_SetFontAndSize(page1, font,15.0);
HPDF_Page_TextRect (

@domfe

This comment has been minimized.

Copy link

commented Jan 17, 2013

do use set an error handler?
https://github.com/libharu/libharu/wiki/Error-handling
if not, use the return value for each haru call and see what's wrong
eg.
ret=HPDF_UseUTFEncodings(pdf);
if(ret!=HPDF_OK)
; // error, see value of ret

for HPDF_LoadTTFontFromFile and HPDF_GetFont use this code to get the error
if(fontname==NULL) // or if(font==NULL)
ret=doc->error.error_no;

now, what the error says? what function generates error?

@mklemarczyk mklemarczyk added the problem label Jun 26, 2015

@anhtuantt

This comment has been minimized.

Copy link

commented May 21, 2016

Hello everyone,
I'm using Libharu to generate PDF report that support Chinese language. Everything is fine if only one Chinese font is embedded. But i got the error at embedding the second Chinese font. The first time:
HPDF_LoadTTFontFromFile(outputFile, "c:/Windows/fonts/msyh.ttf", HPDF_TRUE);
everything is OK, the Chinese language is correctly displayed.
After that, i embed the second font (BOLD version)
HPDF_LoadTTFontFromFile(outputFile, "c:/Windows/fonts/msyhbd.ttf", HPDF_TRUE), the problem gets the exception with error code 0x1025 HPDF_INVALID_DOCUMENT with that command.
Please give me any advice or solution. If i understand the problem, i could try to fix it and contribute back to this wonderful library.

@dab0bby

This comment has been minimized.

Copy link

commented Sep 29, 2017

This is my solution working perfectly with UTF-8:

HPDF_UseUTFEncodings(_pdf);
auto font = HPDF_LoadTTFontFromFile(_pdf, (_pathToAssets + "calibri.ttf").data(), HPDF_TRUE);
_font = HPDF_GetFont(_pdf, font, "UTF-8");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.