使用PDFLib生成PDF文档,C代码实例--使用特色

注意:

览生成的PDF文件时,要看到特色的效果,需要设置 Acrobat或AcroReader的OverPrint 属性,大概位置在 编辑->高级 中,版本不同具体位置也不同。

#include <stdio.h>

int SpotColor()

{

     PDF *p;

     int i, font;

     int handle;

     int x, y;

 

     /* 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. */

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

         }

 

         /* This line is required to avoid problems on Japanese systems */

         PDF_set_parameter(p, "hypertextencoding""host");

         PDF_set_parameter(p, "fakebold""true");

 

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

         PDF_set_info(p, "Author""");

         PDF_set_info(p, "Title""");

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

       {

              PDF_setcolor(p, "stroke""cmyk", 0, 0, 1, 0);

              PDF_moveto(p, 50, 620);

              PDF_lineto(p, 200, 620);

              PDF_stroke(p);

 

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "stroke""spot", handle, 0.5, 0, 0);

              PDF_setcolor(p, "stroke""cmyk", 0, 1, 0, 0);

              PDF_moveto(p, 100, 620);

              PDF_lineto(p, 250, 620);

 

              PDF_stroke(p);

              PDF_setcolor(p, "stroke""cmyk", 1, 0, 0, 0);

              PDF_moveto(p, 150, 620);

              PDF_lineto(p, 300, 620);

 

              PDF_stroke(p);

 

              PDF_setcolor(p, "fill""cmyk", 0, 0, 1, 0);

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "fill""spot", handle, 0.4, 0, 0);

              PDF_moveto(p, 50, 600);

              PDF_lineto(p, 200, 600);

              PDF_lineto(p, 200, 550);

              PDF_lineto(p, 50, 550);

 

              PDF_fill(p);

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "fill""spot", handle, 0.5, 0, 0);

              PDF_setcolor(p, "fill""cmyk", 0, 1, 0, 0);

              PDF_moveto(p, 100, 600);

              PDF_lineto(p, 250, 600);

              PDF_lineto(p, 250, 550);

              PDF_lineto(p, 100, 550);

 

              PDF_fill(p);

 

              PDF_setcolor(p, "fill""cmyk", 1, 0, 0, 0);

              PDF_moveto(p, 150, 600);

              PDF_lineto(p, 300, 600);

              PDF_lineto(p, 300, 550);

              PDF_lineto(p, 150, 550);

 

              PDF_fill(p);

 

         }

        

         {

              handle = PDF_create_gstate(p, "overprintmode=1");

              PDF_set_gstate(p, handle);

 

 

              PDF_setcolor(p, "stroke""cmyk", 0, 0, 1, 0);

 

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "stroke""spot", handle, 0.5, 0, 0);

 

              PDF_moveto(p, 50, 520);

              PDF_lineto(p, 200, 520);

 

              PDF_stroke(p);

 

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "stroke""spot", handle, 0.5, 0, 0);

              PDF_setcolor(p, "stroke""cmyk", 0, 1, 0, 0);

              PDF_moveto(p, 100, 520);

              PDF_lineto(p, 250, 520);

 

              PDF_stroke(p);

 

 

              PDF_setcolor(p, "stroke""cmyk", 1, 0, 0, 0);

              PDF_moveto(p, 150, 520);

              PDF_lineto(p, 300, 520);

 

              PDF_stroke(p);

 

 

              handle = PDF_create_gstate(p, "overprintfill=true");

              PDF_set_gstate(p, handle);

 

              PDF_setcolor(p, "fill""cmyk", 0, 0, 1, 0);

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "fill""spot", handle, 0.4, 0, 0);

 

              PDF_moveto(p, 50, 500);

              PDF_lineto(p, 200, 500);

              PDF_lineto(p, 200, 450);

              PDF_lineto(p, 50, 450);

 

              PDF_fill(p);

 

 

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "fill""spot", handle, 0.5, 0, 0);

              PDF_setcolor(p, "fill""cmyk", 0, 1, 0, 0);

              PDF_moveto(p, 100, 500);

              PDF_lineto(p, 250, 500);

              PDF_lineto(p, 250, 450);

              PDF_lineto(p, 100, 450);

 

              PDF_fill(p);

 

 

              PDF_setcolor(p, "fill""cmyk", 1, 0, 0, 0);

              PDF_moveto(p, 150, 500);

              PDF_lineto(p, 300, 500);

              PDF_lineto(p, 300, 450);

              PDF_lineto(p, 150, 450);

 

              PDF_fill(p);

         }

        

 

         {

              handle = PDF_create_gstate(p, "overprintstroke=true");

              PDF_set_gstate(p, handle);

 

 

              PDF_setcolor(p, "stroke""cmyk", 0, 0, 1, 0);

 

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "stroke""spot", handle, 0.5, 0, 0);

 

              PDF_moveto(p, 50, 420);

              PDF_lineto(p, 200, 420);

              PDF_stroke(p);

 

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "stroke""spot", handle, 0.5, 0, 0);

              PDF_setcolor(p, "stroke""cmyk", 0, 1, 0, 0);

              PDF_moveto(p, 100, 420);

              PDF_lineto(p, 250, 420);

 

              PDF_stroke(p);

 

 

              PDF_setcolor(p, "stroke""cmyk", 1, 0, 0, 0);

              PDF_moveto(p, 150, 420);

              PDF_lineto(p, 300, 420);

 

              PDF_stroke(p);

 

 

              handle = PDF_create_gstate(p, "overprintfill=false");

              PDF_set_gstate(p, handle);

 

              PDF_setcolor(p, "fill""cmyk", 0, 0, 1, 0);

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "fill""spot", handle, 0.4, 0, 0);

 

              PDF_moveto(p, 50, 400);

              PDF_lineto(p, 200, 400);

              PDF_lineto(p, 200, 350);

              PDF_lineto(p, 50, 350);

 

              PDF_fill(p);

 

 

              handle = PDF_makespotcolor(p, "PANTONE 871 C", 0);

              PDF_setcolor(p, "fill""spot", handle, 0.5, 0, 0);

              PDF_setcolor(p, "fill""cmyk", 0, 1, 0, 0);

              PDF_moveto(p, 100, 400);

              PDF_lineto(p, 250, 400);

              PDF_lineto(p, 250, 350);

              PDF_lineto(p, 100, 350);

 

              PDF_fill(p);

 

 

              PDF_setcolor(p, "fill""cmyk", 1, 0, 0, 0);

              PDF_moveto(p, 150, 400);

              PDF_lineto(p, 300, 400);

              PDF_lineto(p, 300, 350);

              PDF_lineto(p, 150, 350);

 

              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>

Int  main(void)

{

    SpotColor();

     return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值