使用PDFLib生成PDF文档,C代码实例--画图形

#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;

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值