您的位置:首页 > 编程语言

使用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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: