pdf page to image c# itextsharp : Add form fields to pdf online control software utility azure windows winforms visual studio 05-welling-php-mysql-web89-part141

857
Solution Overview
cache($type, $parameters, $ars);
Let’s look more closely at these two functions:
cached()
and 
cache()
.These functions,
shown in Listing 33.12,implement the caching Amazon requires as part of its terms and
conditions.
Listing 33.12 cached() and cache() Functions—Caching Functions from 
cachefunctions.php
// check if Amazon data is in the cache
// if it is, return it
// if not, return false
function cached($type, $parameters)
{
if($type == ‘browse’)
{
$filename =
➥CACHE.’/browse.’.$parameters[‘browsenode’].’.’.$parameters[‘page’].
‘.’.$parameters[‘mode’].’.dat’;
}
if($type == ‘search’)
{
$filename = CACHE.’/search.’.$parameters[‘search’].’.’.$parameters[‘page’].
‘.’.$parameters[‘mode’].’.dat’;
}
if($type == ‘asin’)
 
$filename = CACHE.’/asin.’.$parameters[‘asin’].’.’.$parameters[‘mode’].
‘.dat’;
}
// is cached data missing or > 1 hour old?
if(!file_exists($filename) ||
((mktime() - filemtime($filename)) > 60*60))
{
return false;
}
$data = file_get_contents($filename);
return unserialize($data);
}
// add Amazon data to the cache
function cache($type, $parameters, $data)
{
if($type == ‘browse’)
Add form fields to pdf online - C# PDF Field Edit Library: insert, delete, update pdf form field in C#.net, ASP.NET, MVC, Ajax, WPF
Online C# Tutorial to Insert, Delete and Update Fields in PDF Document
allow saving of pdf form; best way to make pdf forms
Add form fields to pdf online - VB.NET PDF Field Edit library: insert, delete, update pdf form field in vb.net, ASP.NET, MVC, Ajax, WPF
How to Insert, Delete and Update Fields in PDF Document with VB.NET Demo Code
change font size in pdf form; adding text field to pdf
858
Chapter 33 Connecting to Web Services with XML and SOAP
{
$filename = CACHE.’/browse.’.$parameters[‘browsenode’].
‘.’.$parameters[‘page’].’.’.$parameters[‘mode’].’.dat’;
}
if($type == ‘search’)
{
$filename = CACHE.’/search.’.$parameters[‘search’].’.’.$parameters[‘page’].
‘.’.$parameters[‘mode’].’.dat’;
}
if($type == ‘asin’)
{
$filename = CACHE.’/asin.’.$parameters[‘asin’].’.’.$parameters[‘mode’].
‘.dat’;
}
$data = serialize($data);
$fp = fopen($filename, ‘wb’);
if(!$fp||(fwrite($fp, $data)==-1))
{
echo  (‘<p>Error, could not store cache file’);
}
fclose($fp);
}
Looking through this code,you can see that cache files are stored under a filename that
consists of the type of query followed by the query parameters.The 
cache()
function
stores results by serializing them,and the 
cached()
function deserializes them.The
cached()
function will also overwrite any data more than an hour old,as per the terms
and conditions.
The function 
serialize()
turns stored program data into a string that can be stored.
In this case,you create a storable representation of an 
AmazonResultSet
object.Calling
unserialize()
does the opposite,turning the stored version back into a data structure
in memory.Note that unserializing an object like this means you need to have the class
definition in the file so that the class is comprehendible and usable once reloaded.
In this application,retrieving a resultset from the cache takes a fraction of a second.
Making a new live query takes up to 10 seconds.
Building the Shopping Cart
So,given all these amazing Amazon querying abilities,what can you do with them? The
most obvious thing you can build is a shopping cart. Because we already covered this
topic extensively in Chapter 27,we do not go into deep detail here.
The shopping cart functions are shown in Listing 33.13.
Listing 33.12 Continued 
VB.NET PDF Form Data Read library: extract form data from PDF in
Add necessary references: RasterEdge.Imaging.Basic.dll. using RasterEdge.XDoc.PDF; Demo Code to Retrieve All Form Fields from a PDF File in VB.NET.
acrobat create pdf form; create a fillable pdf form from a word document
C# PDF Form Data Read Library: extract form data from PDF in C#.
Add necessary references: RasterEdge.Imaging.Basic.dll. C#.NET Demo Code: Retrieve All Form Fields from a PDF File in C#.NET.
add editable fields to pdf; edit pdf form
859
Solution Overview
Listing 33.13 cartfunctions.php—Implementing the Shopping Cart
<?php
require_once(‘AmazonResultSet.php’);
// Using the function showSummary() in the file bookdisplay.php display
// the current contents of the shopping cart
function showCart($cart, $mode)
{
// build an array to pass
$products = array();
foreach($cart as $ASIN=>$product)
{
$ars = getARS(‘asin’, array(‘asin’=>$ASIN, ‘mode’=>$mode));
if($ars)
$products[] = $ars->getProduct(0);
}
// build the form to link to an Amazon.com shopping cart
echo ‘<form method=”POST”
action=”http://www.amazon.com/o/dt/assoc/handle-buy-box”>’;
foreach($cart as $ASIN=>$product)
{
$quantity = $cart[$ASIN][‘quantity’];
echo “<input type=’hidden’ name=’asin.$ASIN’ value=’$quantity’>”;
}
echo ‘<input type=”hidden” name=”tag-value” value=”ASSOCIATEID”>’;
echo ‘<input type=”hidden” name=”tag_value” value=”ASSOCIATEID”>’;
echo ‘<input type=”image” src=”images/checkout.gif”
name=”submit.add-to-cart”
value=”Buy From Amazon.com”>’;
echo ‘ When you have finished shopping press checkout to add all the 
items in your Tahuayo cart to your Amazon cart and complete 
your purchase.<br />’;
echo ‘</form>’;
echo ‘<a href = “index.php?action=emptycart”><img 
src = “images/emptycart.gif” alt = “Empty Cart” border = 0></a> 
If you have finished with this cart, you can empty it of all items.
<br />’;
echo ‘<h1>Cart Contents</h1>’;
showSummary($products, 1, count($products), $mode,  0, true);
}
.NET PDF Document Viewing, Annotation, Conversion & Processing
Form Process. Fill in form data programmatically. Read form data from PDF form file. Add, Update, Delete form fields programmatically. Document Protect.
create a fillable pdf form from a pdf; cannot save pdf form
VB.NET PDF insert image library: insert images into PDF in vb.net
Add images to any selected PDF page in VB.NET. Insert images into PDF form field in VB.NET. inserting image to PDF in preview without adobe PDF control installed.
create a pdf form from excel; adding a signature to a pdf form
860
Chapter 33 Connecting to Web Services with XML and SOAP
// show the small overview cart that is always on the screen
// only shows the last three items added 
function showSmallCart()
{
global $_SESSION;
echo ‘<table border = 1 cellpadding = 1 cellspacing = 0>’;
echo ‘<tr><td class = cartheading>Your Cart $’.
number_format(cartPrice(), 2).
‘</td></tr>’;
echo ‘<tr><td class = cart>’.cartContents().’</td></tr>’;
// form to link to an Amazon.com shopping cart
echo ‘<form method=”POST”
action=”http://www.amazon.com/o/dt/assoc/handle-buy-box”>’;
echo ‘<tr><td class = cartheading><a href = 
“index.php?action=showcart”><img 
src=”images/details.gif” border=0></a>’;
foreach($_SESSION[‘cart’] as $ASIN=>$product)
{
$quantity = $_SESSION[‘cart’][$ASIN][‘quantity’];
echo “<input type=’hidden’ name=’asin.$ASIN’ value=’$quantity’>”;
}
echo ‘<input type=”hidden” name=”tag-value” value=”ASSOCIATEID”>’;
echo ‘<input type=”hidden” name=”tag_value” value=”ASSOCIATEID”>’;
echo ‘<input type=”image” src=”images/checkout.gif”
name=”submit.add-to-cart” value=”Buy From Amazon.com”>’;
echo ‘</td></tr>’;
echo ‘</form>’;
echo ‘</table>’;
}
// show last three items added to cart
function cartContents()
{
global $_SESSION;
$display = array_slice($_SESSION[‘cart’], -3, 3);
// we want them in reverse chronological order
$display = array_reverse($display, true);
$result = ‘’;
$counter = 0;
Listing 33.13 Continued 
VB.NET PDF Password Library: add, remove, edit PDF file password
passwordSetting.IsAnnot = True ' Allow to fill form. passwordSetting document. passwordSetting.IsAssemble = True ' Add password to PDF file. PDFDocument
create a pdf form online; change pdf to fillable form
C# PDF insert image Library: insert images into PDF in C#.net, ASP
Insert images into PDF form field. Access to freeware download and online C#.NET class source code. How to insert and add image, picture, digital photo, scanned
convert pdf to editable form; adding text fields to pdf acrobat
861
Solution Overview
// abbreviate the names if they are long
foreach($display as $product)
{
if(strlen($product[‘name’])<=40)
$result .= $product[‘name’].’<br />’;
else
$result .= substr($product[‘name’], 0, 37).’...<br />’;
$counter++;
 
// add blank lines if the cart is nearly empty to keep the 
// display the same
for(;$counter<3; $counter++)  
{
$result .= ‘<br />’;
}
return $result;
}
// calculate total price of items in cart
function cartPrice()
{
global $_SESSION;
$total = 0.0;
foreach($_SESSION[‘cart’] as $product)
{
$price = str_replace(‘$’, ‘’, $product[‘price’]);
$total += $price*$product[‘quantity’];
}
return $total;
}
// add a single item to cart
// there is currently no facility to add more than one at a time
function addToCart(&$cart, $ASIN, $mode)
{
if(isset($cart[$ASIN] ))
{
$cart[$ASIN][‘quantity’] +=1;
}
else
{
Listing 33.13 Continued 
C# PDF Password Library: add, remove, edit PDF file password in C#
passwordSetting.IsAnnot = true; // Allow to fill form. passwordSetting document. passwordSetting.IsAssemble = true; // Add password to PDF file. PDFDocument
add text fields to pdf; adding images to pdf forms
VB.NET PDF File Compress Library: Compress reduce PDF size in vb.
Reduce image resources: Since images are usually or large size, images size reducing can help to reduce PDF file size effectively. Flatten form fields.
adding form fields to pdf; change text size pdf form
862
Chapter 33 Connecting to Web Services with XML and SOAP
// check that the ASIN is valid and look up the price
$ars = new AmazonResultSet;
$product = $ars->ASINSearch($ASIN, $mode);
if($product->valid())
$cart[$ASIN] = array(‘price’=>$product->ourPrice(), 
‘name’ => $product->productName(), ‘quantity’ => 1) ;
   
}
// delete all of a particular item from cart
function deleteFromCart(&$cart, $ASIN)
{
unset ($cart[$ASIN]);
}   
?>
There are some differences about the way you do things with this cart. For example,
look at the 
addToCart()
function.When you try to add an item to the cart,you can
check that it has a valid ASIN and look up the current (or at least,cached) price.
The really interesting issue here is this question:When customers check out,how do
you get their data to Amazon?
Checking Out to Amazon
Look closely at the 
showCart()
function in Listing 33.13.Here’s the relevant part:
// build the form to link to an Amazon.com shopping cart
echo ‘<form method=”POST”
action=”http://www.amazon.com/o/dt/assoc/handle-buy-box”>’;
foreach($cart as $ASIN=>$product)
{
$quantity = $cart[$ASIN][‘quantity’];
echo “<input type=’hidden’ name=’asin.$ASIN’ value=’$quantity’>”;
}
echo ‘<input type=”hidden” name=”tag-value” value=”ASSOCIATEID”>’;
echo ‘<input type=”hidden” name=”tag_value” value=”ASSOCIATEID”>’;
echo ‘<input type=”image” src=”images/checkout.gif”
name=”submit.add-to-cart” value=”Buy From Amazon.com”>’;
echo ‘ When you have finished shopping press checkout to add all the items 
in your Tahuayo cart to your Amazon cart and complete your purchase.
<br />’;
echo ‘</form>’;
Listing 33.13 Continued 
863
Extending the Project
The checkout button is a form button that connects the cart to a customer’s shopping
cart on Amazon.You send ASINs,quantities,and your Associate ID through as 
POST
vari-
ables.And hey,presto! You can see the result of clicking this button in Figure 33.5,earlier
in this chapter.
One difficulty with this interface is that it is a one-way interaction.You can add items
to the Amazon cart but cannot remove them.This means that people cannot browse
back and forth between the sites easily without ending up with duplicate items in their
carts.
Installing the Project Code
If you want to install the project code from this chapter,you will need to take a few steps
beyond the norm.After you have the code in an appropriate location on your server,you
need to do the following:
n
Create a cache directory.
n
Set the permissions on the cache directory so that the scripts will be able to write
in it.
n
Edit 
constants.php
to provide the location of the cache.
n
Sign up for an Amazon developer token.
n
Edit 
constants.php
to include your developer token and, optionally,your
Associate ID.
n
Make sure NuSOAP is installed.We included it inside the Tahuayo directory,but
you could move it and change the code.
n
Check that you have PHP5 compiled with simpleXML support.
Extending the Project
There are lots of fun things you could do to extend this project:
n
You could expand the types of searches that are available via Tahuayo.
n
You might like to experiment with Amazon’s XSLT Web Service.
n
You could check out the links to innovative sample applications in Amazon’s Web
Services How-To. Look at these applications for more ideas:
http://associates.amazon.com/exec/panama/associates/ntg/browse/-/567634/
Shopping carts are the most obvious thing to build with this data,but they are not the
only thing.
864
Chapter 33 Connecting to Web Services with XML and SOAP
Further Reading
A million books and online resources are available on the topics of XML and Web
Services.A great place to start is always at the W3C.You can look at the XML Working
Group page at
http://www.w3.org/XML/Core/
and the Web Services Activity page at
http://www.w3.org/2002/ws/
just as a beginning.
VI
Appendixes
A Installing PHP and MySQL
B Web Resources
Documents you may be interested
Documents you may be interested