× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I don't know if anyone would actually want to do this, but you can use PHP to open and read the HTML file from the URL. The HTML page is read as a stream file. Then process the file and turn it into a PDF using Zend Framework.

Personally, I think anyone who needs to easily move between HTML and PDF would be better off using XML as the source document. Use XSL or write a PHP program that parses XML to convert to HTML. Write a PHP program that parses the same XML and turns it into a PDF.

Thanks,

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 Shannon ODonnell
Sent: Friday, February 26, 2010 9:03 AM
To: 'Web Enabling the AS400 / iSeries'
Subject: Re: [WEB400] Zend PDF and the RPG Experiment

This is very cool (extremely cool actually!) I LOVE PHP! It's soooo much
easier to almost everything with PHP than it is with RPG.

But...this doesn't solve Aaron's problem of capturing the HTML form itself
and turning that into a PDF. At least not as I understood what he was
asking for.

This instead takes a separate instance of the data and rebuilds it into a
PDF, right?

Or maybe that's good enough for Aaron's needs in this case.


The one benefit to the approach I offered yesterday is that it captures the
users browser session exactly as is and creates an image of that which can
then be used as is or converted to a PDF or whatever. The data is only
touched once. With very little code. In fact, the entire code is a little
bit of JavaScript and a very small java program:



<HTML>

<HEAD>

<TITLE>Screen Capture Demo</TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT">

<!-- *************************************************-->
<!-- Set Dimensions for Screen Capture Rectangle -->
<!-- *************************************************-->
function getScreenCaptureDimensions()
{
window.status = "Capturing Image of Document...please stand by...";
var sl = window.screenLeft;
var cw = document.body.clientWidth;
var ch = document.body.clientHeight;
var imagename = 'YourImage';
var st = window.screenTop;
st = st + 2;
ch = ch - 1;
sl = sl + 3;
var DimensionParms = ('"' +
sl + '" "' +
st + '" "' +
cw + '" "' +
ch + '" "' +
imagename + '"');


capturescreen(DimensionParms);
}

<!-- *************************************************-->
<!-- Call Java program to perform screen capture
-->
<!-- *************************************************-->
function capturescreen(inParms)
{
var oShell = new ActiveXObject("Shell.Application");
oShell.ShellExecute ("C:\\SCAP1.lnk", inParms, "0", "open", "0");
}

</SCRIPT>
</HEAD>
<BODY>
<FORM>
<!-- Enter your own HTML information here...... -->
<CENTER>

Click on the button below to capture the screen to a JPEG file. <br>
A new image file named "YourImage.JPEG" will be created in the root
directory.<br>

<br><br>
<input type="Button" name="Capture" value="Capture Screen as JPEG"
onClick="getScreenCaptureDimensions()" />
</center>

</FORM>

</BODY>
</HTML>




//**************************************************************************
**********
//
//
// ScreenCapture
//
// Author: Shannon O'Donnell
// IT Jungle 2002
//
// Function: Creates a JPEG image of that portion of the screen (defined as
a Rectangle)
// passed as coordinates to this application
//
// Parameters: Top - Top portion of the screen area to be captured
// TopLeft - Top Left portion of the screen area to be
captured
// Width - Width of the screen area to be captured
// Height - Height of the screen area to be captured
//
//**************************************************************************
**********

import java.io.*;
import java.awt.*;
import java.awt.Robot;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;

public class ScreenCapture {

ScreenCapture (int intop, int inleft, int inwidth, int inheight, String
imageName) {

try {
BufferedImage capture = null;

Rectangle area = new Rectangle(intop, inleft, inwidth, inheight);
Robot robot = new Robot();
capture = robot.createScreenCapture(area);

String imgFile = "c:\\" + imageName + ".jpeg";
FileOutputStream out =
new FileOutputStream(imgFile);

JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(out);
encoder.encode(capture);
out.flush();
out.close();
System.exit(0);


} catch (Exception exc) {
System.out.println("errors ");
exc.printStackTrace();
}

finally {
System.out.println("Error Creating Image");
System.exit(0); }

}

//*******************************************************
public static void main(String args[])
{

int inputtop = Integer.parseInt(args[0]);
int inputleft = Integer.parseInt(args[1]);
int inputwidth = Integer.parseInt(args[2]);
int inputheight = Integer.parseInt(args[3]);
String inImage = args[4];

new ScreenCapture(inputtop, inputleft, inputwidth, inputheight, inImage);

}
}





-----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";

/* */



?>






As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.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 on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.