home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / pdflib / pdflib-4.0.1.sit / pdflib-4.0.1 / bind / c / image.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-04  |  1.3 KB  |  55 lines  |  [TEXT/CWIE]

  1. /* $Id: image.c,v 1.7.2.1 2001/05/16 12:25:50 york Exp $
  2.  * PDFlib client: image example in C
  3.  *
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. #include "pdflib.h"
  10.  
  11. int
  12. main(void)
  13. {
  14.     PDF *p;
  15.     int image;
  16.     float width, height;
  17.     char *imagefile = "../../test/nesrin.jpg";
  18.  
  19.     p = PDF_new();
  20.  
  21.     /* open new PDF file */
  22.     if (PDF_open_file(p, "image.pdf") == -1) {
  23.     fprintf(stderr, "Error: couldn't open PDF file image.pdf.\n");
  24.     exit(2);
  25.     }
  26.  
  27.     PDF_set_info(p, "Creator", "image.c");
  28.     PDF_set_info(p, "Author", "Thomas Merz");
  29.     PDF_set_info(p, "Title", "image sample (C)");
  30.  
  31.     image = PDF_open_image_file(p, "jpeg", imagefile, "", 0);
  32.  
  33.     if (image == -1) {
  34.     fprintf(stderr, "Error: couldn't open image file.\n");
  35.     exit(3);
  36.     }
  37.  
  38.     /* See the PDFlib manual for more advanced image size calculations */
  39.     width = PDF_get_value(p, "imagewidth", image);
  40.     height = PDF_get_value(p, "imageheight", image);
  41.  
  42.     /* We generate a page with the image's dimensions */
  43.     PDF_begin_page(p, width, height);
  44.     PDF_place_image(p, image, (float) 0.0, (float) 0.0, (float) 1.0);
  45.     PDF_close_image(p, image);
  46.  
  47.     PDF_end_page(p);                /* close page        */
  48.  
  49.     PDF_close(p);                /* close PDF document    */
  50.  
  51.     PDF_delete(p);                /* delete the PDF object */
  52.  
  53.     return 0;
  54. }
  55.