1<?php 2# $Id: starter_layer.php,v 1.1.2.2 2008/02/11 20:10:28 rjs Exp $ 3# Starter layer: 4# Define several layers, output images and text to them and define 5# particular layers to be visible when opening the document 6# 7# Define two layers for RGB or Grayscale images and two layers for English or 8# German image captions. Output images and text on the various layers and 9# open the document with the RGB images and English captions visible. 10# 11# Required software: PDFlib/PDFlib+PDI/PPS 7 12# Required data: grayscale and RGB images 13# 14 15# This is where the data files are. Adjust as necessary. 16$searchpath = "../data"; 17$title = "Starter Layer"; 18 19# create a new PDFlib object 20$p = PDF_new(); 21 22$rgb = "nesrin.jpg"; 23$gray = "nesrin_gray.jpg"; 24 25 PDF_set_parameter($p, "SearchPath", $searchpath); 26 27 # This means we must check return values of load_font() etc. 28 PDF_set_parameter($p, "errorpolicy", "return"); 29 30 31 # Open the document with the "Layers" navigation tab visible 32 if (PDF_begin_document($p, "", "openmode=layers") == 0) { 33 die("Error: " . PDF_get_errmsg($p)); 34 } 35 36 PDF_set_info($p, "Creator", "PDFlib Cookbook"); 37 $buf = $title . ' $Revision: 1.1.2.2 $'; 38 PDF_set_info($p, "Title", $buf); 39 40 # Load the font 41 $font = PDF_load_font($p, "Helvetica", "winansi", ""); 42 43 if ($font == 0) { 44 die("Error: " . PDF_get_errmsg($p)); 45 } 46 47 # Load the Grayscale image 48 $imageGray = PDF_load_image($p, "auto", $gray, ""); 49 if ($imageGray == 0) { 50 die("Error: " . PDF_get_errmsg($p)); 51 } 52 53 # Load the RGB image 54 $imageRGB = PDF_load_image($p, "auto", $rgb, ""); 55 if ($imageRGB == 0) { 56 die("Error: " . PDF_get_errmsg($p)); 57 } 58 59 # Define all layers which will be used, and their relationships. 60 # This should be done before the first page if the layers are 61 # used on more than one page. 62 # 63 64 # Define the layer "RGB" 65 $layerRGB = PDF_define_layer($p, "RGB", ""); 66 67 # Define the layer "Grayscale" which is hidden when opening the 68 # document or printing it. 69 $layerGray = PDF_define_layer($p, "Grayscale", 70 "initialviewstate=false initialprintstate=false"); 71 72 # At most one of the "Grayscale" and "RGB" layers should be visible 73 $buf = "group={" . $layerGray . " " . $layerRGB . "}"; 74 PDF_set_layer_dependency($p, "Radiobtn", $buf); 75 76 # Define the layer "English" 77 $layerEN = PDF_define_layer($p, "English", ""); 78 79 # Define the layer "German" which is hidden when opening the document 80 # or printing it. 81 $layerDE = PDF_define_layer($p, "German", 82 "initialviewstate=false initialprintstate=false"); 83 84 # At most one of the "English" and "German" layers should be visible 85 $buf = "group={" . $layerEN . " " . $layerDE . "}"; 86 PDF_set_layer_dependency($p, "Radiobtn", $buf); 87 88 89 # Start page 90 PDF_begin_page_ext($p, 0, 0, "width=a4.width height=a4.height"); 91 92 # Place the RGB image on the layer "RGB" 93 PDF_begin_layer($p, $layerRGB); 94 PDF_fit_image($p, $imageRGB, 100, 400, 95 "boxsize={400 300} fitmethod=meet"); 96 97 # Place the Grayscale image on the layer "Grayscale" 98 PDF_begin_layer($p, $layerGray); 99 PDF_fit_image($p, $imageGray, 100, 400, 100 "boxsize={400 300} fitmethod=meet"); 101 102 # Place an English image caption on the layer "English" 103 PDF_begin_layer($p, $layerEN); 104 $buf = "font=" . $font . " fontsize=20"; 105 PDF_fit_textline($p, "This is the Nesrin image.", 100, 370, $buf); 106 107 # Place a German image caption on the layer "German". 108 PDF_begin_layer($p, $layerDE); 109 $buf = "font=" . $font . " fontsize=20"; 110 PDF_fit_textline($p, "Das ist das Nesrin-Bild.", 100, 370, $buf); 111 112 PDF_end_layer($p); 113 114 PDF_end_page_ext($p, ""); 115 116 PDF_end_document($p, ""); 117 118$buf = PDF_get_buffer($p); 119$len = strlen($buf); 120 121header("Content-type: application/pdf"); 122header("Content-Length: $len"); 123header("Content-Disposition: inline; filename=hello.pdf"); 124print $buf; 125 126?> 127