您的位置:逆风者 VC++ 正文
 添加时间:2007-09-01 原文发表:2007-08-31 人气:73 来源:vckbase.com

本文章共4306字,分3页,当前第2页,快速翻页:
 

下面是一个相关的例子--C 源程序
/*******************************************************************/

/* This example demostrates the usage of host font and other fonts

/* based on Chinese Simplifed Windows.

/*******************************************************************/



#include <stdio.h>

#include <stdlib.h>

#include <string.h>



#include "pdflib.h"



int main(void)

{

    PDF         *p = NULL;

    int             i = 0, j = 0, Left = 50, Top = 800;

    int             Font_E = 0, Font_CS = 0;

    char          fontfile[1024];

    char          buf[1024];

    char          TextUnicode[] = "\x80\x7B\x53\x4F\x2D\x4E\x87\x65";



    /* 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) {

	if (PDF_begin_document(p, "pdflib_cs2.pdf", 0, "") == -1) 

             {

	    printf("Error: %s\n", PDF_get_errmsg(p));

	    return(2);

	}



	PDF_set_info(p, "Creator", "pdflib_cs2.c");

	PDF_set_info(p, "Author", "myi@pdflib.com");

	PDF_set_info(p, "Title", "Output Chinese Simplify with host font and others");



        /* Start a new page. */

        PDF_begin_page_ext(p, a4_width, a4_height, "");

        Font_E = PDF_load_font(p, "Helvetica-Bold", 0, "winansi", "");



        /* Using host font -- C:\WINDOWS\Fonts\SimHei.ttf. 

           PDFlib is using BOM UTF8 string to calling multi-byte character string

           SimHei.ttf font name is "黑体", its corresponding BOM UTF8 string is 

           "\xEF\xBB\xBF\xE9\xBB\x91\xE4\xBD\x93" */



        Font_CS= PDF_load_font(p, "\xEF\xBB\xBF\xE9\xBB\x91\xE4\xBD\x93", 0, "unicode", "");

        /* Font_CS= PDF_load_font(p, "SimHei", 0, "unicode", ""); */

		

        PDF_setfont(p, Font_E, 20);

        PDF_show_xy(p, "SimHei font:" , Left,  Top);

        PDF_setfont(p, Font_CS, 24);

        Top-=30;

        PDF_show_xy(p, TextUnicode , Left,  Top);



        /* Using other disk-based font file that is not installed in system directory -- 

            C:\PSFONTS\CS\gkai00mp.ttf*/

        Top-=50;

        strcpy(fontfile, "C:\\PSFONTS\\CS\\gkai00mp.ttf");

        sprintf(buf, "kai=%s", fontfile);

        /* Defines kai as alias for ..\gkai00mp.ttf */

        PDF_set_parameter(p, "FontOutline", buf); 

        Font_CS= PDF_load_font(p, "kai", 0, "unicode", "");

        PDF_setfont(p, Font_E, 20);

        PDF_show_xy(p, "AR PL KaitiM GB  font:" , Left,  Top);

        PDF_setfont(p, Font_CS, 24);

        Top-=30;

        PDF_show_xy(p, TextUnicode , Left,  Top);



        /* Using TrueType collection font with index -- C:\WINDOWS\Fonts\simsun.ttc*/

        Top-=50;

        strcpy(fontfile, "C:\\WINDOWS\\Fonts\\simsun.ttc");

        sprintf(buf, "simsun=%s", fontfile);

        /* Defines AdobeSongStd as alias for ..\AdobeSongStd-Light.otf 

        This only need to claim once will be sufficient to 

		configure all fonts in simsun.ttc*/

        PDF_set_parameter(p, "FontOutline", buf); 

        /* TTC files contain multiple separate fonts.

        Address 1st font by appending a colon character and 0 after alias simsun */

        Font_CS= PDF_load_font(p, "simsun:0", 0, "unicode", "");

        PDF_setfont(p, Font_E, 20);

        PDF_show_xy(p, "simsun:0 font:", Left, Top);

        PDF_setfont(p, Font_CS, 24);

        Top-=30;

        PDF_show_xy2(p, TextUnicode, 8, Left,  Top);



        /*Address 2nd font by appending a colon character and 1 after alias simsun */

        Top-=50;

        Font_CS= PDF_load_font(p, "simsun:1", 0, "unicode", "");

        PDF_setfont(p, Font_E, 20);

        PDF_show_xy(p, "simsun:1 font:", Left, Top);

        PDF_setfont(p, Font_CS, 24);

        Top-=30;

        PDF_show_xy2(p, TextUnicode, 8, Left,  Top);



        /* End of page. */

        PDF_end_page_ext(p, "");

        PDF_end_document(p, "");

    }



    PDF_CATCH(p) {

        printf("PDFlib exception occurred in pdflib_cs2 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;

}
 
本文章更多内容<<上一页 - 1 - 2 - 3 - 下一页>>
相关文章

用 C 创建简单的 Win32 服务程序
DataGrid的客户端分页
真正的全动态报表:RDLC ReportViewer
COM 组件设计与应用(十六)——连接点(vc.
如何实现Office式样的扁平组合框
在EVC3.0中使用数据库
Brew 后台应用开发
VC中调用EXECL模板生成报表
在Visual C 中定制AppWizard (一)
连接 COM 与 .NET 的桥梁(一)——预备知识
层叠式窗体控件指南
基于 SSL 的 ASP.NET Web 应用测试自动化
Windows SDK笔记(七):创建MDI窗口
KVIP考勤系统
一个生成公章图片的简易工具
检测:.NET中强大的检测选项让你有信心建立

相关评论


本文章所属分类:首页 VC++

  热门关键字: