2.1 官方范例学习《hello》
来源:互联网 发布:润知文化传播有限公司 编辑:程序博客网 时间:2024/05/22 10:28
一 本例研究的内容:
- [1]创建/保存PDF
- [2]创建页面/简单设置
- [3]设置文档属性
- [4]简单那输出文本,换行
二 本例缺陷:
- [1]文本输出中文乱码
[2]文档属性中文乱码
缺陷将在下篇研究,尝试解决
三 示例
**环境配置参见此系列第一篇****讲解参见注释**
#include "stdafx.h"#include "pdflib.h"#include <afxwin.h>int main(){ PDF *p; int font; /* 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. */ /* errorpolicy:(关键字)控制出现错误时各种函数的行为。 return 如果发生错误,函数将返回。 */ PDF_set_option(p, "errorpolicy=return"); /* 1.PDF_begin_document() 与 PDF_end_document()成堆出现 简单形式PDF_begin_document(p,"创建的PDF文件名,不能为中文(目前),0,""),后面两个参数暂时用不到,先如此写。 2.PDF_get_errmsg(p) 获取上一个出错的原因,配套的还有PDF_get_errnum(p)获取出错代码,然而知道代码有什么卵用,还不如msg */ 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 */ /*hypertextencoding 超文本字符串编码,默认值是auto,至于为什么是host?在文档中说的我没有找到,暂且认为是“避免在日语系统上出错”吧”*/ PDF_set_option(p, "hypertextencoding=host"); /*设置文档信息:右键->文档属性 查看 Creator->应用程序: Author->作者: Title->标题: Subject:主题 Keywords:关键字 */ PDF_set_info(p, "Creator", "hello.cc"); PDF_set_info(p, "Author", "skysun"); PDF_set_info(p, "Title", "Hello, world (C)!"); /*设置页面属性,宽高:a4大小,宏定义了a0~a6,b2~b5的大小,optlist暂时为空*/ 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); } /*设置字体与字号*/ PDF_setfont(p, font, 24); /*设置文字出现在文档中的位置 默认左下角为坐标原点 若想更改为从左上角为坐标原点,则应在PDF_begin_page_ext()函数前设置 PDF_set_option(p, "topdown=true"); */ PDF_set_text_pos(p, 50, 700); /* PDF_show() 在页面上输出内容,必须先设置好PDF_setfont() */ PDF_show(p, "Hello, world!"); /*下一行打印*/ PDF_continue_text(p, "(says C)"); /* 和begin函数要配对嘛,这年头函数都出来虐狗 */ PDF_end_page_ext(p, ""); /* 那么如何开启下一页呢? 很简单,再来一个 PDF_begin_page_ext(); PDF_end_page_ext(); */ PDF_end_document(p, ""); } PDF_CATCH(p) { /* PDF_get_apiname(p)获取出错的api名字 */ 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); } /* new完就删,真tm爽 */ PDF_delete(p); /* 打开生成的pdf,方便调试 */ system("hello.pdf"); return 0;}
0 0
- 2.1 官方范例学习《hello》
- samtools学习及使用范例,以及官方文档详解
- NDK范例hello-jni
- NOKIA官方范例
- Gora官方范例
- Gora官方范例
- Google官方提供的有用的Android范例程序,值得学习的新技术
- 动态桌面官方范例源代码 —— CubeWallpaper
- opencv官方范例之calHist()
- Handler官方范例AsyncQueryHandler源码解析
- XmlHttp学习范例
- 范例学习SIP
- HMM学习范例
- qsort范例学习
- HMM 学习最佳范例
- HMM学习最佳范例
- HMM学习最佳范例
- HMM学习最佳范例
- 南阳oj 155 高精度幂
- git提交代码详细过程
- C/C++不是类型安全的!
- 第十周项目1---二叉树的算法库
- luogu【P1007】独木桥
- 2.1 官方范例学习《hello》
- 突如其来的变化
- jQuery appendTo() 无效(不生效)如何解决
- Activity之task-----by 安仔
- 《算法》第一章——Dijkstra双栈表达式求值
- 第十周项目2---二叉树遍历的递归算法
- lightoj 1066 - Gathering Food
- 实用 .htaccess 用法大全
- NYOJ 218 Dinner