pdflib版本:PDFlib-Lite-7.0.5p3
http://www.pdflib.com/download/free-software/pdflib-lite-7/
开发环境:VC++6.0
中文demo:
/*
* PDFlib client: hello example in C
PDFlib-Lite-7.0.5p3
*/
#include
#include
#include "pdflib.h"
int main(void)
{
PDF *p;
int font;
int font_ch;
/* create a new PDFlib object */
if ((p = PDF_new()) == (PDF *) 0)
{
printf("Couldn't create PDFlib object (out of memory)!\n");
return(2);
}
PDF_TRY(p) {
/* This means we must check return values of load_font() etc. */
PDF_set_parameter(p, "errorpolicy", "return");
PDF_set_parameter(p, "hypertextencoding", "host"); //--(增加位置)
if (PDF_begin_document(p, "hello.pdf", 0, "") == -1) {
printf("Error: %s\n", PDF_get_errmsg(p));
return(2);
}
/* This line is required to avoid problems on Japanese systems */
//PDF_set_parameter(p, "hypertextencoding", "host"); //--(注释位置)
PDF_set_info(p, "Creator", "hello.c");
PDF_set_info(p, "Author", "Thomas Merz");
PDF_set_info(p, "Title", "Hello, world (C)!");
PDF_begin_page_ext(p, a4_width, a4_height, "");
/* Change "host" encoding to "winansi" or whatever you need! */
font = PDF_load_font(p, "Helvetica-Bold", 0, "host", "");
if (font == -1) {
printf("Error: %s\n", PDF_get_errmsg(p));
PDF_delete(p);
return(2);
}
font_ch = PDF_load_font(p, "STSong-Light", 0, "GB-EUC-H", "");
if (font == -1) {
printf("Error: %s\n", PDF_get_errmsg(p));
PDF_delete(p);
return 0;
}
//=====================================
PDF_save(p);
PDF_setfont(p, font, 24);
PDF_set_text_pos(p, 50, 700);
PDF_show(p, "Hello, world!");
PDF_setfont(p, font_ch, 24);
PDF_continue_text(p, "您好,世界!");
PDF_restore(p);
//====================================
PDF_end_page_ext(p, "");
PDF_end_document(p, "");
}
PDF_CATCH(p) {
printf("PDFlib exception occurred in hello sample:\n");
printf("[%d] %s: %s\n",
PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
PDF_delete(p);
return(2);
}
PDF_delete(p);
return 0;
}