I'm creating an ADOBE AIR application.
I have some text boxes and labels in my Hbox. I want to generate a pdf and have to add that hbox into that pdf ..lot of people telll about alivepdf .
I searched ,but have not seen a demo..If you have any idea ,Please share me ,or advice me..Thanks
I think it could help you.
This are my Air-application and the PDF-file.
//source
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
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;
protected function onBtnGeneratePDF(event:MouseEvent):void
{
var pdf:PDF = new PDF( Orientation.PORTRAIT, Unit.MM, Size.A4 );
pdf.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
var newPage:Page = new Page ( Orientation.PORTRAIT, Unit.MM, Size.A4 );
pdf.addPage( newPage );
pdf.addText("This is my PDF from AdobeFlex", 5, 10);
pdf.addImage(hgMain, null, 5, 10);
var fs:FileStream = new FileStream();
var file:File = File.desktopDirectory.resolvePath("testPage.pdf");
fs.open(file, FileMode.WRITE);
var bytes:ByteArray = pdf.save(Method.LOCAL);
fs.writeBytes(bytes);
fs.close();
}
]]>
</fx:Script>
<s:HGroup id="hgMain" x="10" y="10" width="439" height="161">
<s:Label text="MyLabel_01"/>
<s:TextArea width="133" height="116" contentBackgroundColor="#E6B3B3" fontStyle="italic"
text="MyTextArea"/>
<s:Label fontWeight="bold" text="MyLabel_02"/>
<s:TextArea width="127" height="69" contentBackgroundColor="#CED4F2" fontSize="15"
fontWeight="bold" text="MyTextArea"/>
</s:HGroup>
<s:Button x="10" y="179" label="Generate PDF" click="onBtnGeneratePDF(event)"/>
</s:WindowedApplication>
Related
I am trying to create links inside data grid cells and I am unable to remove the horizontal scroll bar
Here is my example
///////////////////////////////////////////
//GridExample.mxml - Main application
///////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<mx:Box id="myCustomBox" height="100%" width="100%" initialize="assignData();">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.HierarchicalData;
[Embed("dialog_error.png")]
private var myImage:Class;
public function assignData():void {
var retVal:ArrayCollection = new ArrayCollection();
var hData:HierarchicalData = new HierarchicalData();
var s:String = '[{"Property":"AA","Value":2,"RowIdentifier":"AA"},{"Property":"BB","Value":"Nice looking link","RowIdentifier":"BB"},{"Property":"CC","Value":"sdfgusgdfugadgfuasygdfgauidsguiasgdfugasuidfguiasg","RowIdentifier":"CC"}]';
var pSets:Object = JSON.parse(s);
var propertySets:Array = pSets as Array;
for (var i:int=0;i<propertySets.length;i++)
{
var item:Object = propertySets[i];
var arrayElt:Object = {Property: item["Property"], RowIdentifier: item["RowIdentifier"], Value: item["Value"]};
retVal.addItem(arrayElt);
}
hData.source = retVal;
myGridId.dataProvider = hData;
}
]]>
</fx:Script>
<mx:AdvancedDataGrid id="myGridId"
variableRowHeight="true"
width="100%"
showHeaders="false"
includeInLayout="{myGridId.visible}"
defaultLeafIcon="{null}"
>
<mx:columns >
<mx:AdvancedDataGridColumn dataField="Property" headerText="Property" backgroundColor="#E5EFF5" width="0.4" wordWrap="true" />
<mx:AdvancedDataGridColumn dataField="Value" headerText="Value" backgroundColor="white" width="0.6" itemRenderer="ExampleRenderer"/>
<mx:AdvancedDataGridColumn dataField="RowIdentifier" visible="false"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Box>
</s:WindowedApplication>
///////////////////////////////////////////
//ExampleRenderer.mxml - ItemRenderer used
///////////////////////////////////////////
<?xml version="1.0"?>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" textAlign="center" creationComplete="renderNow()" >
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.controls.LinkButton;
import mx.controls.Alert;
private function renderNow():void {
var dataObject:Object = super.data;
var rowId:String = dataObject["RowIdentifier"];
var label:LinkButton = new LinkButton();
label.addEventListener(MouseEvent.CLICK, mouseClick);
label.percentWidth = 100;
label.label = dataObject["Value"];
label.setStyle("horizontalScrollPolicy","off");
label.setStyle("textAlign","left");
label.setStyle("paddingLeft",3);
this.addChild(label);
}
override public function set data(value:Object):void
{
super.data = value;
dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
}
private function mouseClick(e:MouseEvent):void{
Alert.show("Clicked on a link");
}
]]>
</mx:Script>
</mx:Box>
The LinkButton produced nice links that can be clicked and in a web view it looks really good with a nice hover producing an underline (just like a link) etc but when the text is long, the horizontal scroll bar obscures the text itself. How do I get rid of the horizontal scrollbar (I have tried turning horizontalScrollPolicy off and that does not help). I do not mind if the extra text over and beyond the row length is hidden as I am going to add a tooltip anyway to every cell. Any help here is appreciated.
Thank you.
Setting the minWidth to 0 along with the percentWidth=100 fixed it.
I want to get motherboard ID in flex builder. This is my code. I follow this code to build my own Retrieve manufacturer information from device that AIR app is running on
But I got this error TypeError: Error #1009: Cannot access a property or method of a null object reference.
give me some solution please.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" showStatusBar="false" verticalAlign="middle"
name="Login" windowComplete="init()">
<mx:Script>
<![CDATA[
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.filesystem.File;
private var process:NativeProcess;
private function init():void
{
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = new File("C:/Windows/System32/cmd.exe");
nativeProcessStartupInfo.executable = file;
var processArgs:Vector.<String> = new Vector.<String>();
processArgs.push("wmic baseboard get serialnumber");
nativeProcessStartupInfo.arguments = processArgs;
process.start(nativeProcessStartupInfo);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.exit();
}
private function onOutputData(event:ProgressEvent):void
{
var data:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
txtreq.text = data;
}
]]>
</mx:Script>
<mx:Panel id="panel1" width="368" height="84" borderAlpha="0.47" dropShadowVisible="true"
horizontalCenter="-10" layout="absolute" title="Activation" verticalCenter="-10">
<mx:TextInput id="txtreq" x="10" y="10" width="293" editable="true"/>
</mx:Panel>
</mx:WindowedApplication>
this is error..
http://i.stack.imgur.com/QoTfb.png
I am making a program where people can create their own food schedule.
I also want to calculate the total amount of calories per food schedule.
So first off people can add items to a list which are saved in an arraycollection:
<s:List includeIn="State2" x="12" y="533" width="428" height="157" dataProvider="{acKoop}"
enabled="true" change="totalcal(event)">
<s:itemRenderer>
<fx:Component>
<mx:Label text="{data.Type} {data.Kcal}" />
</fx:Component>
</s:itemRenderer>
</s:List>
I want a function that retrieves all the values of data.Kcal and then makes a Sum of it.
public function totalcal(event:Event):void{
var price:Number=acKoop[event.columnIndex].Kcal;
total += price;
}
Here the code of link I was send, maybe will be useful:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
private var acKoop:ArrayCollection = null;
public function init():void{
var arr:ArrayCollection = new ArrayCollection();
var obj:Object = new Object();
obj.Type = "TYPE1";
obj.Kcal = 10;
arr.addItem(obj);
obj = new Object();
obj.Type = "TYPE2";
obj.Kcal = 50;
arr.addItem(obj);
acKoop = arr;
}
public function totalcal(event:Event):void{
var i:Number = 0;
for each(var obj:Object in ArrayCollection(List(event.currentTarget).dataProvider)){
i = i + obj.Kcal;
}
Alert.show("Total of Kcal = " + i.toString());
}
]]>
</fx:Script>
<s:List dataProvider="{acKoop}"
enabled="true" change="totalcal(event)">
<s:itemRenderer>
<fx:Component>
<mx:Label text="{data.Type} {data.Kcal}" />
</fx:Component>
</s:itemRenderer>
</s:List>
</s:Application>
Basically, on the change event I take the dataprovider information from the event, and calculate the TOTAL with the for each loop. I hope this will be useful.
i am trying to add one Box to my application using the following code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"
>
<mx:HBox height="100%" width="100%" backgroundColor="red" borderColor="black"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.containers.Box;
import mx.events.FlexEvent;
protected function button1_clickHandler():void
{
var box:Box = new Box();
box.setStyle("backgroundColor","blue");
box.height = 100;
box.width = 100;
//box.addChild(new Button());
addChild(box);
trace("children "+numChildren);
}
]]>
</mx:Script>
<mx:Button label="click" click="button1_clickHandler()" x="200" y="200" />
</mx:Application>
this code is work in flexBuilder.but it doesn't work while compiling in command prompt(using mxmlc command).
please suggest me on this issue, because my work is fully depending on command prompt.
thanks in advance
vengatesh s
This totally depends on the compiler you are using. If you are using the Flex 4+ compiler I would suggest you to try using addElement instead of addChild. The same code above just changes to
protected function button1_clickHandler():void
{
var box:Box = new Box();
box.setStyle("backgroundColor","blue");
box.height = 100;
box.width = 100;
/********** ----------- CHANGE----------------------********/
// This is the only change from your code
addElement(box);
/********** ----------- CHANGE----------------------********/
trace("children "+numChildren);
}
I created a flex application that snapshot a picture of the webcam. Im trying now to save every snapshop and display it directly when the image has been capture. But I cant seems to understand how to.
I want the images to be display in the Thumbnail box.
Any help ? or any sites I can found some help on ?
This is what I have for the moment
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top"
horizontalAlign="center" paddingTop="0" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.UIComponent;
private function videoDisplay_creationComplete() : void
{
var camera:Camera = Camera.getCamera();
if (camera)
{
videoDisplay.attachCamera(camera);
}
else
{
Alert.show("Oops, we can't find your camera.");
}
}
private function capture_click() : void
{
var snap:BitmapData = new BitmapData(320, 240, true);
var snapBmp:Bitmap = new Bitmap(snap);
snapBmp.width = 320;
snapBmp.height = 240;
if(snapshotHolder.numChildren > 0)
snapshotHolder.removeChildAt(0);
snapshotHolder.addChild(snapBmp);
snap.draw(videoDisplay);
}
]]>
</mx:Script>
<mx:HBox>
<mx:Panel title="Video">
<mx:VideoDisplay id="videoDisplay" creationComplete="videoDisplay_creationComplete();" width="320" height="240" />
</mx:Panel>
<mx:Panel title="Snapshot">
<mx:UIComponent id="snapshotHolder" width="320" height="240" />
</mx:Panel>
</mx:HBox>
<mx:HBox>
<mx:Button label="reload camera" click="videoDisplay_creationComplete();"/>
<mx:Button label="capture" click="capture_click();"/>
</mx:HBox>
<mx:HBox>
<mx:Panel title="Thumbnails">
<mx:UIComponent id="snapshotHolderTN" width="128" height="96" />
</mx:Panel>
</mx:HBox>
</mx:Application>
Pls try with this when u click for image snaps.
var bmp:BitmapData = new BitmapData(videodisplay.width,videodisplay.height);
bmp.draw(drawArea);
var jpgEncode:JPEGEncoder = new JPEGEncoder(50);
var imageByte:ByteArray = jpgEncode.encode(bmp);
var fileRef:FileReference = new FileReference;
fileRef.save(imageByte);