void pdf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) { internal_t*i = (internal_t*)dev->internal; reset_matrix(i); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); /* pdf-x (pdf 1.3) doesn't support opacityfill if(color->a!=255) { char opacityfill[80]; sprintf(opacityfill, "opacityfill %f", color->a/256.0); int gstate = PDF_create_gstate(i->p, opacityfill); PDF_set_gstate(i->p, gstate); }*/ if(mkline(line, i->p, i->config_xpad, i->config_ypad, 1.0, 1)) { PDF_fill(i->p); } }
void pdf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix) { internal_t*i = (internal_t*)dev->internal; if(!font) return; gfxglyph_t*glyph = &font->glyphs[glyphnr]; char as_shape = 0; if(!type3 && !ttf) {msg("<warning> No type3 enabled. Drawing char %d as shape", glyphnr);as_shape=1;} if(glyphnr>256-32) {msg("<warning> Drawing char %d as shape (not < 224)", glyphnr);as_shape=1;} if(as_shape) { reset_matrix(i); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); gfxline_t*line2 = gfxline_clone(glyph->line); gfxline_transform(line2, matrix); if(mkline(line2, i->p, i->config_xpad, i->config_ypad, 1.0, 1)) { PDF_fill(i->p); } gfxline_free(line2); } else { assert(gfxfontlist_hasfont(i->fontlist, font)); int fontid = (int)(ptroff_t)gfxfontlist_getuserdata(i->fontlist, font->id); gfxmatrix_t m = *matrix; m.m00*=64; m.m01*=64; m.m10*=64; m.m11*=64; if(ttf) { m.m10 = -m.m10; m.m11 = -m.m11; } if(!(fabs(m.m00 - i->m00) < 1e-6 && fabs(m.m01 - i->m01) < 1e-6 && fabs(m.m10 - i->m10) < 1e-6 && fabs(m.m11 - i->m11) < 1e-6)) { set_matrix(i, m.m00, m.m01, m.m10, m.m11); } double tx, ty; transform_back(i, m.tx+i->config_xpad, m.ty+i->config_ypad, &tx, &ty); PDF_setfont(i->p, fontid, ttf?16.0:1.0); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); char name[32]; sprintf(name, "%c", glyphnr+32); if(fabs(tx - i->lastx) > 0.001 || ty != i->lasty) { PDF_show_xy2(i->p, name, strlen(name), tx, ty); } else { PDF_show2(i->p, name, strlen(name)); } i->lastx = tx + glyph->advance; i->lasty = ty; } }
void pdf_addfont(gfxdevice_t*dev, gfxfont_t*font) { internal_t*i = (internal_t*)dev->internal; int num = font->num_glyphs<256-32?font->num_glyphs:256-32; if(type3) { int fontid = 0; if(!gfxfontlist_hasfont(i->fontlist, font)) { static int fontnr = 1; char fontname[32]; sprintf(fontname, "font%d", fontnr++); int l = strlen(fontname); char fontname2[64]; int t; for(t=0;t<l+1;t++) { fontname2[t*2+0] = fontname[t]; fontname2[t*2+1] = 0; } PDF_begin_font(i->p, fontname2, l*2, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, ""); for(t=0;t<num;t++) { gfxglyph_t*g = &font->glyphs[t]; gfxbbox_t bbox = gfxline_getbbox(g->line); char name[32]; sprintf(name, "chr%d", t+32); PDF_encoding_set_char(i->p, fontname, t+32, name, 0); PDF_begin_glyph(i->p, name, g->advance, bbox.xmin/64.0, bbox.ymin/64.0, bbox.xmax/64.0, bbox.ymax/64.0); if(mkline(g->line, i->p, 0, 0, 1.0/64.0, 1)) PDF_fill(i->p); PDF_end_glyph(i->p); } PDF_end_font(i->p); fontid = PDF_load_font(i->p, fontname2, l*2, fontname, ""); i->fontlist = gfxfontlist_addfont2(i->fontlist, font, (void*)(ptroff_t)fontid); } } else if(ttf) { int fontid = 0; if(!gfxfontlist_hasfont(i->fontlist, font)) { char fontname[32],filename[32],fontname2[64]; static int fontnr = 1; sprintf(fontname, "font%d", fontnr); sprintf(filename, "font%d.ttf", fontnr); fontnr++; const char*old_id = font->id; font->id = fontname; int t; for(t=0;t<num;t++) { font->glyphs[t].unicode = 32+t; } font->max_unicode = 0; font->unicode2glyph = 0; gfxfont_save(font, filename); font->id=old_id; #ifdef RUN_TTX /* for testing the generated fonts: run everything through ttx (fonttools) */ char cmd[256]; sprintf(cmd, "mv %s.ttf test.ttf", fontname);system(cmd); system("rm -f test.ttx"); if(system("ttx test.ttf")&0xff00) exit(1); sprintf(cmd, "mv test.ttf %s.old.ttf", fontname, fontname);system(cmd); sprintf(cmd, "ttx test.ttx;mv test.ttf %s.ttf", fontname);system(cmd); sprintf(cmd, "rm -f test.ttx");system(cmd); #endif int l = strlen(fontname); for(t=0;t<l+1;t++) { fontname2[t*2+0] = fontname[t]; fontname2[t*2+1] = 0; } fontid = PDF_load_font(i->p, fontname2, l*2, "host", "embedding=true"); i->fontlist = gfxfontlist_addfont2(i->fontlist, font, (void*)(ptroff_t)fontid); unlink(filename); } } }
/* ** cg_cut_lines() ** Write the cut lines in a page. */ yerr_t cg_cut_lines(cg_t *carta, cg_deck_t *deck, cg_back_t back) { int i; double color_luminance = 0; /* hidden-ditch */ PDF_save(carta->p); if ((back == BACK_NO && deck->ditch_odd) || (back != BACK_NO && deck->ditch_even)) { unsigned int hex1, hex2, hex3; double col1, col2, col3; char *used_color = (back == BACK_NO) ? deck->ditch_odd : deck->ditch_even; sscanf(used_color, "#%02x%02x%02x", &hex1, &hex2, &hex3); col1 = (double)hex1 / 255; col2 = (double)hex2 / 255; col3 = (double)hex3 / 255; color_luminance = (col1 * LUMINANCE_RED) + (col2 * LUMINANCE_GREEN) + (col3 * LUMINANCE_BLUE); PDF_setcolor(carta->p, "fill", "rgb", col1, col2, col3, 0.0); PDF_rect(carta->p, YVAL2PT(deck->paper_margin_w) / 2.0, YVAL2PT(deck->paper_margin_h) / 2.0, YVAL2PT(deck->paper_width) - YVAL2PT(deck->paper_margin_w), YVAL2PT(deck->paper_height) - YVAL2PT(deck->paper_margin_h)); PDF_fill(carta->p); } PDF_restore(carta->p); /* external cut lines */ PDF_save(carta->p); PDF_setcolor(carta->p, "fillstroke", "rgb", 0.0, 0.0, 0.0, 0.0); for (i = 0; i <= deck->cols; ++i) { double x, y; if (i == deck->cols && YVAL2PT(deck->space_width)) break ; x = YVAL2PT(deck->paper_margin_w) + (i * YVAL2PT(deck->card_width)) + (i * YVAL2PT(deck->space_width)); if (back == BACK_HEIGHT || back == BACK_WIDTH) x = YVAL2PT(deck->paper_width) - YVAL2PT(deck->paper_margin_w) - (i * YVAL2PT(deck->card_width)) - (i * YVAL2PT(deck->space_width)); y = 0.0; PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_margin_h) / 2.0; PDF_lineto(carta->p, x, y); y = YVAL2PT(deck->paper_height); PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_height) - (YVAL2PT(deck->paper_margin_h) / 2.0); PDF_lineto(carta->p, x, y); /* second cut line - space between cards */ if (i < deck->cols && YVAL2PT(deck->space_width)) { if (back == BACK_HEIGHT || back == BACK_WIDTH) x -= YVAL2PT(deck->card_width); else x += YVAL2PT(deck->card_width); y = 0.0; PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_margin_h) / 2.0; PDF_lineto(carta->p, x, y); y = YVAL2PT(deck->paper_height); PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_height) - (YVAL2PT(deck->paper_margin_h) / 2.0); PDF_lineto(carta->p, x, y); } } for (i = 0; i <= deck->rows; ++i) { double x, y; if (i == deck->rows && YVAL2PT(deck->space_height)) break ; x = 0.0; y = YVAL2PT(deck->paper_margin_h) + (i * YVAL2PT(deck->card_height)) + (i * YVAL2PT(deck->space_height)); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_margin_w) / 2.0; PDF_lineto(carta->p, x, y); x = YVAL2PT(deck->paper_width); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_width) - (YVAL2PT(deck->paper_margin_w) / 2.0); PDF_lineto(carta->p, x, y); /* second cut line - space between cards */ if (i < deck->rows && YVAL2PT(deck->space_height)) { x = 0.0; y += YVAL2PT(deck->card_height); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_margin_w) / 2.0; PDF_lineto(carta->p, x, y); x = YVAL2PT(deck->paper_width); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_width) - (YVAL2PT(deck->paper_margin_w) / 2.0); PDF_lineto(carta->p, x, y); } } PDF_stroke(carta->p); PDF_restore(carta->p); /* internal cut lines */ PDF_save(carta->p); if (color_luminance >= LUMINANCE_THRESHOLD) PDF_setcolor(carta->p, "fillstroke", "rgb", 0.0, 0.0, 0.0, 0.0); else PDF_setcolor(carta->p, "fillstroke", "rgb", 1.0, 1.0, 1.0, 0.0); for (i = 0; i <= deck->cols; ++i) { double x, y; if (i == deck->cols && YVAL2PT(deck->space_width)) break ; x = YVAL2PT(deck->paper_margin_w) + (i * YVAL2PT(deck->card_width)) + (i * YVAL2PT(deck->space_width)); if (back == BACK_HEIGHT || back == BACK_WIDTH) x = YVAL2PT(deck->paper_width) - YVAL2PT(deck->paper_margin_w) - (i * YVAL2PT(deck->card_width)) - (i * YVAL2PT(deck->space_width)); y = YVAL2PT(deck->paper_margin_h) / 2.0; PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0; PDF_lineto(carta->p, x, y); y = YVAL2PT(deck->paper_height) - (YVAL2PT(deck->paper_margin_h) / 2.0); PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_height) - (YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0); PDF_lineto(carta->p, x, y); /* second cut line - space between cards */ if (i < deck->cols && YVAL2PT(deck->space_width)) { if (back == BACK_HEIGHT || back == BACK_WIDTH) x -= YVAL2PT(deck->card_width); else x += YVAL2PT(deck->card_width); y = YVAL2PT(deck->paper_margin_h) / 2.0; PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0; PDF_lineto(carta->p, x, y); y = YVAL2PT(deck->paper_height) - (YVAL2PT(deck->paper_margin_h) / 2.0); PDF_moveto(carta->p, x, y); y = YVAL2PT(deck->paper_height) - (YVAL2PT(deck->paper_margin_h) * 2.0 / 3.0); PDF_lineto(carta->p, x, y); } } for (i = 0; i <= deck->rows; ++i) { double x, y; if (i == deck->rows && YVAL2PT(deck->space_height)) break ; x = YVAL2PT(deck->paper_margin_w) / 2.0; y = YVAL2PT(deck->paper_margin_h) + (i * YVAL2PT(deck->card_height)) + (i * YVAL2PT(deck->space_height)); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0; PDF_lineto(carta->p, x, y); x = YVAL2PT(deck->paper_width) - (YVAL2PT(deck->paper_margin_w) / 2.0); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_width) - (YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0); PDF_lineto(carta->p, x, y); /* second cut line - space between cards */ if (i < deck->rows && YVAL2PT(deck->space_height)) { x = YVAL2PT(deck->paper_margin_w) / 2.0; y += YVAL2PT(deck->card_height); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0; PDF_lineto(carta->p, x, y); x = YVAL2PT(deck->paper_width) - (YVAL2PT(deck->paper_margin_w) / 2.0); PDF_moveto(carta->p, x, y); x = YVAL2PT(deck->paper_width) - (YVAL2PT(deck->paper_margin_w) * 2.0 / 3.0); PDF_lineto(carta->p, x, y); } } PDF_stroke(carta->p); PDF_restore(carta->p); return (YENOERR); }
int main(void) { PDF *p; float alpha; time_t timer; struct tm ltime; /* 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) { /* open new PDF file */ if (PDF_open_file(p, "pdfclock.pdf") == -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_info(p, "Creator", "pdfclock.c"); PDF_set_info(p, "Author", "Thomas Merz"); PDF_set_info(p, "Title", "PDF clock (C)"); PDF_begin_page(p, (float) (2 * (RADIUS + MARGIN)), (float) (2 * (RADIUS + MARGIN))); PDF_translate(p, RADIUS + MARGIN, RADIUS + MARGIN); PDF_setcolor(p, "fillstroke", "rgb", 0, 0, 1, 0); PDF_save(p); /* minute strokes */ PDF_setlinewidth(p, 2); for (alpha = 0; alpha < 360; alpha += 6) { PDF_rotate(p, 6); PDF_moveto(p, RADIUS, 0); PDF_lineto(p, (float) (RADIUS-MARGIN/3), 0); PDF_stroke(p); } PDF_restore(p); PDF_save(p); /* 5 minute strokes */ PDF_setlinewidth(p, 3); for (alpha = 0; alpha < 360; alpha += 30) { PDF_rotate(p, 30); PDF_moveto(p, RADIUS, 0); PDF_lineto(p, RADIUS-MARGIN, 0); PDF_stroke(p); } time(&timer); ltime = *localtime(&timer); /* draw hour hand */ PDF_save(p); PDF_rotate(p, (float)(-((ltime.tm_min/60.0) + ltime.tm_hour - 3.0) * 30.0)); PDF_moveto(p, -RADIUS/10, -RADIUS/20); PDF_lineto(p, RADIUS/2, 0); PDF_lineto(p, -RADIUS/10, RADIUS/20); PDF_closepath(p); PDF_fill(p); PDF_restore(p); /* draw minute hand */ PDF_save(p); PDF_rotate(p, (float) (-((ltime.tm_sec/60.0) + ltime.tm_min - 15.0) * 6.0)); PDF_moveto(p, -RADIUS/10, -RADIUS/20); PDF_lineto(p, RADIUS * 0.8f, 0); PDF_lineto(p, -RADIUS/10, RADIUS/20); PDF_closepath(p); PDF_fill(p); PDF_restore(p); /* draw second hand */ PDF_setcolor(p, "fillstroke", "rgb", 1, 0, 0, 0); PDF_setlinewidth(p, 2); PDF_save(p); PDF_rotate(p, (float) -((ltime.tm_sec - 15.0) * 6.0)); PDF_moveto(p, -RADIUS/5, 0); PDF_lineto(p, RADIUS, 0); PDF_stroke(p); PDF_restore(p); /* draw little circle at center */ PDF_circle(p, 0, 0, (float) RADIUS/30); PDF_fill(p); PDF_restore(p); PDF_end_page(p); PDF_close(p); } PDF_CATCH(p) { printf("PDFlib exception occurred in pdfclock sample:\n"); printf("[%d] %s: %s\n", PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p)); PDF_delete(p); return(2); } PDF_delete(p); /* delete the PDFlib object */ return 0; }
int main(int argc, char *argv[]) { char *pdffilename = NULL; char *imagetype = "auto"; char *useroptions = ""; PDF *p; int image; #ifndef PDFLIB_LITE int tagged, opt; int item=0; char *pdfalevel = NULL, *intent = "sRGB"; #endif /* PDFLIB_LITE */ int resolution = 0; int page_numbering = 0; double graylevel = -1.0; int frame; int current_page = 1; #define BUFLEN 1024 char optlist[BUFLEN]; char buf[BUFLEN]; #ifndef PDFLIB_LITE while ((opt = getopt(argc, argv, "a:g:I:i:o:p:r:t:")) != -1) #else while ((opt = getopt(argc, argv, "g:i:o:p:r:t:")) != -1) #endif /* PDFLIB_LITE */ switch (opt) { #ifndef PDFLIB_LITE case 'a': if (strcmp(optarg, "none")) pdfalevel = optarg; break; #endif /* PDFLIB_LITE */ case 'g': if (optarg) { graylevel = atof(optarg); if (graylevel < 0.0 || graylevel > 1.0) { fprintf(stderr, "Error: Bad gray level %.2g for -g.\n", graylevel); usage(); } } break; #ifndef PDFLIB_LITE case 'I': if (!strcmp(optarg, "none")) intent = NULL; else intent = optarg; break; #endif /* PDFLIB_LITE */ case 'i': useroptions = optarg; if (strlen(useroptions) > BUFLEN-20) { fprintf(stderr, "Error: image option list too long.\n"); usage(); } break; case 'o': pdffilename = optarg; break; case 'p': page_numbering = 1; if (optarg) { current_page = atoi(optarg); } break; case 'r': if (!optarg || (resolution = atoi(optarg)) <= 0) { fprintf(stderr, "Error: non-positive resolution.\n"); usage(); } break; case 't': imagetype = optarg; break; case '?': default: usage(); } if (optind == argc) { fprintf(stderr, "Error: no image files given.\n"); usage(); } if (pdffilename == NULL) { fprintf(stderr, "Error: no output file given.\n"); usage(); } if ((p = PDF_new()) == (PDF *) 0) { fprintf(stderr, "Couldn't create PDFlib object (out of memory)!\n"); exit(99); } PDF_TRY(p) { optlist[0] = 0; #ifndef PDFLIB_LITE tagged = pdfalevel && !strcmp(pdfalevel, "PDF/A-1a:2005"); if (pdfalevel) { /* disabled (see bug #1577) if (tagged) sprintf(optlist, "pdfa=%s lang=en", pdfalevel); else */ sprintf(optlist, "pdfa=%s", pdfalevel); } #endif /* PDFLIB_LITE */ if (PDF_begin_document(p, pdffilename, 0, optlist) == -1) { fprintf(stderr, "Error: cannot open output file %s.\n", pdffilename); exit(1); } #ifndef PDFLIB_LITE if (pdfalevel && intent) { if (strcmp("sRGB", intent)) { sprintf(optlist, "Intent=%s", intent); PDF_set_parameter(p, "ICCProfile", optlist); } fprintf(stderr, "Using '%s' as PDF/A output intent.\n", intent); PDF_load_iccprofile(p, intent, 0, "usage=outputintent"); } if (tagged) item = PDF_begin_item(p, "Document", "Alt={Images converted with pdfimage by PDFlib GmbH}"); #endif /* PDFLIB_LITE */ PDF_set_info(p, "Creator", "pdfimage"); PDF_set_parameter(p, "warning", "false"); while (optind++ < argc) { #ifndef PDFLIB_LITE int item2=0; #endif /* PDFLIB_LITE */ int parent=0; fprintf(stderr, "Processing image file '%s'...", argv[optind-1]); /* process all frames in a multi-page image file */ for (frame=1; /* */; frame++) { sprintf(optlist, "%s page %d", useroptions, frame); image = PDF_load_image(p, imagetype, argv[optind-1],0, optlist); if (image == -1) { if (frame == 1) fprintf(stderr, "\n%s (skipped).\n", PDF_get_errmsg(p)); break; } /* dummy page size, will be adjusted later */ PDF_begin_page_ext(p, 20, 20, ""); if (graylevel >= 0.0) { if (pdfalevel) { PDF_setcolor(p, "fill", "lab", graylevel, 0.0, 0.0, 0.0); } else { PDF_setcolor(p, "fill", "gray", graylevel, 0.0, 0.0, 0.0); } PDF_rect(p, 0, 0, 10000, 10000); PDF_fill(p); } /* define outline with filename or page number */ if (page_numbering) { sprintf(buf, "Page %d", current_page++); PDF_create_bookmark(p, buf, 0, ""); } else { if (frame == 1) { parent = PDF_create_bookmark(p, argv[optind-1], 0, "open"); } else { sprintf(buf, "page %d", frame); sprintf(optlist, "parent=%d", parent); PDF_create_bookmark(p, buf, 0, optlist); } } #ifndef PDFLIB_LITE if (tagged) { /* The file name is the best /Alt value we can provide */ sprintf(optlist, "Alt={%s}", argv[optind-1]); item2 = PDF_begin_item(p, "Figure", optlist); } #endif /* PDFLIB_LITE */ if (resolution != 0) sprintf(optlist, "dpi %d adjustpage", resolution); else sprintf(optlist, "adjustpage"); PDF_fit_image(p, image, 0.0, 0.0, optlist); #ifndef PDFLIB_LITE if (tagged) PDF_end_item(p, item2); #endif /* PDFLIB_LITE */ PDF_end_page_ext(p, ""); } if (frame > 2) fprintf(stderr, "(%d frames)", frame-1); fprintf(stderr, "\n"); } #ifndef PDFLIB_LITE if (tagged) PDF_end_item(p, item); #endif /* PDFLIB_LITE */ PDF_end_document(p, ""); } PDF_CATCH(p) { printf("\npdfimage: error while creating PDF output (%s(): %s)\n", PDF_get_apiname(p), PDF_get_errmsg(p)); PDF_delete(p); exit(99); } PDF_delete(p); exit(0); }
int main(void) { /* This is where the data files are. Adjust as necessary. */ const char* searchpath = "../data"; PDF * p; const char* imagefile = "nesrin.jpg"; char* optlist; int font, image; /* 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"); PDF_set_parameter(p, "SearchPath", searchpath); if (PDF_begin_document(p, "starter_basic.pdf", 0, "") == -1) { printf("Error: %s\n", PDF_get_errmsg(p)); PDF_delete(p); return(2); } PDF_set_info(p, "Creator", "PDFlib starter sample"); PDF_set_info(p, "Title", "starter_basic"); /* We load the image before the first page, and use it * on all pages */ image = PDF_load_image(p, "auto", imagefile, 0, ""); if (image == -1) { printf("Error: %s\n", PDF_get_errmsg(p)); PDF_delete(p); return(2); } /* Page 1 */ PDF_begin_page_ext(p, 595, 842, ""); font = PDF_load_font(p, "Helvetica-Bold", 0, "winansi", ""); if (font == -1) { printf("Error: %s\n", PDF_get_errmsg(p)); PDF_delete(p); return(2); } PDF_setfont(p, font, 24); PDF_set_text_pos(p, 50, 700); PDF_show(p, "Hello world!"); PDF_fit_image(p, image, (float) 0.0, (float) 0.0, "scale=0.25"); PDF_end_page_ext(p, ""); /* Page 2 */ PDF_begin_page_ext(p, 595, 842, ""); /* red rectangle */ PDF_setcolor(p, "fill", "rgb", 1.0, 0.0, 0.0, 0.0); PDF_rect(p, 200, 200, 250, 150); PDF_fill(p); /* blue circle */ PDF_setcolor(p, "fill", "rgb", 0.0, 0.0, 1.0, 0.0); PDF_arc(p, 400, 600, 100, 0, 360); PDF_fill(p); /* thick gray line */ PDF_setcolor(p, "stroke", "gray", 0.5, 0.0, 0.0, 0.0); PDF_setlinewidth(p, 10); PDF_moveto(p, 100, 500); PDF_lineto(p, 300, 700); PDF_stroke(p); /* Using the same image handle means the data will be copied * to the PDF only once, which saves space. */ PDF_fit_image(p, image, 150.0, 25.0, "scale=0.25"); PDF_end_page_ext(p, ""); /* Page 3 */ PDF_begin_page_ext(p, 595, 842, ""); /* Fit the image to a box of predefined size (without distortion) */ optlist = "boxsize={400 400} position={center} fitmethod=meet"; PDF_fit_image(p, image, 100, 200, optlist); PDF_end_page_ext(p, ""); PDF_close_image(p, image); PDF_end_document(p, ""); } PDF_CATCH(p) { printf("PDFlib exception occurred:\n"); printf("[%d] %s: %s\n", PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p)); PDF_delete(p); return(2); } PDF_delete(p); return 0; }