MIDRANGE dot COM Mailing List Archive



Home » WEB400 » February 2010

Re: Zend PDF and the RPG Experiment



fixed

Okay. I promise to watch the webcast(s) this weekend. :)

Kelly Cookson
Senior Programmer/Analyst
Dot Foods, Inc.
217-773-4486 x12676
www.dotfoods.com


-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Mike Pavlak
Sent: Friday, February 26, 2010 9:33 AM
To: Web Enabling the AS400 / iSeries
Subject: Re: [WEB400] Zend PDF and the RPG Experiment

I keep begging you all to tune into my webcasts ;-)

Yes, the CE version runs the same code as the full version but with many
of the key features like Monitoring and Code Tracing disabled. There is
no reverse proxy in ANY edition of Zend Server. But I might be able to
craft one specifically for you if you think you will miss it too much.
:-)

Regards,

Mike

mike.p@xxxxxxxx Cell: (408)679-1011 Office: (815)722-3454

Zend Server for IBM i Beta avilable at
http://www.zend.com/en/products/server/zend-server-5-new-ibmi



-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx]
On Behalf Of Kelly Cookson
Sent: Friday, February 26, 2010 9:15 AM
To: Web Enabling the AS400 / iSeries
Subject: Re: [WEB400] Zend PDF and the RPG Experiment

I wasn't aware there was free "community version" of the Zend Server for
IBM i.

I'm assuming the free version does NOT have the tools from the Zend
Platform.

But does the community version do away with the reverse proxy?

Kelly Cookson
Senior Programmer/Analyst
Dot Foods, Inc.
217-773-4486 x12676
www.dotfoods.com

-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx]
On Behalf Of Mike Pavlak
Sent: Friday, February 26, 2010 8:48 AM
To: Web Enabling the AS400 / iSeries
Subject: [WEB400] Zend PDF and the RPG Experiment

Aaron,



I am starting a new thread.



I was hoping someone would open the door for PHP. I would recommend
Zend Server for IBM i Community Edition. (GA, VERY soon, beta available
at link below) This is the no charge runtime for PHP and includes Zend
Framework. Why do I mention ZF? Simply because there is support for
Zend_PDF which supports a template approach to PDF generation. I am
working with some folks to put an nice example here. See this link for
the documentation on Zend_PDF for more details:
http://framework.zend.com/manual/en/zend.pdf.html



Once you start with PHP, you may never go back to Java ;-)



Of course, you can use FPDF in this environment too.



I am not aware of another solution to deliver PHP to IBM i short of Rob
Ward. But all I see of his previous site is a blog now. If you hear of
one I would like to know.



Below is a really BASIC example of Zend_PDF in action without a
template. It's not gl;amorous but I think you get the idea. There are
quite a few interesting components in this little hunk of code. In
addition to the Zend_PDF example is an example of how you can use the
library list in PHP, using PHP functions, DB2 error trapping, DB2 Fetch
of a record into an associative array (one of my favorites) and the use
of the root file system to drop the PDF. Once it is there you can do
with it what you want like attach it to an email, archive, etc.



Why buy tools when you can get this for free?





Regards,



Mike Pavlak

Solutions Consultant

Zend Technologies, Inc.

(815)722-3454

(408)679-1011

mike.p@xxxxxxxx



Check out my blog at http://mikepavlak.blogspot.com/



Zend Server for IBM i Beta avilable at
http://www.zend.com/en/products/server/zend-server-5-new-ibmi





<?php







// Bring in the PDF classes from Zend Framework

require_once 'Zend/Pdf.php';



// Read through detail records...

//Function to get Order Details...



function getConnection() {



$conn = "*LOCAL"; $name = "PHPUSER"; $pwd = "phpuser";

$LibraryList = array("i5_lib"=>"ZENDSMP010"); // Yes, you can
use a library list in PHP...

$db2_link = db2_connect($conn, $name, $pwd, $LibraryList);

if (!$db2_link) {

echo 'Connection failed: '.db2_stmt_error().' :
'.db2_stmt_errormsg();

exit;

}

return $db2_link;

}



function getSales($orderNumber){

$sql = "SELECT * from SALESLINE where SALESLINE_ORDER =
$orderNumber";



global $db2_link; // Share connection to DB...



$Sales_Rec = db2_exec($db2_link, $sql); // Execute the
query

if (!$Sales_Rec) {

echo "SQL statement $sql Call Failed: " .db2_stmt_error().'
: '.db2_stmt_errormsg();

exit;

}



// Roll through the sales records for this order and
calculate values...

/* echo '<table><tr><td>Order Number</td><td>Line Number</td>

<td>Product Number</td><td>Quantity</td><td>Line
Sales</td>'; */

while ($row=db2_fetch_assoc($Sales_Rec)) {

$lineCount++;

$lineSales+=($row[SALESLINE_QUANTITY]*$row[SALESLINE_PRICE]

*
(1-$row[SALESLINE_DISCOUNT]));

$return[$lineCount]=
array($row[SALESLINE_ORDER],$row[SALESLINE_NUMBER],


$row[SALESLINE_PRODUCT], $row[SALESLINE_QUANTITY],

$lineSales);



}

return $return;

// echo "</table>";

}



$db2_link = getConnection();

$return = getSales(5); //hard code order number for convenience...



// Create a new PDF object

$pdf = new Zend_Pdf();



// Create a new PDF page

$pdf->pages[] = ($nextPage =
$pdf->newPage(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE));



// Create a new font

$font =
Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);



// Apply the font

$nextPage->setFont($font, 20);



// Print the first line of data on the page

$dataLine = "Sales Detail report for order 5\n";

$printLine = 576;

$nextPage->drawText($dataLine, 72, $printLine);



// Print the remaining lines of data

foreach ($return as $index=> $value)

{

$printLine -= 21;

$amount = sprintf("$%.2f", $value[4]);

$text="Order: {$value[0]} Line: {$value[1]}
Product: {$value[2]}

Quantity: {$value[3]} Amount:
$amount";

$nextPage->drawText($text, 72, $printLine);

}



// Save the PDF in directory /tmp/pdf

$pdf->save("/tmp/pdf/RPGSample.pdf");

unset($pdf);

echo "Order printed";

/* */



?>










Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact