Reputation: 61
I have been searching for ways to generate pdf files using flash. However, all the results provide solutions in flex environment. I am naive at using flex builder. If anyone can kindly provide any guidance regarding a procedure by which I can generate PDF files using adobe flash professional, it will be a great help. It is to be mentioned that I am using CS6 and actionscript 3.0. I tried using AlivePDF, but it didn't quite help.
Upvotes: 1
Views: 1499
Reputation: 723
first download AlivePDF from official website (https://code.google.com/p/alivepdf/downloads/list);
then, importthe Alivepdf.swc into your project, in Actionscript3 setting
after that, paste the following scripts into the first frame of your stage
you can then draw somethings and add some frame on your stage.
finally, run the movie, if everything work, you may be prompted to save a pdf file.
import org.alivepdf.pdf.PDF;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.layout.Resize;
import org.alivepdf.display.Display;
import org.alivepdf.saving.Method;
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.events.Event;
var size:Size = Size.A4;
var orientation:String = Orientation.PORTRAIT;
var unit:String = Unit.MM;
var myPDF:PDF = new PDF(orientation, unit, size);
myPDF.setDisplayMode(Display.FULL_WIDTH);
var _pdfFilename:String = "test.pdf";
stop();
addEventListener(Event.ENTER_FRAME, CapScreen);
function CapScreen(e:Event):void
{
myPDF.addPage();
myPDF.addImage(CapStage());
var curFrame:int = this.currentFrame + 1;
this.gotoAndStop(curFrame);
if(curFrame > this.framesLoaded)
{
removeEventListener(Event.ENTER_FRAME, CapScreen);
generatePDF();
}
}
function CapStage():Bitmap
{
var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true);
bmd.drawWithQuality(stage, null, null, null, null, true, "best");
return new Bitmap(bmd);
}
function generatePDF():void
{
var fileReference:FileReference = new FileReference();
var byteArray:ByteArray = myPDF.save(Method.LOCAL);
fileReference.save(byteArray, _pdfFilename);
}
Upvotes: 1