使用PDFLib生成PDF文档,C代码实例--画图形
2015-05-26 20:14
821 查看
#include <stdio.h>
#include <stdlib.h>
#include "pdflib.h"
#include <math.h>
#include <windows.h>
#include <WinBase.h>
#include <sys/stat.h>
Int main(void)
{
draw();
return 0;
}
int draw()
{
PDF *p;
int i, font;
int handle;
double result;
char str[100], *pStr;
int nSize;
char fontfile[1024];
char buf[1024];
if ((p = PDF_new()) == (PDF *) 0)
{
printf("Couldn't create PDFlib object (out of memory)!/n");
return(2);
}
PDF_TRY(p) {
PDF_set_parameter(p, "errorpolicy", "return");
if (PDF_begin_document(p, "d://hello.pdf", 0, "") ==
-1) {
printf("Error: %s/n", PDF_get_errmsg(p));
return(2);
}
PDF_set_parameter(p, "hypertextencoding", "host");
PDF_set_parameter(p, "fakebold", "true");
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, "");
PDF_setcolor(p, "stroke", "cmyk", 0, 0, 0, 1);
PDF_setlinewidth(p, 4);
PDF_moveto(p , 100, 100);
PDF_lineto(p , 500, 500);
PDF_stroke(p);
PDF_setcolor(p, "fill", "cmyk", 0, 0, 1, 0);
PDF_arc(p, 100, 500, 50, 0, 360);
PDF_moveto(p , 0, 0);
PDF_rect(p, 200, 500, 50, 10);
PDF_fill(p);
PDF_setcolor(p, "fill", "cmyk", 0, 1, 1, 0);
PDF_rect(p, 300, 500, 50, 10);
PDF_closepath(p);
PDF_fill(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);
getchar();
return(2);
}
PDF_delete(p);
execl("C://Program Files//Adobe//Acrobat 7.0//Acrobat//Acrobat.exe",
"_execl",
"d://hello.pdf", NULL, NULL);
return 0;
}
#include <stdlib.h>
#include "pdflib.h"
#include <math.h>
#include <windows.h>
#include <WinBase.h>
#include <sys/stat.h>
Int main(void)
{
draw();
return 0;
}
int draw()
{
PDF *p;
int i, font;
int handle;
double result;
char str[100], *pStr;
int nSize;
char fontfile[1024];
char buf[1024];
if ((p = PDF_new()) == (PDF *) 0)
{
printf("Couldn't create PDFlib object (out of memory)!/n");
return(2);
}
PDF_TRY(p) {
PDF_set_parameter(p, "errorpolicy", "return");
if (PDF_begin_document(p, "d://hello.pdf", 0, "") ==
-1) {
printf("Error: %s/n", PDF_get_errmsg(p));
return(2);
}
PDF_set_parameter(p, "hypertextencoding", "host");
PDF_set_parameter(p, "fakebold", "true");
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, "");
PDF_setcolor(p, "stroke", "cmyk", 0, 0, 0, 1);
PDF_setlinewidth(p, 4);
PDF_moveto(p , 100, 100);
PDF_lineto(p , 500, 500);
PDF_stroke(p);
PDF_setcolor(p, "fill", "cmyk", 0, 0, 1, 0);
PDF_arc(p, 100, 500, 50, 0, 360);
PDF_moveto(p , 0, 0);
PDF_rect(p, 200, 500, 50, 10);
PDF_fill(p);
PDF_setcolor(p, "fill", "cmyk", 0, 1, 1, 0);
PDF_rect(p, 300, 500, 50, 10);
PDF_closepath(p);
PDF_fill(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);
getchar();
return(2);
}
PDF_delete(p);
execl("C://Program Files//Adobe//Acrobat 7.0//Acrobat//Acrobat.exe",
"_execl",
"d://hello.pdf", NULL, NULL);
return 0;
}
相关文章推荐
- 使用PDFLib生成PDF文档,C代码实例--画图形
- 使用PDFLib生成PDF文档,C代码实例--使用特色
- 使用PDFLib生成PDF文档,C代码实例--使用特色
- PHP中使用TCPDF生成PDF文档实例
- 使用PDFLib生成PDF文档(C语言版)
- 使用PDFLib生成PDF文档教程
- 使用PDFLib生成PDF文档教程
- PHP中使用TCPDF生成PDF文档实例
- PHP中使用TCPDF生成PDF文档实例
- 使用PDFLib生成PDF文档
- Java使用Flying Saucer实现HTML代码生成PDF文档
- Java使用wkhtmltox实现HTML代码生成PDF文档或者图片
- 使用PDFLib生成PDF文档(C语言版)--使用指导
- iTEXT生成PDF文件使用方法 实例 示例 Servlet输出PDF文档方法
- Java使用wkhtmltox实现HTML代码生成PDF文档或者图片
- 使用C#给PDF文档添加注释的实现代码
- 使用Dcxygen对代码进行文档自动生成
- 使用GitBook工具生成PDF格式的文档
- Doxygen代码文档生成工具简单介绍与使用
- 使用wsimport命令生成webService客户端代码实例