Raghu
Raghu

Reputation: 45

PDF export to local using AlivePDF with flex

I need to export charts and data tables to pdf file in flex application.

For this we can user AlivePDF but i need to export to local not server.

Can we export to local system prompting user to select the location to export?

Thanks in advance.

Upvotes: 1

Views: 2360

Answers (3)

Yannick Chaze
Yannick Chaze

Reputation: 576

With the latest version of AlivePDF (0.1.5 RC), you can do this:

var element:IBitmapDrawable; // Chart to export
var pdf:PDF = new UnicodePDF();
pdf.addPage();

var bitmapData:BitmapData = new BitmapData(element.width, element.height, false, 0xffffff);
try{
    bitmapData.draw(element as IBitmapDrawable);
}catch(e:*)
{
    throw new Error("bitmap draw failed");
}

var jpegencoder:JPEGEncoder = new JPEGEncoder(100);
var byteArray:ByteArray     = jpegencoder.encode(bitmapData);

pdf.addImageStream(byteArray);
var file : FileReference = new FileReference()
file.save(pdf.save(Method.LOCAL),"my.pdf");

Upvotes: 0

splash
splash

Reputation: 13327

Since FP10 the FileReference Class should support this via the save() function. The code to do this in Flash Player 10 or better is shown below:

var bytes:ByteArray = pdf.save(Method.LOCAL);
var file:FileReference = new FileReference();
file.save(bytes, "myPDF.pdf");

Upvotes: 3

Nidhi
Nidhi

Reputation: 785

Try this

var pdfFile:PDF = new PDF();
var pdfByteArray:ByteArray =  new ByteArray ();
pdfByteArray = pdfFile.save(Method.LOCAL);

Upvotes: 1

Related Questions