#!/usr/bin/perl -wT use PDF::API2; use PDF::Table; use perlchartdir; use CGI; use strict; use warnings; print header( "application/pdf" ); use constant mm => 25.4/72; use constant in => 1/72; use constant pt => 1; sub setImage; sub newText; sub newTextRight; sub checkCurrency; sub GrabParams; my $q = new CGI; my %valueHash; GrabParams(); my $ID = $q->param("ID"); ###################################################### ## Config Variable Edit this for Easy Configuration ## ###################################################### my $Template = qq(Dell_Deployment_Optimization_Report.pdf); my $ChartImageName = "DellDOChart".$ID.".jpeg"; my $bubbleName = "Bubble".$ID.".jpeg"; ## Text Vars my $fontType = qq(Helvetica); my $CurrencySymbol = $q->param("CurrencySymbol"); ############### MAKE stack bar CHART #################### # The data for the bar chart my $data6 = [$valueHash{"ch1v11"}, $valueHash{"ch1v21"}, $valueHash{"ch1v31"}, $valueHash{"ch1v41"}]; my $data5 = [$valueHash{"ch1v12"}, $valueHash{"ch1v22"}, $valueHash{"ch1v32"}, $valueHash{"ch1v42"}]; my $data4 = [$valueHash{"ch1v13"}, $valueHash{"ch1v23"}, $valueHash{"ch1v33"}, $valueHash{"ch1v43"}]; my $data3 = [$valueHash{"ch1v14"}, $valueHash{"ch1v24"}, $valueHash{"ch1v34"}, $valueHash{"ch1v44"}]; my $data2 = [$valueHash{"ch1v15"}, $valueHash{"ch1v25"}, $valueHash{"ch1v35"}, $valueHash{"ch1v45"}]; my $data1 = [$valueHash{"ch1v16"}, $valueHash{"ch1v26"}, $valueHash{"ch1v36"}, $valueHash{"ch1v46"}]; my $data0 = [$valueHash{"ch1v17"}, $valueHash{"ch1v27"}, $valueHash{"ch1v37"}, $valueHash{"ch1v47"}]; # The labels for the bar chart my $labels = [$valueHash{"ch1x1"}, $valueHash{"ch1x2"}, $valueHash{"ch1x3"}, $valueHash{"ch1x4"}]; # Create a XYChart object of size 500 x 320 pixels my $c = new XYChart(540, 450); # Set the plotarea at (100, 40) and of size 280 x 240 pixels $c->setPlotArea(105, 45, 305, 375); # Add a legend box at (400, 100) $c->addLegend(349, 42)->setBackground(0xffffff); #$c->LegendBox # Add a title to the chart using 14 points Times Bold Itatic font $c->addTitle($valueHash{"ch1title"}, "", 13); # Add a title to the y axis. Draw the title upright (font angle = 0) #$c->yAxis()->setTitle($q->param("Currency"))->setFontAngle(90); # Set the labels on the x axis $c->yAxis()->setLabelFormat("$CurrencySymbol"." "."{value|,}"); # Set the labels on the x axis $c->xAxis()->setLabels($labels); # Add a stacked bar layer and set the layer 3D depth to 8 pixels my $layer = $c->addBarLayer2($perlchartdir::Stack, 8); # Add the seven data sets to the bar layer $layer->addDataSet($data6, 0x9999ff, $valueHash{"ch1s1"}); $layer->addDataSet($data5, 0x993366, $valueHash{"ch1s2"}); $layer->addDataSet($data4, 0xffffcc, $valueHash{"ch1s3"}); $layer->addDataSet($data3, 0xccffff, $valueHash{"ch1s4"}); $layer->addDataSet($data2, 0x660066, $valueHash{"ch1s5"}); $layer->addDataSet($data1, 0xff8080, $valueHash{"ch1s6"}); $layer->addDataSet($data0, 0x0066cc, $valueHash{"ch1s7"}); # Enable bar label for the whole bar #$layer->setAggregateLabelStyle(); # Enable bar label for each segment of the stacked bar #$layer->setDataLabelStyle(); # output the chart $c->makeChart($ChartImageName); ######################### END CHART ############################# ########################### BUBBLE CHART ############################################# # The XYZ points for the bubble chart my $dataX0 = [150, 300, 1000, 1700]; my $dataY0 = [12, 60, 25, 65]; my $dataZ0 = [20, 50, 50, 85]; my $dataX1 = [500, 1000, 1300]; my $dataY1 = [35, 50, 75]; my $dataZ1 = [30, 55, 95]; # Create a XYChart object of size 450 x 420 pixels my $ch = new XYChart(450, 420); # Set the plotarea at (55, 65) and of size 350 x 300 pixels, with a light grey border # (0xc0c0c0). Turn on both horizontal and vertical grid lines with light grey color # (0xc0c0c0) $ch->setPlotArea(55, 65, 350, 300, -1, -1, 0xc0c0c0, 0xc0c0c0, -1); # Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use 12 pts # Times Bold Italic font. Set the background and border color to Transparent. $ch->addLegend(50, 30, 0, "timesbi.ttf", 12)->setBackground($perlchartdir::Transparent ); # Add a title to the chart using 18 pts Times Bold Itatic font. $ch->addTitle("Product Comparison Chart", "timesbi.ttf", 18); # Add a title to the y axis using 12 pts Arial Bold Italic font $ch->yAxis()->setTitle("Capacity (tons)", "arialbi.ttf", 12); # Add a title to the x axis using 12 pts Arial Bold Italic font $ch->xAxis()->setTitle("Range (miles)", "arialbi.ttf", 12); # Set the axes line width to 3 pixels $ch->xAxis()->setWidth(3); $ch->yAxis()->setWidth(3); # Add (dataX0, dataY0) as a scatter layer with semi-transparent red (0x80ff3333) # circle symbols, where the circle size is modulated by dataZ0. This creates a bubble # effect. $ch->addScatterLayer($dataX0, $dataY0, "Technology AAA", $perlchartdir::CircleSymbol, 9, 0x80ff3333, 0x80ff3333)->setSymbolScale($dataZ0); # Add (dataX1, dataY1) as a scatter layer with semi-transparent green (0x803333ff) # circle symbols, where the circle size is modulated by dataZ1. This creates a bubble # effect. $ch->addScatterLayer($dataX1, $dataY1, "Technology BBB", $perlchartdir::CircleSymbol, 9, 0x803333ff, 0x803333ff)->setSymbolScale($dataZ1); # output the chart $ch->makeChart($bubbleName); ########################### MAKE PDF ############################ my $pdftable = new PDF::Table; my $pdf = PDF::API2->open($Template); my $page = $pdf->openpage(1); ##### Set Font ############### my %font = ( Helvetica => { Bold => $pdf->corefont('Helvetica-Bold', -encoding => 'latin1'), Roman => $pdf->corefont('Helvetica', -encoding => 'latin1'), Italic => $pdf->corefont('Helvetica-Oblique', -encoding => 'latin1'), }, ); ## Set Image( x, y, w, h) ############### setImage($ChartImageName, 115/mm, 171/mm, 89/mm, 75/mm); ## Set Text ############### #Title newText($fontType, 'Roman', 12.5/pt, 'black', 13.5/mm, 263/mm, $valueHash{"repTitle"}); #ES newText($fontType, 'Roman', 7/pt, 'black', 12.5/mm, 254/mm, $valueHash{"ES1"}); newText($fontType, 'Roman', 7/pt, 'black', 12.5/mm, 251/mm, $valueHash{"ES2"}); newText($fontType, 'Roman', 7/pt, 'black', 12.5/mm, 248/mm, $valueHash{"ES3"}); newText($fontType, 'Roman', 7/pt, 'black', 12.5/mm, 245/mm, $valueHash{"ES4"}); #Assumptions newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 230/mm, $valueHash{"CompanyType"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 226/mm, $valueHash{"Country"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 222/mm, $valueHash{"Currency"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 215/mm, $valueHash{"D9"}); #newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 196/mm, $valueHash{"D11"}); #newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 192/mm, $valueHash{"D12"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 211/mm, $valueHash{"D14"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 207/mm, $valueHash{"D15"}); #Current Optimization Practices newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 195/mm, "Deployment Management:"); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 191/mm, $valueHash{"COP1a"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 184/mm, "Staging and Logistics of deployed PCs:"); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 180/mm, $valueHash{"COP2a"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 173/mm, "Image Loading:"); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 169/mm, $valueHash{"COP3a"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 161/mm, "Methods used to install applications:"); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 157/mm, $valueHash{"COP41a"}); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 153/mm, $valueHash{"COP42a"}); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 149/mm, $valueHash{"COP43a"}); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 145/mm, $valueHash{"COP44a"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 138/mm, "User State Migration:"); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 134/mm, $valueHash{"COP5a"}); newText($fontType, 'Roman', 8/pt, 'black', 12.5/mm, 127/mm, "Post Deployment End User Support:"); newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 123/mm, $valueHash{"COP6a"}); #newText($fontType, 'Roman', 6.75/pt, 'black', 12.5/mm, 123/mm, "Remote issue resolution; \"command center\" remotely monitors deployment/troubleshoots issues"); ################################################################################################### $page = $pdf->openpage(2); setImage($bubbleName, 115/mm, 100/mm, 89/mm, 75/mm); ################################################################################################ sub newText{ my $flashVars = $page->text; $flashVars->font( $font{$_[0]}{$_[1]}, $_[2] ); $flashVars->fillcolor( $_[3] ); $flashVars->translate( $_[4], $_[5] ); $flashVars->text( $_[6] ); } #################################### sub setImage{ my $photo_file=$pdf->image_jpeg($_[0]); my $photo = $page->gfx; ## add photo to pdf include cordinates and size - image($photo, x, y, width, hieght); $photo->image($photo_file, $_[1], $_[2], $_[3], $_[4]); } ############ END setImage FUNCTION ################# sub GrabParams{ my ( $paramName, $paramValue); foreach $paramName ($q->param) { $valueHash{$paramName}; foreach $paramValue ($q->param( $paramName )) { $valueHash{ $paramName } = pack 'U0A*', $paramValue; } } } print $pdf->stringify; binmode STDOUT; $pdf->end; unlink($ChartImageName, $bubbleName); __END__