header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Vivek
Points:0
Posts:0

3/23/2011 4:04:57 AM

Title: How to take snapshot of text area which was displayed by user given input and insert it in to pdf



<?xml version="1.0" encoding="utf-8"?>  
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>  
		<![CDATA[ 
			import mx.collections.*;
			import mx.graphics.ImageSnapshot;
			
			import org.alivepdf.display.Display;
			import org.alivepdf.fonts.*;
			import org.alivepdf.layout.*;
			import org.alivepdf.pages.Page;
			import org.alivepdf.pdf.PDF;
			import org.alivepdf.saving.Method;
			
			[Bindable] private var datagridDataProvider:ArrayCollection= new ArrayCollection();
			
			private function takeSnapshot(source:IBitmapDrawable):void 
			{
				datagridDataProvider.addItem({userFirstName:this.firstNameInput.text, userLastName:this.lastNameInput.text, userAgeInput:this.ageInput.text});
				datagridDataProvider.refresh();
				
				this.textArea.text = this.firstNameInput.text + "\n" + this.lastNameInput.text + "\n" + this.ageInput.text;
				
				var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(source);
				swfLoader.source = new Bitmap(imageBitmapData);
				
				var userPDF:PDF; 
				userPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4 ); 
				userPDF.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE );
				
				var newPage:Page = new Page(Orientation.PORTRAIT, Unit.MM, Size.A4 );
				userPDF.addPage(newPage);
				
				userPDF.setFontSize(14);
				userPDF.addText(this.firstNameInput.text + "\n",5,15);
				userPDF.addPage();
				
				var pdfFileStream:FileStream = new FileStream(); 
				var pdfFile:File; 
				
				pdfFile = File.desktopDirectory.resolvePath("Data.pdf");   
				pdfFileStream.open( pdfFile, FileMode.WRITE);   
				
				var pdfBytes:ByteArray = userPDF.save(Method.LOCAL);   
				pdfFileStream.writeBytes(pdfBytes);   
				pdfFileStream.close();  
				
			}
			
		]]>   
	</mx:Script>
	
	<mx:Form>
		<mx:FormItem height="56">
			<mx:Label id="firstName" text="First Name" fontWeight="bold"/>
			<mx:TextInput id="firstNameInput" restrict="A-Z\\a-z\\ "/>
		</mx:FormItem>
		
		<mx:FormItem height="56">
			<mx:Label id="lastName" text="Last Name" fontWeight="bold"/>
			<mx:TextInput id="lastNameInput" restrict="A-Z\\a-z\\ "/>
		</mx:FormItem>
		
		<mx:FormItem height="56">
			<mx:Label id="age" text="Age" fontWeight="bold" textAlign="left"/>
			<mx:TextInput id="ageInput" restrict="0-9"/>
		</mx:FormItem>
		
		<mx:FormItem>
					<mx:DataGrid width="426" id="dataGrid" dataProvider="{datagridDataProvider}" showHeaders="true" height="234">
						  <mx:columns>
							  <mx:DataGridColumn headerText="First Name" dataField="userFirstName" width="80"/>
							  <mx:DataGridColumn headerText="Last Name" dataField="userLastName" width="80"/>
							  <mx:DataGridColumn headerText="Age" dataField="userAgeInput" width="35"/>
						  </mx:columns>
					  </mx:DataGrid>
			<mx:SWFLoader id="swfLoader">
			<mx:filters>
					<mx:DropShadowFilter />
				</mx:filters>
			</mx:SWFLoader>
		</mx:FormItem>
		<mx:TextArea id="textArea"/>	
		<mx:Button click="takeSnapshot(textArea)" label="Generate PDF" horizontalCenter="0" verticalCenter="0"/> 
	</mx:Form>
	
</mx:WindowedApplication>



1
Rex
Points: 1280
Posts:0
3/26/2011 11:20:05 AM



is it a working solution?


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 6+5 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions