package
{
import flash.net.FileReference;
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.containers.VBox;
import org.alivepdf.colors.RGBColor;
import org.alivepdf.data.*;
import org.alivepdf.display.Display;
import org.alivepdf.drawing.Blend;
import org.alivepdf.drawing.Joint;
import org.alivepdf.fonts.CoreFont;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.layout.Layout;
import org.alivepdf.layout.Mode;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Position;
import org.alivepdf.layout.Resize;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.pages.Page;
import org.alivepdf.pdf.PDF;
import org.alivepdf.saving.Method;
public class PDFReportGeneration
{
public function PDFReportGeneration()
{
}
public function generatePDF(imageParameter:VBox, nameOfPDFFile:String, titleOfPDF:String, dataFromDatagrid:ArrayCollection, index:uint, gridWidth:uint):void
{
var userPDF:PDF = new PDF();;
var newPage:Page = new Page(Orientation.PORTRAIT, Unit.MM, Size.A4 );
userPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4 );
userPDF.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE );
userPDF.addPage(newPage);
userPDF.setFont(new CoreFont(FontFamily.TIMES_BOLD),36);
userPDF.setXY(18,110);
userPDF.writeText(50,titleOfPDF,null);
userPDF.addPage();
if(index == 1)
{
userPDF.addImage(imageParameter,new Resize(Mode.RESIZE_PAGE,Position.CENTERED),0, 0, 0, 0, 0, 1,true,'PNG',100, Blend.SCREEN);
}
else
{
var grid:org.alivepdf.data.Grid = new org.alivepdf.data.Grid(dataFromDatagrid.toArray(), gridWidth, 22, new RGBColor(0xCCCCCC), new RGBColor(0xAAAAAA), true, new RGBColor(0x0), 1, Joint.MITER);
userPDF.setFontSize(45);
userPDF.setFont(new CoreFont(),10);
userPDF.textStyle(new RGBColor(0x000000));
userPDF.addGrid(grid);
}
var pdfFileReference:FileReference = new FileReference();
var pdfByteArray:ByteArray = userPDF.save(Method.LOCAL);
pdfFileReference.save(pdfByteArray,nameOfPDFFile+".pdf");
}
}
}
{
import flash.net.FileReference;
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.containers.VBox;
import org.alivepdf.colors.RGBColor;
import org.alivepdf.data.*;
import org.alivepdf.display.Display;
import org.alivepdf.drawing.Blend;
import org.alivepdf.drawing.Joint;
import org.alivepdf.fonts.CoreFont;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.layout.Layout;
import org.alivepdf.layout.Mode;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Position;
import org.alivepdf.layout.Resize;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.pages.Page;
import org.alivepdf.pdf.PDF;
import org.alivepdf.saving.Method;
public class PDFReportGeneration
{
public function PDFReportGeneration()
{
}
public function generatePDF(imageParameter:VBox, nameOfPDFFile:String, titleOfPDF:String, dataFromDatagrid:ArrayCollection, index:uint, gridWidth:uint):void
{
var userPDF:PDF = new PDF();;
var newPage:Page = new Page(Orientation.PORTRAIT, Unit.MM, Size.A4 );
userPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4 );
userPDF.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE );
userPDF.addPage(newPage);
userPDF.setFont(new CoreFont(FontFamily.TIMES_BOLD),36);
userPDF.setXY(18,110);
userPDF.writeText(50,titleOfPDF,null);
userPDF.addPage();
if(index == 1)
{
userPDF.addImage(imageParameter,new Resize(Mode.RESIZE_PAGE,Position.CENTERED),0, 0, 0, 0, 0, 1,true,'PNG',100, Blend.SCREEN);
}
else
{
var grid:org.alivepdf.data.Grid = new org.alivepdf.data.Grid(dataFromDatagrid.toArray(), gridWidth, 22, new RGBColor(0xCCCCCC), new RGBColor(0xAAAAAA), true, new RGBColor(0x0), 1, Joint.MITER);
userPDF.setFontSize(45);
userPDF.setFont(new CoreFont(),10);
userPDF.textStyle(new RGBColor(0x000000));
userPDF.addGrid(grid);
}
var pdfFileReference:FileReference = new FileReference();
var pdfByteArray:ByteArray = userPDF.save(Method.LOCAL);
pdfFileReference.save(pdfByteArray,nameOfPDFFile+".pdf");
}
}
}
No comments:
Post a Comment