<-------Add the lib file(AlivePDF)----->
<mx:Script>
<![CDATA[
import mx.core.BitmapAsset;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import mx.utils.ObjectUtil;
import mx.controls.Alert;
import mx.printing.FlexPrintJob;
import mx.collections.ArrayCollection;
import org.alivepdf.saving.Method;
import org.alivepdf.images.PDFImage;
import mx.utils.URLUtil;
import mx.core.UIComponent;
import flash.net.navigateToURL;
import org.alivepdf.pages.Page;
import org.alivepdf.pdf.PDF;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.display.Display;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.fonts.Style;
import mx.utils.UIDUtil;
[Bindable]
public var dataSource:ArrayCollection = new ArrayCollection();
private var totalRecords:Number = 15;
private function init():void
{
for (var i:int = 1; i<=totalRecords; i++) {
var dataObject:Object = new Object();
dataObject.Name = "Name #" + i;
dataObject.Phone = "Phone #" + i;
dataObject.Address = "Address #" + i;
dataSource.addItem(dataObject);
}
}
private function doPrint():void {
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
printJob.addObject(pan);
printJob.send();
}
}
var claimPDF:PDF;
[Embed(source="assets/graph.png", mimeType="application/octet-stream" )]
protected var jpgBytes:Class;
protected function savePDF(e:MouseEvent):void
{
claimPDF = new PDF(Orientation.LANDSCAPE, Unit.MM, Size.LETTER);
claimPDF.setDisplayMode (Display.FULL_WIDTH);
claimPDF.addPage();
claimPDF.addImageStream(new jpgBytes() as ByteArray, 100, 125, 88, 20, 25);
claimPDF.setFont(FontFamily.ARIAL , Style.NORMAL, 12);
claimPDF.addText("Name: " + this.firstName.text + " " + lastName.text,10,40);
claimPDF.addText("Date: " + this.date.text,10,50);
//claimPDF.addTextNote(48,45,100,2,"Claim Filed on: " + this.date.text + " today's date: " + new Date());
claimPDF.addText("Email ID: " + this.policyNum.text,10,60);
claimPDF.addText("Contact #: " + this.contact.text,10,70);
claimPDF.addText("Description:",10,90);
var bd:BitmapData=new BitmapData(chart.width,chart.height);
bd.draw(chart);
var bm:Bitmap=new Bitmap(bd);
bm.x=235;
bm.y=105;
claimPDF.addImage(bm);
claimPDF.setXY(10,95);
claimPDF.addMultiCell(200,5,desc.text);
var bytes:ByteArray=claimPDF.save(Method.LOCAL);
var f:FileReference=new FileReference();
f.save(bytes,"Test 1.pdf");
}
]]>
</mx:Script>
<mx:HTTPService id="re" url="E:\prabu\data.xml"/>
<mx:Model id="results" source="data.xml"/>
<mx:Panel id="pan" title="Line Chart" x="69.5" y="93">
<mx:LineChart id="chart" dataProvider="{results.result}" showDataTips="true" >
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="month"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="Weekone" displayName="Weekone"/>
<mx:LineSeries yField="Weektwo" displayName="Weektwo"/>
<mx:LineSeries yField="Weekthree" displayName="Weekthree"/>
</mx:series>
</mx:LineChart>
<mx:Legend dataProvider="{chart}" height="30"/>
</mx:Panel>
<mx:Button label="Print" click="doPrint()" x="133" y="607"/>
<mx:Label x="518" y="193" text="Week-three :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea id="tex1" text="{ObjectUtil.toString(re.lastResult.data.result[0].Weekone)}" x="627" y="131" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="529" y="130" text="Week-one :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[0].Weektwo)}" x="627" y="162" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="528" y="163" text="Week-two :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[0].Weekthree)}" x="627" y="193" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="516" y="323" text="Week-three :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[1].Weekone)}" x="627" y="261" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="528" y="260" text="Week-one :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[1].Weektwo)}" x="627" y="292" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="526" y="293" text="Week-two :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[1].Weekthree)}" x="627" y="323" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="531" y="93" text="Month : Jan-01/2010" fontSize="14" fontWeight="bold"/>
<mx:Label x="514" y="463" text="Week-three :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[2].Weekone)}" x="627" y="401" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="528" y="400" text="Week-one :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[2].Weektwo)}" x="627" y="432" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="526" y="433" text="Week-two :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[2].Weekthree)}" x="627" y="463" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="533" y="229" text="Month : Feb-01/2010" fontSize="14" fontWeight="bold"/>
<mx:Label x="527" y="369" text="Month : Aug-01/2010" fontSize="14" fontWeight="bold"/>
<mx:Label fontSize="18" text="PDF Form" left="736" top="91" color="#0084FF"/>
<mx:Form id="form1" width="324" height="331" x="736" y="131">
<mx:FormItem label="First Name:" color="#000000">
<mx:TextInput id="firstName"/>
</mx:FormItem>
<mx:FormItem label="Last Name:" color="#000000">
<mx:TextInput id="lastName"/>
</mx:FormItem>
<mx:FormItem label="Date:" color="#000000">
<mx:DateField id="date" />
</mx:FormItem>
<mx:FormItem label="Email ID:" color="#000000">
<mx:TextInput id="policyNum" />
</mx:FormItem>
<mx:FormItem label="Contact #:" color="#000000">
<mx:TextInput id="contact" maxChars="12"/>
</mx:FormItem>
<mx:Label text="Description:" color="#0078FF"/>
<mx:TextArea id="desc" height="133" width="205"/>
</mx:Form>
<mx:Button click="savePDF(event)" label="Save to PDF" id="savePDFBtn" y="607" x="195"/>
SCREEN SHOT & DEMO HERE
<mx:Script>
<![CDATA[
import mx.core.BitmapAsset;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import mx.utils.ObjectUtil;
import mx.controls.Alert;
import mx.printing.FlexPrintJob;
import mx.collections.ArrayCollection;
import org.alivepdf.saving.Method;
import org.alivepdf.images.PDFImage;
import mx.utils.URLUtil;
import mx.core.UIComponent;
import flash.net.navigateToURL;
import org.alivepdf.pages.Page;
import org.alivepdf.pdf.PDF;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.display.Display;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.fonts.Style;
import mx.utils.UIDUtil;
[Bindable]
public var dataSource:ArrayCollection = new ArrayCollection();
private var totalRecords:Number = 15;
private function init():void
{
for (var i:int = 1; i<=totalRecords; i++) {
var dataObject:Object = new Object();
dataObject.Name = "Name #" + i;
dataObject.Phone = "Phone #" + i;
dataObject.Address = "Address #" + i;
dataSource.addItem(dataObject);
}
}
private function doPrint():void {
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
printJob.addObject(pan);
printJob.send();
}
}
var claimPDF:PDF;
[Embed(source="assets/graph.png", mimeType="application/octet-stream" )]
protected var jpgBytes:Class;
protected function savePDF(e:MouseEvent):void
{
claimPDF = new PDF(Orientation.LANDSCAPE, Unit.MM, Size.LETTER);
claimPDF.setDisplayMode (Display.FULL_WIDTH);
claimPDF.addPage();
claimPDF.addImageStream(new jpgBytes() as ByteArray, 100, 125, 88, 20, 25);
claimPDF.setFont(FontFamily.ARIAL , Style.NORMAL, 12);
claimPDF.addText("Name: " + this.firstName.text + " " + lastName.text,10,40);
claimPDF.addText("Date: " + this.date.text,10,50);
//claimPDF.addTextNote(48,45,100,2,"Claim Filed on: " + this.date.text + " today's date: " + new Date());
claimPDF.addText("Email ID: " + this.policyNum.text,10,60);
claimPDF.addText("Contact #: " + this.contact.text,10,70);
claimPDF.addText("Description:",10,90);
var bd:BitmapData=new BitmapData(chart.width,chart.height);
bd.draw(chart);
var bm:Bitmap=new Bitmap(bd);
bm.x=235;
bm.y=105;
claimPDF.addImage(bm);
claimPDF.setXY(10,95);
claimPDF.addMultiCell(200,5,desc.text);
var bytes:ByteArray=claimPDF.save(Method.LOCAL);
var f:FileReference=new FileReference();
f.save(bytes,"Test 1.pdf");
}
]]>
</mx:Script>
<mx:HTTPService id="re" url="E:\prabu\data.xml"/>
<mx:Model id="results" source="data.xml"/>
<mx:Panel id="pan" title="Line Chart" x="69.5" y="93">
<mx:LineChart id="chart" dataProvider="{results.result}" showDataTips="true" >
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="month"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="Weekone" displayName="Weekone"/>
<mx:LineSeries yField="Weektwo" displayName="Weektwo"/>
<mx:LineSeries yField="Weekthree" displayName="Weekthree"/>
</mx:series>
</mx:LineChart>
<mx:Legend dataProvider="{chart}" height="30"/>
</mx:Panel>
<mx:Button label="Print" click="doPrint()" x="133" y="607"/>
<mx:Label x="518" y="193" text="Week-three :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea id="tex1" text="{ObjectUtil.toString(re.lastResult.data.result[0].Weekone)}" x="627" y="131" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="529" y="130" text="Week-one :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[0].Weektwo)}" x="627" y="162" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="528" y="163" text="Week-two :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[0].Weekthree)}" x="627" y="193" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="516" y="323" text="Week-three :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[1].Weekone)}" x="627" y="261" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="528" y="260" text="Week-one :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[1].Weektwo)}" x="627" y="292" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="526" y="293" text="Week-two :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[1].Weekthree)}" x="627" y="323" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="531" y="93" text="Month : Jan-01/2010" fontSize="14" fontWeight="bold"/>
<mx:Label x="514" y="463" text="Week-three :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[2].Weekone)}" x="627" y="401" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="528" y="400" text="Week-one :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[2].Weektwo)}" x="627" y="432" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="526" y="433" text="Week-two :" fontWeight="bold" fontSize="14" color="#877A7A"/>
<mx:TextArea text="{ObjectUtil.toString(re.lastResult.data.result[2].Weekthree)}" x="627" y="463" width="80" height="23" fontWeight="bold" color="#06434E"/>
<mx:Label x="533" y="229" text="Month : Feb-01/2010" fontSize="14" fontWeight="bold"/>
<mx:Label x="527" y="369" text="Month : Aug-01/2010" fontSize="14" fontWeight="bold"/>
<mx:Label fontSize="18" text="PDF Form" left="736" top="91" color="#0084FF"/>
<mx:Form id="form1" width="324" height="331" x="736" y="131">
<mx:FormItem label="First Name:" color="#000000">
<mx:TextInput id="firstName"/>
</mx:FormItem>
<mx:FormItem label="Last Name:" color="#000000">
<mx:TextInput id="lastName"/>
</mx:FormItem>
<mx:FormItem label="Date:" color="#000000">
<mx:DateField id="date" />
</mx:FormItem>
<mx:FormItem label="Email ID:" color="#000000">
<mx:TextInput id="policyNum" />
</mx:FormItem>
<mx:FormItem label="Contact #:" color="#000000">
<mx:TextInput id="contact" maxChars="12"/>
</mx:FormItem>
<mx:Label text="Description:" color="#0078FF"/>
<mx:TextArea id="desc" height="133" width="205"/>
</mx:Form>
<mx:Button click="savePDF(event)" label="Save to PDF" id="savePDFBtn" y="607" x="195"/>
SCREEN SHOT & DEMO HERE
No comments:
Post a Comment