0

I want to get a pdf with Russina text. VS2010 use libharu

My source code file is encoded as Cyrillic(ISO) Use this code to set font and encoding

detail_font = HPDF_GetFont(pdf, "Times-Roman", "ISO8859-5");

The full code :

int main (int argc, char **argv)
    {
    HPDF_Doc  pdf;
    char fname[256];
    HPDF_Page page;
    HPDF_Font title_font;
    HPDF_Font detail_font;
    HPDF_UINT page_height = 400;
    HPDF_UINT page_width = 400;
    const char *detail_font_name;

    strcpy (fname, "encoding");
    strcat (fname, ".pdf");

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }

    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }

    page = HPDF_AddPage (pdf);
    detail_font = HPDF_GetFont(pdf, "Times-Roman", "ISO8859-5");
    HPDF_Page_BeginText (page);

    /* move the position of the text to top of the page. */
    HPDF_Page_MoveTextPos(page, 10, 280);

    HPDF_Page_SetFontAndSize (page, detail_font, 16);
    HPDF_Page_MoveTextPos (page, 0, -20);
    HPDF_Page_ShowText(page,"регистратор температуры ");
    HPDF_Page_SetWidth (page, page_width);
    HPDF_Page_SetHeight (page, page_height);

    /* finish to print text. */
    HPDF_Page_EndText (page);
    HPDF_SaveToFile (pdf, fname);

    /* clean up */
    HPDF_Free (pdf);

    return 0;
}

I get a abnormal pdf with Russian text.

enter image description here

How to solved this problem? My source files encoding is not available? I can get a normal pdf with Russian text by utf-8 encoding but the font is embeded in my PDF ,so i can not choose utf-8.

characters can be displayed but they overlap

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

1 Answers1

0

I read the pdf by txt style. check that

/Type /Font
/BaseFont /Times-Bold
/Subtype /Type1
/FirstChar 32
/LastChar 255
/Widths [
250 333 555 500 500 1000 833 278 333 333 500 570 250 333 250 278 
500 500 500 500 500 500 500 500 500 500 333 333 570 570 570 500 
930 722 667 722 722 667 611 778 778 389 500 778 667 944 722 778 
611 778 722 556 667 722 722 1000 722 722 667 333 278 333 581 500 
333 500 556 444 556 444 333 500 556 278 333 556 278 833 556 500 
556 556 444 389 333 556 500 722 500 500 444 394 220 394 520 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 
250 250 250 250 250 250 250 250 250 250 250 250 250 500 250 250 
]

Russina text is from 176~256. Should modify 176~256 width like this widths array

/Widths [
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600
250 600 250 250 250 250 250 250 250 250 250 250 250 250 250 250
600 600 600 600 600 600 900 600 600 600 600 600 700 600 700 600
600 600 600 600 600 600 700 600 800 880 800 800 600 600 600 600
500 500 500 480 540 500 600 500 500 500 500 500 600 600 500 500
500 500 500 500 800 500 580 500 700 800 700 600 600 500 600 500
800 600 600 600 600 600 600 600 600 600 600 600 600 500 600 600
]

Certanily,i fill the array by 600 and change the Russian character width which i like.