pdf page to image c# itextsharp : Create a pdf form online software SDK cloud windows wpf winforms class 05-welling-php-mysql-web88-part140

847
Solution Overview
$this->url = ‘http://xml.amazon.com/onca/xml2?t=’.ASSOCIATEID
.’&dev-t=’.DEVTAG.’&KeywordSearch=’
.$search.’&mode=’.$this->mode
.’&type=heavy&page=’
.$this->page
.’&sort=+salesrank&f=xml’;
$this->parseXML();
}
return $this->products;
}
// Parse the XML into Product object(s)
function parseXML()
{
// suppress errors because this will fail sometimes
$xml = @simplexml_load_file($this->url);
if(!$xml)
{
//try a second time in case just server busy
$xml = @simplexml_load_file($this->url);
if(!$xml)
{
return false; 
}
}
$this->totalResults = (integer)$xml->TotalResults;
foreach($xml->Details as $productXML)
{
$this->products[] = new Product($productXML);
}
}
}
?>
This useful class does exactly the sort of thing classes are good for.It encapsulates the
interface to Amazon in a nice black box.Within the class,the connection to Amazon can
be made either via the REST method or the SOAP method.The method it uses is
determined by the global 
METHOD
constant you set in 
constants.php
.
Let’s begin by going back to the Category Search example.You use the
AmazonResultSet
class as follows:
$ars = new AmazonResultSet;
$ars->browseNodeSearch($parameters[‘browsenode’], 
$parameters[‘page’], 
$parameters[‘mode’]);
Listing 33.8 Continued 
Create a pdf form 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
chrome save pdf with fields; add jpg to pdf form
Create a pdf form 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
allow users to save pdf form; create a fillable pdf form online
848
Chapter 33 Connecting to Web Services with XML and SOAP
This class has no constructor,so you go straight to that 
browseNodeSearch()
method.Here,
you pass it three parameters:the 
browsenode
number you are interested in (corresponding to,
say,Business & Investing or Computers & Internet);the page number,representing the
records you would like retrieved;and the mode,representing the type of merchandise you are
interested in.An excerpt of the code for this method is shown in Listing 33.9.
Listing 33.9 browseNodeSearch() Method—Performing a Category Search
function browseNodeSearch($browseNode, $page, $mode)
{
if(METHOD==’SOAP’)
{
$soapclient = new soapclient(
‘http://soap.amazon.com/schemas2/AmazonWebServices.wsdl’,
‘wsdl’);
$soap_proxy = $soapclient->getProxy();
$parameters[‘mode’]=$mode;
$parameters[‘page’]=$page;      
$parameters[‘type’]=’heavy’;
$parameters[‘tag’]=$this->assocID;
$parameters[‘devtag’]=$this->devTag;
$parameters[‘sort’]=’+salesrank’;
$parameters[‘browse_node’] = $browseNode;
// perform actual soap query
$result = $soap_proxy->BrowseNodeSearchRequest($parameters);
if(isSOAPError($result))
return false;
$this->totalResults = $result[‘TotalResults’];
foreach($result[‘Details’] as $product)
{
$this->products[] = new Product($product);
}
unset($soapclient);
unset($soap_proxy);
   
else
{
// form URL and call parseXML to download and parse it
$this->type = ‘browse’;
$this->browseNode = $browseNode;
$this->page = $page;
$this->mode = $mode;
VB.NET PDF - Create PDF Online with VB.NET HTML5 PDF Viewer
C# Protect: Add Password to PDF; C# Form: extract value from NET: ASP.NET PDF Editor; VB.NET: WPF PDF Viewer; VB.NET: Create PDF from Word; VB.NET: Create PDF from
create a form in pdf from word; change font size in pdf form field
VB.NET PDF Form Data Read library: extract form data from PDF in
RasterEdge .NET PDF SDK is such one provide various of form field edit functions. Demo Code to Retrieve All Form Fields from a PDF File in VB.NET.
best program to create pdf forms; pdf form change font size
849
Solution Overview
$this->url = ‘http://xml.amazon.com/onca/xml2?t=’.ASSOCIATEID
.’&dev-t=’.DEVTAG.’&BrowseNodeSearch=’
.$this->browseNode.’&mode=’.$this->mode
.’&type=heavy&page=’.$this->page
.’&sort=+salesrank&f=xml’;
$this->parseXML();
}
return $this->products;
}
Depending on the value of the 
METHOD
constant,this method performs the query via
REST or via SOAP. Next,we look at each of these methods separately.
Using REST/XML Over HTTP
To use REST/XML over HTTP,you begin by setting a few important class member
variables:
n
type
—The type of search required.You are searching for books within a particular
browsenode
,so you set the value to 
browse
.
n
browse
—The value of the particular 
browsenode
you have been passed as a
parameter.
n
page
—The page number that you have been passed as a parameter.
n
mode
—The type of item you are searching for (for example,
books
) that you have
been passed as a parameter.
n
url
—The URL at Amazon that you need to connect to in order to perform this
type of search.
The URLs that you make your HTTP connections to for different types of searches and
the parameters they expect can be found in the Amazon.com Web Services API and
Integration Guide in your developer’s kit.Look closely at the 
GET
parameters passed in
here:
$this->_url = ‘http://xml.amazon.com/onca/xml2?t=’.ASSOCIATEID
.’&dev-t=’.DEVTAG.’&BrowseNodeSearch=’
.$this->_browseNode.’&mode=’.$this->_mode
.’&type=heavy&page=’.$this->_page
.’&sort=+salesrank&f=xml’;
Listing 33.9 Continued 
C# HTML5 PDF Viewer SDK to create PDF document from other file
C# Protect: Add Password to PDF; C# Form: extract value from NET: ASP.NET PDF Editor; VB.NET: WPF PDF Viewer; VB.NET: Create PDF from Word; VB.NET: Create PDF from
create a fillable pdf form from a pdf; add image field to pdf form
VB.NET Create PDF from Word Library to convert docx, doc to PDF in
C# Protect: Add Password to PDF; C# Form: extract value from NET: ASP.NET PDF Editor; VB.NET: WPF PDF Viewer; VB.NET: Create PDF from Word; VB.NET: Create PDF from
change font pdf form; create a pdf form from excel
850
Chapter 33 Connecting to Web Services with XML and SOAP
The parameters you need to pass to this URL are as follows:
n
t
—Your Associate ID.
n
dev-t
—Your developer token.
n
BrowseNodeSearch
—The 
browsenode
number you want to search.
n
mode
books
,or another valid product type.
n
type
Heavy
or 
lite
(note spelling!).
Heavy
gives more information.
n
page
—Group of 10 results.
n
sort
—The order you would like the results returned in.This parameter is option-
al.In this case, we set it to 
+salesrank
because we wanted results in sales rank
order.
n
f
—The format.This parameter should always contain the value 
‘xml’
.
Valid sort types are as follows:
n
Featured Items:
+pmrank
n
Bestselling:
+salesrank
n
Average Customer Review:
+reviewrank
n
Price (Low to High):
+pricerank
n
Price (High to Low):
+inverse-pricerank
n
Publication Date:
+daterank
n
Alphabetical (A-Z):
+titlerank
n
Alphabetical (Z-A):
-titlerank
After you set all these parameters,you call
$this->parseXML();
to actually do the work.The 
parseXML()
method is shown in Listing 33.10.
Listing 33.10 parseXML() Method—Parsing the XML Returned from a Query
// Parse the XML into Product object(s)
function parseXML()
{
// suppress errors because this will fail sometimes
$xml = @simplexml_load_file($this->url);
if(!$xml)
{
//try a second time in case just server busy
$xml = @simplexml_load_file($this->url);
if(!$xml)
{
return false; 
}
VB.NET Create PDF from PowerPoint Library to convert pptx, ppt to
C# Protect: Add Password to PDF; C# Form: extract value from NET: ASP.NET PDF Editor; VB.NET: WPF PDF Viewer; VB.NET: Create PDF from Word; VB.NET: Create PDF from
adding text to pdf form; adding images to pdf forms
VB.NET Create PDF from Excel Library to convert xlsx, xls to PDF
C# Protect: Add Password to PDF; C# Form: extract value from NET: ASP.NET PDF Editor; VB.NET: WPF PDF Viewer; VB.NET: Create PDF from Word; VB.NET: Create PDF from
change font in pdf fillable form; add text fields to pdf
851
Solution Overview
}
$this->totalResults = (integer)$xml->TotalResults;
foreach($xml->Details as $productXML)
{
$this->products[] = new Product($productXML);
}
}
The function 
simplexml_load_file()
does most of the work for you.It reads in the
XML content from a file or,in this case, an URL. It provides an object-oriented inter-
face to the data and the structure in the XML document.This is a useful interface to the
data, but because you want one set of interface functions to work with data that has
come in via REST or SOAP,you can build your own object-oriented interface to the
same data in instances of the 
Product
class. Note that you cast the attributes from the
XML into PHP variable types in the REST version.You do not use the 
cast
operator
in PHP,but without it here,you would receive object representations of each piece of
data that will not be very useful to you.
The 
Product
class contains mostly accessor functions to access the data stored in its
private members, so printing the entire file here is not worthwhile.The stucture of the
class and constructor is worth visiting,though. Listing 33.11 contains part of the defini-
tion of 
Product
.
Listing 33.11 The Product Class Encapsulates the Information You Have About an
Amazon Product
class Product
{
private $ASIN;
private $productName;
private $releaseDate;
private $manufacturer;
private $imageUrlMedium;
private $imageUrlLarge;
private $listPrice;
private $ourPrice;
private $salesRank;
private $availability;
private $avgCustomerRating;
private $authors = array();
private $reviews = array();
private $similarProducts = array();
Listing 33.10 Continued 
C# PDF Form Data Read Library: extract form data from PDF in C#.
A best PDF document SDK library enable users abilities to read and extract PDF form data in Visual C#.NET WinForm and ASP.NET WebForm applications.
can save pdf form data; add an image to a pdf form
VB.NET PDF- View PDF Online with VB.NET HTML5 PDF Viewer
C# Protect: Add Password to PDF; C# Form: extract value from NET: ASP.NET PDF Editor; VB.NET: WPF PDF Viewer; VB.NET: Create PDF from Word; VB.NET: Create PDF from
add form fields to pdf; add email button to pdf form
852
Chapter 33 Connecting to Web Services with XML and SOAP
function __construct($xml)
{
if(METHOD==’SOAP’)
{
$this->ASIN = $xml[‘Asin’];
$this->productName = $xml[‘ProductName’];
if($xml[‘Authors’])
{
foreach($xml[‘Authors’] as $author)
{
$this->authors[] = $author;
}
}
$this->releaseDate = $xml[‘ReleaseDate’];
$this->manufacturer = $xml[‘Manufacturer’];
$this->imageUrlMedium = $xml[‘ImageUrlMedium’];
$this->imageUrlLarge = $xml[‘ImageUrlLarge’];
$this->listPrice = $xml[‘ListPrice’];
$this->listPrice = str_replace(‘$’, ‘’, $this->listPrice);
$this->listPrice = str_replace(‘,’, ‘’, $this->listPrice);
$this->listPrice = floatval($this->listPrice);
$this->ourPrice = $xml[‘OurPrice’];
$this->ourPrice = str_replace(‘$’, ‘’, $this->ourPrice);
$this->ourPrice = str_replace(‘,’, ‘’, $this->ourPrice);
$this->ourPrice = floatval($this->ourPrice);
$this->salesRank = $xml[‘SalesRank’];
$this->availability = $xml[‘Availability’];
$this->avgCustomerRating = $xml[‘Reviews’][‘AvgCustomerRating’];
$reviewCount = 0;
if($xml[‘Reviews’][‘CustomerReviews’])
{
foreach ($xml[‘Reviews’][‘CustomerReviews’] as $review)
{
$this->reviews[$reviewCount][‘rating’] = $review[‘Rating’];
$this->reviews[$reviewCount][‘summary’] = $review[‘Summary’];
$this->reviews[$reviewCount][‘comment’] = $review[‘Comment’];
$reviewCount++;
}
}
Listing 33.11 Continued 
C# HTML5 PDF Viewer SDK to view PDF document online in C#.NET
C# Protect: Add Password to PDF; C# Form: extract value from NET: ASP.NET PDF Editor; VB.NET: WPF PDF Viewer; VB.NET: Create PDF from Word; VB.NET: Create PDF from
create a pdf form online; can reader edit pdf forms
VB.NET PDF Convert to Tiff SDK: Convert PDF to tiff images in vb.
NET. Create multipage Tiff image files from PDF in VB.NET project. NET. Convert PDF file to Tiff and jpeg in ASPX webpage online. Online
convert pdf to editable form; change font size pdf form
853
Solution Overview
if($xml[‘SimilarProducts’])
{
foreach ($xml[‘SimilarProducts’] as $similar)
{
$this->similarProducts[] = $similar;
}
}
}
else // using REST
{
$this->ASIN = (string)$xml->Asin;
$this->productName = (string)$xml->ProductName;
if($xml->Authors->Author)
{
foreach($xml->Authors->Author as $author)
{
$this->authors[] = (string)$author;
}
}
$this->releaseDate = (string)$xml->ReleaseDate;
$this->manufacturer = (string)$xml->Manufacturer;
$this->imageUrlMedium = (string)$xml->ImageUrlMedium;
$this->imageUrlLarge = (string)$xml->ImageUrlLarge;
$this->listPrice = (string)$xml->ListPrice;
$this->listPrice = str_replace(‘$’, ‘’, $this->listPrice);
$this->listPrice = str_replace(‘,’, ‘’, $this->listPrice);
$this->listPrice = floatval($this->listPrice);
$this->ourPrice = (string)$xml->OurPrice;
$this->ourPrice = str_replace(‘$’, ‘’, $this->ourPrice);
$this->ourPrice = str_replace(‘,’, ‘’, $this->ourPrice);
$this->ourPrice = floatval($this->ourPrice);
$this->salesRank = (string)$xml->SalesRank;
$this->availability = (string)$xml->Availability;
$this->avgCustomerRating = (float)$xml->Reviews->AvgCustomerRating;
$reviewCount = 0;
if($xml->Reviews->CustomerReview)
{
foreach ($xml->Reviews->CustomerReview as $review)
Listing 33.11 Continued 
854
Chapter 33 Connecting to Web Services with XML and SOAP
{
$this->reviews[$reviewCount][‘rating’] = (float)$review->Rating;
$this->reviews[$reviewCount][‘summary’] = (string)$review->Summary;
$this->reviews[$reviewCount][‘comment’] = (string)$review->Comment;
$reviewCount++;
}
}
if($xml->SimilarProducts->Product)
{
foreach ($xml->SimilarProducts->Product as $similar)
{
$this->similarProducts[] = (string)$similar;
}
}
}
}
Again, this constructor takes two different forms of input data and creates one applica-
tion interface.Note that while some of the handling code could be made more generic,
some tricky attributes such as reviews have different names depending on the method.
Having gone through all this processing to retrieve the data,you now return control
back to the 
getARS()
function and hence back to 
showBrowseNode()
.The next step is
showSummary($ars->products(), $page, 
$ars->totalResults(), $mode, 
$browseNode);
The 
showSummary()
function simply displays the data in the 
AmazonResultSet
,as you
can see it all the way back in Figure 33.1.We therefore did not include the function
here.
Using SOAP
Let’s go back and look at the SOAP version of the 
browseNodeSearch()
function.This
section of the code is repeated here:
$soapclient = new soapclient(
‘http://soap.amazon.com/schemas2/AmazonWebServices.wsdl’,
‘wsdl’);
$soap_proxy = $soapclient->getProxy();
$parameters[‘mode’]=$mode;
$parameters[‘page’]=$page;      
$parameters[‘type’]=’heavy’;
$parameters[‘tag’]=$this->assocID;
$parameters[‘devtag’]=$this->devTag;
$parameters[‘sort’]=’+salesrank’;
$parameters[‘browse_node’] = $browseNode;
Listing 33.11 Continued 
855
Solution Overview
// perform actual soap query
$result = $soap_proxy->BrowseNodeSearchRequest($parameters);
if(isSOAPError($result))
return false;
$this->totalResults = $result[‘TotalResults’];
foreach($result[‘Details’] as $product)
{
$this->products[] = new Product($product);
}
unset($soapclient);
unset($soap_proxy) ;
There are no extra functions to go through here;the SOAP client does everything for
you.
You begin by creating an instance of the SOAP client:
$soapclient = new soapclient(
‘http://soap.amazon.com/schemas2/AmazonWebServices.wsdl’,
‘wsdl’);
Here, you provide the client with two parameters.The first is the WSDL description of
the service,and the second parameter tells the SOAP client that this is a WSDL URL.
Alternatively,you could just provide one parameter:the endpoint of the service,which is
the direct URL of the SOAP Server.
We chose to do it this way for a good reason,which you can see right there in the
next line of code:
$soap_proxy = $soapclient->getProxy();
This line creates a class according to the information in the WSDL document.This class,
the SOAP proxy,will have methods that correspond to the methods of the Web Service.
This makes life much easier.You can interact with the Web Service as though it were a
local PHP class.
Next, you set up an array of the parameters you need to pass to the 
browsenode
query:
$parameters[‘mode’]=$mode;
$parameters[‘page’]=$page;
$parameters[‘type’]=’heavy’;
$parameters[‘tag’]=$this->_assocID;
$parameters[‘devtag’]=$this->_devTag;
$parameters[‘sort’]=’+salesrank’;
$parameters[‘browse_node’] = $browseNode;
Using the 
proxy
class,you can then just call the Web Service methods,passing in the
array of parameters:
856
Chapter 33 Connecting to Web Services with XML and SOAP
$result = $soap_proxy->BrowseNodeSearchRequest($parameters);
The data stored in 
$result
is an array that you can directly store as a Product object in
the 
products
array in the 
AmazonResultSet
class.
Caching the Data
Let’s go back to the 
getARS()
function and address caching.As you might recall,the
function looks like this:
// Get an AmazonResultSet either from cache or a live query
// If a live query add it to the cache
function getARS($type, $parameters)
{
$cache = cached($type, $parameters);
if($cache)  // if found in cache
{
return  $cache;
}
else
{
$ars = new AmazonResultSet;
if($type == ‘asin’)
$ars->ASINSearch(padASIN($parameters[‘asin’]), $parameters[‘mode’]);
if($type == ‘browse’)                   
$ars->browseNodeSearch($parameters[‘browsenode’], $parameters[‘page’], 
$parameters[‘mode’]);
if($type == ‘search’)
$ars->keywordSearch($parameters[‘search’], $parameters[‘page’], 
$parameters[‘mode’]);
cache($type, $parameters, $ars);
}
return $ars;
}
All the application’s SOAP or XML caching is done via this function.You also use
another function to cache images.You begin by calling the 
cached()
function to see
whether the required 
AmazonResultSet
is already cached.If it is,you return that data
instead of making a new request to Amazon:
$cache = cached($type, $parameters);
if($cache)  // if found in cache
{
return  $cache;
}
If not,when you get the data back from Amazon,you add it to the cache:
Documents you may be interested
Documents you may be interested