{= include("templates.util.base_util"); include("lib.pdf"); # KHP 04/Mar/2011 - Only allow root_admin access bool is_root_admin = get_is_root_admin(); if (is_root_admin) then ( # Start a new PDF node pdf = new_pdf(); # Add a new page v.page_width = 612; v.page_height = 792; node page1 = new_page(pdf, 0, 0, v.page_width, v.page_height); # Choose which tests to run bool circletest = true; bool transparentpngtest = true; bool fonttest = true; bool fontsizetest = true; bool linetest = true; bool pngcircletest = true; bool pietest = true; bool giftest = true; bool textwraptest = true; ## ## CIRCLE TEST ## if (circletest) then ( # Draw several concentric circles for (int i = 0; i < 100; i += 4) ( draw_circle(page1, 234 + i, 234 - i, 50 + i, false); ); ); # if circletest ## ## TRANSPARENT PNG TEST ## if (transparentpngtest) then ( # Get the logo image int logoImage = read_image_from_disk("LogAnalysisInfo/WebServerRoot/picts/sawmill_logo.png"); string logoImageName = load_image_into_pdf(pdf, logoImage); # Draw several rectangles with the transparent logo on them int v = 300; int h = 450; for (int i = 0; i < 3; i++) ( if (i == 0) then set_nonstroking_color(page1, 0.5, 0, 0); else if (i == 1) then set_nonstroking_color(page1, 0, 0.5, 0); else set_nonstroking_color(page1, 0, 0, 0.5); draw_rectangle(page1, h, v, get_image_width(logoImage) + 40, get_image_height(logoImage) + 40, true); draw_rectangle(page1, h, v, get_image_width(logoImage) + 40, get_image_height(logoImage) + 40, false); draw_image(page1, logoImageName, h+20, v+20, get_image_width(logoImage), get_image_height(logoImage)); v += (get_image_height(logoImage) + 40); ); set_nonstroking_color(page1, 0, 0, 0); ); # if transparentpngtest ## ## FONT TEST ## if (fonttest) then ( # Add a text stream to the contents node helvetica = new_type1_font(pdf, "/Helvetica", "/MacRomanEncoding"); node timesItalic = new_type1_font(pdf, "/Times-Italic", "/MacRomanEncoding"); node courierBold = new_type1_font(pdf, "/Courier-BoldOblique", "/MacRomanEncoding"); draw_text(page1, helvetica, 24, 350, 600, "Helvetica"); draw_text(page1, courierBold, 20, 350, 630, "Courier-BoldOblique"); draw_text(page1, timesItalic, 24, 350, 660, "Times-Italic"); ); # if fonttest ## ## FONT SIZE TEST ## if (fontsizetest) then ( node timesRoman = new_type1_font(pdf, "/Times-Roman", "/MacRomanEncoding"); # Draw font in several sizes float vpos = 700; for (int i = 1; i < 24; i++) ( string text = "Times-Roman (" . i . " point)"; # Draw a light gray rectangle around the text box float textWidth = text_width(timesRoman, i, text); float textLineSpacing = text_line_spacing(timesRoman, i); set_stroking_color(page1, 0.8, 0.8, 0.8); draw_rectangle(page1, 30, vpos, textWidth, textLineSpacing, false); set_stroking_color(page1, 0, 0, 0); # Draw the text draw_text(page1, timesRoman, i, 30, vpos, text); vpos -= i + 3; ); # for i ); # if fontsizetest ## ## LINE TEST ## if (linetest) then ( # Draw a pattern of lines float radius = 130; float xcenter = 120; float ycenter = 120; for (float r = 0; r < 3.14; r += 0.2) ( draw_line(page1, xcenter-(radius*sin(r)), ycenter-(radius*cos(r)), xcenter+(radius*sin(r)), ycenter+(radius*cos(r))); ); ); # if linetest ## ## PNG CIRCLE TEST ## # Draw a circle of error images, with lines if (pngcircletest) then ( float radius = 100; int errorImage = read_image_from_disk("LogAnalysisInfo/WebServerRoot/picts/error.png"); string errorImageName = load_image_into_pdf(pdf, errorImage); for (float r = 0; r < 6.28; r += 0.3) ( draw_image(page1, errorImageName, xcenter + radius*sin(r) - (get_image_width(errorImage) / 2), ycenter + radius*cos(r) - (get_image_height(errorImage) / 2), get_image_width(errorImage), get_image_height(errorImage)); ); ); # if pngcircletest ## ## PIE CHART TEST ## # Draw an oval as a polygon if (pietest) then ( float xcenter = 250; float ycenter = 650; float ovalHeight = 40; float ovalWidth = 80; node vertices = new_node(); int vertexNum = 0; float shade = 0; int sliceSegment = 0; for (float r = 0; r < 6.28; r += 0.1) ( node vertex = vertices{vertexNum}; vertex{"x"} = xcenter + (ovalWidth*sin(r)); vertex{"y"} = ycenter + (ovalHeight*cos(r)); if (sliceSegment == 10) then ( node vertex = vertices{(vertexNum + 1)}; vertex{"x"} = xcenter; vertex{"y"} = ycenter; set_nonstroking_color(page1, 0, shade, 0); draw_polygon(page1, vertices, true); set_nonstroking_color(page1, 0, 0, 0); shade += 0.1; sliceSegment = 0; delete_node(vertices); vertices = new_node(); node vertex = vertices{vertexNum}; vertex{"x"} = xcenter + (ovalWidth*sin(r)); vertex{"y"} = ycenter + (ovalHeight*cos(r)); ); sliceSegment++; vertexNum++; ); # for r ); # if pietest ## ## GIF TEST ## if (giftest) then ( # Get the logo image int docspictureImage = read_image_from_disk("LogAnalysisInfo/WebServerRoot/picts/docslogo.gif"); string docspictureImageName = load_image_into_pdf(pdf, docspictureImage); draw_image(page1, docspictureImageName, 100, 300, get_image_width(docspictureImage), get_image_height(docspictureImage)); # Get the log image #int docspictureImage = read_image_from_disk("LogAnalysisInfo/WebServerRoot/picts/docspicture.gif"); int dateFilterImage = read_image_from_disk("LogAnalysisInfo/WebServerRoot/picts/ic_date_filter.gif"); string dateFilterImageName = load_image_into_pdf(pdf, dateFilterImage); draw_image(page1, dateFilterImageName, 80, 300, get_image_width(dateFilterImage), get_image_height(dateFilterImage)); ); # if giftest ## ## TEXT WRAP TEST ## if (textwraptest) then ( node timesRoman = new_type1_font(pdf, "/Times-Roman", "/MacRomanEncoding"); float xmin = 250; float ymin = 10; float width = 350; float height = 120; set_stroking_color(page1, 0.6, 0.6, 1.0); set_nonstroking_color(page1, 0.9, 0.9, 1.0); draw_rectangle(page1, xmin, ymin, width, height, true); draw_rectangle(page1, xmin, ymin, width, height, false); set_stroking_color(page1, 0, 0, 0); set_nonstroking_color(page1, 0, 0, 0); string text = "Call me Ishmael. Some years ago - never mind how long precisely - having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen, and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off - then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me."; # text = "Ishmael"; float boxheight = draw_wrapped_text(page1, timesRoman, 9, xmin, ymin + height, width, text, "left", true, true, false, false); #echo("boxheight: " . boxheight); #echo("boxheight: " . boxheight); ); # if giftest #node courierBold = new_type1_font(pdf, "/Courier-BoldOblique", "/MacRomanEncoding"); node courier = new_type1_font(pdf, "/Courier", "/MacRomanEncoding"); boxheight = draw_wrapped_text(page1, courier, 24, 0, v.page_height, v.page_width, "Salang PDF Library Demo", "center", true, true, false, false); # Add an outline item add_outline_entry(pdf, "Sample Outline Entry"); # Write it to a file write_pdf(pdf, "out.pdf"); ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}