1#!/usr/bin/python
2# $Id: image.py 14574 2005-10-29 16:27:43Z bonefish $
3#
4# PDFlib client: image example in Python
5#
6
7from sys import *
8from pdflib_py import *
9
10imagefile = "nesrin.jpg"
11
12# This is where font/image/PDF input files live. Adjust as necessary.
13searchpath = "../data"
14
15
16p = PDF_new()
17
18if PDF_open_file(p, "image.pdf") == -1:
19    print "Error: " + PDF_get_errmsg(p) + "\n"
20    exit(2)
21
22PDF_set_parameter(p, "SearchPath", searchpath)
23
24# This line is required to avoid problems on Japanese systems
25PDF_set_parameter(p, "hypertextencoding", "winansi")
26
27PDF_set_info(p, "Creator", "image.py")
28PDF_set_info(p, "Author", "Thomas Merz")
29PDF_set_info(p, "Title", "image sample (Python)")
30
31image = PDF_load_image(p, "auto", imagefile, "")
32
33if image == -1:
34    print "Error: " + PDF_get_errmsg(p) + "\n"
35    exit(3)
36
37# dummy page size, will be adjusted by PDF_fit_image()
38PDF_begin_page(p, 10, 10)
39PDF_fit_image(p, image, 0, 0, "adjustpage")
40PDF_close_image(p, image)
41PDF_end_page(p)			# close page
42
43PDF_close(p)			# close PDF document
44
45PDF_delete(p)
46