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

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

2008-03-12 16:27 1221 查看
注意:
浏览生成的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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: