<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Giametta &#187; AIR</title>
	<atom:link href="http://www.appfoundation.com/blogs/giametta/tag/air/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.appfoundation.com/blogs/giametta</link>
	<description>Rich Internet Apps</description>
	<lastBuildDate>Wed, 19 Oct 2011 22:22:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Render PDF in Adobe AIR with PDF Scaling</title>
		<link>http://www.appfoundation.com/blogs/giametta/2009/04/14/render-pdf-in-adobe-air-with-pdf-scaling/</link>
		<comments>http://www.appfoundation.com/blogs/giametta/2009/04/14/render-pdf-in-adobe-air-with-pdf-scaling/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 19:34:21 +0000</pubDate>
		<dc:creator>Chris Giametta</dc:creator>
				<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Rich Internet]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://www.appfoundation.com/blogs/giametta/?p=45</guid>
		<description><![CDATA[AIR can render PDFs using the HTMLControl as long as the host computer
has Acrobat 8 or later installed.
I have seen many examples of doing this, just without the ability to scale the PDF larger and smaller when a resize of the AIR application occurs. So I worked that issue out ...]]></description>
			<content:encoded><![CDATA[<p>AIR can render PDFs using the HTMLControl as long as the host computer<br />
has Acrobat 8 or later installed.</p>
<p>I have seen many examples of doing this, just without the ability to scale the PDF larger and smaller when a resize of the AIR application occurs. So I worked that issue out and wanted to share it with the Flex community.</p>
<p>To load a PDF into an AIR application, use the HTMLLoader class to load the PDF into your AIR window. Since you cannot add the HTMLLoader as a child, you will need to create a <em>UIComponent()</em> to add the PDF to a container.</p>
<p>If you look at the <em>addFile() </em>function, you will see that I first checked the PDF capability had a STATUS_OK before proceeding to the PDF loading steps with the following line of code:</p>
<p><code>if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK) {}</code></p>
<p>Once successful, I created an URLRequest to locate the PDF on my Tomcat server. You could easily add a parameter to set the PDF based on your content management as needed.</p>
<p>I then set the PDF&#8217;s initial height and width to that of the <em><mx:VBox></em> with the id of <strong>container</strong>. After that is done, I loaded the PDF to the HTMLLoader from the URLRequest.</p>
<p>Now that you have a handle on the PDF and it is loaded to the AIR application, you can use the <em>UIComponent.addChild </em>function to add the PDF to the UIComponent. After that, you need to add the child to the <em><mx:VBox></em> which is done by calling the <em>addChild() </em>function on <strong>container</strong>.</p>
<p>If you look at the example from the Adobe Livedocs you will notice they give the PDF&#8217;s height and width static numbers. What we want to do is allow the PDF to scale on window resize. To accomplish this, create a new function that is executed everytime the application is resized. In this example, I created the <em>scalePDF() </em>function that is called by the <strong>resize </strong>function on the <em><mx:VBox></em> as follows:</p>
<p><code><mx:VBox id="container" width="100%" height="100%" resize="scalePDF()"/></code></p>
<p>Since the width and height are set to 100% on the <em><mx:VBox></em> and I set the PDF&#8217;s height and width to the <em><mx:VBox> </em>height and width, the PDF will resize to fit the width and height of the <em><mx:VBox></em> every time it is resized. This will always give you the maximum reading space available for the PDF.</p>
<p>Here is the full source for this example. You can take this code and create a component that can be reused throughout your AIR applications. Enjoy.</p>
<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:WindowedApplication
   xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"&gt;

   &lt;mx:Script&gt;
      &lt;![CDATA[
      import mx.core.UIComponent;

      private var pdf:HTMLLoader = new HTMLLoader();

      private function addFile():void
      {
         if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK)
         {
            var request:URLRequest =
               new URLRequest("http://localhost:8080/af_Central/a.pdf");

            pdf.height = container.width;
            pdf.width = container.width;

            pdf.load(request);

            var ui:UIComponent = new UIComponent();
            ui.addChild(pdf)

            container.addChild(ui);
         }
         else
         {
            trace("PDF cannot be displayed. Error code:",
               HTMLLoader.pdfCapability);
         }
      }
      private function scalePDF():void
      {
         pdf.height = container.width;
         pdf.width = container.width;
      }
      ]]&gt;
   &lt;/mx:Script&gt;

   &lt;mx:Button label="Do It" click="addFile()" /&gt;
   &lt;mx:VBox id="container" width="100%" height="100%"
      resize="scalePDF()"/&gt;

&lt;/mx:WindowedApplication&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.appfoundation.com/blogs/giametta/2009/04/14/render-pdf-in-adobe-air-with-pdf-scaling/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

