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 / java / image.java < prev    next >
Encoding:
Java Source  |  2001-07-04  |  1.3 KB  |  52 lines  |  [TEXT/javc]

  1. /* $Id: image.java,v 1.5.2.1 2001/05/16 12:25:50 york Exp $
  2.  *
  3.  * PDFlib client: image example in Java
  4.  */
  5.  
  6. import java.io.*;
  7. import com.pdflib.pdflib;
  8.  
  9. public class image
  10. {
  11.     public static void main (String argv[]) throws
  12.     OutOfMemoryError, IOException, IllegalArgumentException,
  13.     IndexOutOfBoundsException, ClassCastException, ArithmeticException,
  14.     RuntimeException, InternalError, UnknownError
  15.     {
  16.     int image;
  17.     float width, height;
  18.     pdflib p;
  19.     String imagefile = "../../test/nesrin.jpg";
  20.  
  21.     p = new pdflib();
  22.  
  23.     if (p.open_file("image.pdf") == -1) {
  24.         System.err.println("Couldn't open PDF file image.pdf\n");
  25.         System.exit(1);
  26.     }
  27.  
  28.     p.set_info("Creator", "image.java");
  29.     p.set_info("Author", "Thomas Merz");
  30.     p.set_info("Title", "image sample (Java)");
  31.  
  32.     image = p.open_image_file("jpeg", imagefile, "", 0);
  33.  
  34.     if (image == -1) {
  35.         System.err.println("Couldn't open image file.\n");
  36.         System.exit(1);
  37.     }
  38.  
  39.     // See the PDFlib manual for more advanced image size calculations
  40.     width = p.get_value("imagewidth", image);
  41.     height = p.get_value("imageheight", image);
  42.  
  43.     // We generate a page with the image's dimensions
  44.     p.begin_page(width, height);
  45.     p.place_image(image, (float) 0.0, (float) 0.0, (float) 1.0);
  46.     p.close_image(image);
  47.     p.end_page();
  48.  
  49.     p.close();
  50.     }
  51. }
  52.