Computer programming in PHP for business and passion
In: PHP| Zend Core| Zend Framework| i5/OS
30 Jan 2010Recently I started to develop on IBM i5 systems using PHP. PHP is becoming a very popular languages in the IBM i5 community to produce web applications and to modernize “green screen” applications. If you want to know how to use PHP on IBM i5 systems you have to look at the Zend Core for i5, the PHP distribution of Zend Technologies.
Zend Core for i5/OS provides the i5 Toolkit for PHP, an API system to call i5 functionalities from PHP. One of the function of this API is the i5_spool that is able to manage spool files for specific i5 users. In this post I present a class to convert a spool file in PDF using the Zend_Pdf class of the Zend Framework.
The class is the i5Spool and you can download it here.
You can easly convert a spool file in PDF choosing the page format, the page margins, the font type, the font size, the interline, etc.
Here an example of usage:
1 2 3 4 5 6 7 8 9 10 11 12 | require_once 'i5Spool.php'; $spool= new i5Spool('host','username','password'); $sp = array ( 'JOBNAME' => 'QPADEV0012', 'SPLFNAME' => 'QPJOBLOG', 'SPLFNBR' => 3, 'USERNAME' => 'ENRICO', 'JOBNBR' => '697478' ); header("Content-Disposition: inline; filename=spool.pdf"); header("Content-type: application/x-pdf"); echo $spool->toPdf($sp); |
In the line 2 we create an i5Spool object passing the host, username and password to connect to the i5 system. In order to export a spool to PDF we use the toPdf method.
We have to pass the information related to the spool file: job name (JOBNAME), job number (JOBNBR), user (USERNAME), spool name (SPLFNAME) and spool number (SPLFNBR).
The toPdf function returns a string contains the PDF so you have to print it if you want to pass to the browser (line 12).
The toPdf method has a second optional parameter, an array contains the format of the PDF page.
The format of a PDF page is composed by (the default values are reported in parenthesis):

For instance if you want to change the font size, the margins and the interline you can use the follow array as second parameter of the toPdf method:
1 2 3 4 5 6 7 | $format= array ( 'font-size' => 10, 'interline' => 11, 'margin-left' => 30, 'margin-top' => 30, 'margin-bottom' => 30 ); |
For more info about the i5 Toolkit for PHP you can visit this web page: http://files.zend.com/help/Zend-Core-i5-Help/i5_php_connector_api.htm
This is my personal blog about computer programming in PHP for business and passion. I'm Enrico Zimuel a Software Engineer since 1996. I work as Senior Consultant & Architect at Zend Technologies. For more info about me visit my web site.
6 Responses to Convert a spool file to PDF using PHP on i5/OS
Alberto Ernestini
February 12th, 2010 at 11:21 pm
Your article sound very interesting. As a Iseries specialist from too many years i’ve tried to set it up on a test system, but i may need better PHP experience
By example the i5spool asks also for a ‘JOBNR’ parameter and i wasn’t able to set the correct font. i still get a error.
There is anything missing?
Thanks a lot.
Ciao.
Alberto.
Enrico Zimuel
February 13th, 2010 at 6:23 pm
Hi Alberto,
What’s the error message that you got? Which version of ZF are you using?
In the i5Spool class you can use the function getList($user[,$num]) to get all the data of the user’s spool files (the $num is an optional parameter to get only the first $num spool file).
Alberto Ernestini
February 15th, 2010 at 10:55 am
Hi , thanks for your prompt answer!
This is the error :
Catchable fatal error: Argument 1 passed to Zend_Pdf_Page::setFont() must be an instance of Zend_Pdf_Resource_Font, string given, called in /usr/local/Zend/5250/demos/emulation/i5Spool.php on line 111 and defined in /usr/local/Zend/ZendFramework/library/Zend/Pdf/Page.php on line 586
and this is what i am having on my Iseries 515 :
1ZCORE5 *BASE 5001 Zend Core for IBM i5/OS (2.6.1)
1ZCORE5 1 5002 Zend Platform for IBM i5/OS (3.6.1 )
The Zend FW version is 1.6.0.
Thanks!
Ciao.
Alberto.
Enrico Zimuel
February 16th, 2010 at 4:22 pm
Hi Alberto, did you tried to install the last ZF version? I guess this problem comes out using an old version of ZF. I tried the example in the post using ZF 1.9.6 on i5/OS and i didn’t found your error.
Alberto Ernestini
February 16th, 2010 at 4:30 pm
Almost solved!!
There was some problems on the Iseries side.
A Codepage font problem reported as ‘ Wrong Charset conversion from utf-8 to CP1252//IGNORE is not allowed’.
For this i had to modify the Font/Simple.php in this way :
/Zend/Pdf/Resource/Font/Simple.php
line 259, replace :
return iconv($charEncoding, ‘CP1252//IGNORE’, $string);
with
return $string;
and line 273, replace :
return iconv(’CP1252′, $charEncoding, $string);
with
return $string;
(taken from a Zend Forum post of Mon, 04 August 2008)
and also the other error was because of line 111 on i5spool.php under toPdf function
$page->setFont($conf_pdf['font'],$conf_pdf['font-size']);
changing it with this :
$page->setFont(Zend_Pdf_Font::fontWithName($conf_pdf['font']),(int)$conf_pdf['font-size']);
solved the font problem.
there is also a extra addition on the i5spool.php, at the new page i had to add this line after line 123
$page->setFont(Zend_Pdf_Font::fontWithName($conf_pdf['font']),(int)$conf_pdf['font-size']);
this for set the font also on the new page.
Now the code works well , except for the breakpage but i think i can fix it
Thanks a lot!
Ciao
Alberto
Enrico Zimuel
February 16th, 2010 at 4:38 pm
Hi Alberto, i found that this was a bug of your ZF version. In the new version of ZF this issue has been solved with the management of AIX (i5/OS) environments.
In /Zend/Pdf/Resource/Font/Simple.php in the new ZF version there is this patch:
public function encodeString($string, $charEncoding)
{
if (PHP_OS == ‘AIX’) {
return $string; // returning here b/c AIX doesnt know what CP1252 is
}
return iconv($charEncoding, ‘CP1252//IGNORE’, $string);
}
I suggest you to upgrade your version of ZF with the last one.
Regarding the issue of the new PDF page in the i5Spool class I just fixed the problem. I updated the class in the post, thanks!