1#!/bin/sh
2# $Id: starter_layer.tcl,v 1.1.2.2 2008/02/11 20:10:29 rjs Exp $
3#
4# Hide the exec to Tcl but not to the shell by appending a backslash\
5exec tclsh "$0" ${1+"$@"}
6
7# The lappend line is unnecessary if PDFlib has been installed
8# in the Tcl package directory
9set auto_path [linsert $auto_path 0 .libs .]
10
11package require pdflib 7.0
12
13# Starter layer:
14# Define several layers output images and text to them and define
15# particular layers to be visible when opening the document
16#
17# Define two layers for RGB or Grayscale images and two layers for English or
18# German image captions. Output images and text on the various layers and
19# open the document with the RGB images and English captions visible.
20#
21# Required software: PDFlib/PDFlib+PDI/PPS 7
22# Required data: grayscale and RGB images
23
24set p [PDF_new]
25
26if { [catch {
27
28    # This is where the data files are. Adjust as necessary.
29    set searchpath "../data"
30    set outfile "starter_layer.pdf"
31
32    set rgb "nesrin.jpg"
33    set gray "nesrin_gray.jpg"
34
35	PDF_set_parameter $p "SearchPath" $searchpath
36
37	PDF_set_parameter $p "errorpolicy" "exception"
38
39	# Open the document with the "Layers" navigation tab visible
40	PDF_begin_document $p $outfile "openmode=layers"
41
42	PDF_set_info $p "Creator" "PDFlib starter sample"
43	PDF_set_info $p "Title" "starter_layer"
44
45	# Load the font
46	set font [PDF_load_font $p "Helvetica" "winansi" ""]
47
48	# Load the Grayscale image
49	set imageGray [PDF_load_image $p "auto" $gray ""]
50
51	# Load the RGB image
52	set imageRGB [PDF_load_image $p "auto" $rgb ""]
53
54	# Define all layers which will be used, and their relationships.
55	# This should be done before the first page if the layers are
56	# used on more than one page.
57
58	# Define the layer "RGB"
59	set layerRGB [PDF_define_layer $p "RGB" ""]
60
61	# Define the layer "Grayscale" which is hidden when opening the
62	# document or printing it.
63
64	set layerGray [PDF_define_layer $p "Grayscale" \
65		"initialviewstate=false initialprintstate=false"]
66
67	# At most one of the "Grayscale" and "RGB" layers should be visible
68	PDF_set_layer_dependency $p "Radiobtn" "group={$layerGray $layerRGB}"
69
70	# Define the layer "English"
71	set layerEN [PDF_define_layer $p "English" ""]
72
73	# Define the layer "German" which is hidden when opening the document
74	# or printing it.
75	set layerDE [PDF_define_layer $p "German" \
76		"initialviewstate=false initialprintstate=false"]
77
78	# At most one of the "English" and "German" layers should be visible
79	PDF_set_layer_dependency $p "Radiobtn" "group={$layerEN $layerDE}"
80
81	# Start page
82	PDF_begin_page_ext $p 0 0 "width=a4.width height=a4.height"
83
84	# Place the RGB image on the layer "RGB"
85	PDF_begin_layer $p $layerRGB
86	PDF_fit_image $p $imageRGB 100 400 "boxsize={400 300} fitmethod=meet"
87
88	# Place the Grayscale image on the layer "Grayscale"
89	PDF_begin_layer $p $layerGray
90	PDF_fit_image $p $imageGray 100 400	"boxsize={400 300} fitmethod=meet"
91	# Place an English image caption on the layer "English"
92	PDF_begin_layer $p $layerEN
93	PDF_fit_textline $p "This is the Nesrin image." 100 370 \
94	    "font=$font fontsize=20"
95
96	# Place a German image caption on the layer "German"
97	PDF_begin_layer $p $layerDE
98	PDF_fit_textline $p "Das ist das Nesrin-Bild." 100 370 \
99		"font=$font fontsize=20"
100
101	PDF_end_layer $p
102
103	PDF_end_page_ext $p ""
104
105	PDF_end_document $p ""
106
107} result]} {
108    puts stderr $result
109}
110
111PDF_delete $p
112