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 / python / image.py < prev    next >
Encoding:
Python Source  |  2001-07-04  |  936 b   |  39 lines  |  [TEXT/Pyth]

  1. #!/usr/bin/python
  2. # $Id: image.py,v 1.6.2.1 2001/05/16 12:25:50 york Exp $
  3. #
  4. # PDFlib client: image example in Python
  5. #
  6.  
  7. from sys import *
  8. from pdflib_py import *
  9.  
  10. p = PDF_new()
  11.  
  12. if PDF_open_file(p, "image.pdf") == -1:
  13.     print "Couldn't open PDF file 'image.pdf'\n"
  14.     exit(2)
  15.  
  16. PDF_set_info(p, "Author", "Thomas Merz")
  17. PDF_set_info(p, "Creator", "image.py")
  18. PDF_set_info(p, "Title", "image sample (Python)")
  19.  
  20. imgfile = "../../test/nesrin.jpg"
  21. image = PDF_open_image_file(p, "jpeg", imgfile, "", 0)
  22.  
  23. if image == -1:
  24.     print "Couldn't open image file '" + imgfile + "'\n"
  25.     exit(3)
  26.  
  27. # See the PDFlib manual for more advanced image size calculations
  28. width = PDF_get_value(p, "imagewidth", image)
  29. height = PDF_get_value(p, "imageheight", image)
  30.  
  31. # We generate a page with the image's dimensions
  32. PDF_begin_page(p, width, height)
  33. PDF_place_image(p, image, 0, 0, 1)
  34. PDF_close_image(p, image)
  35. PDF_end_page(p)
  36.  
  37. PDF_close(p)
  38. PDF_delete(p)
  39.