<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html">
<mx:TextInput id="txt" x="10" y="10" width="300"/>
<mx:Button label="PDF作成" click="generatePDF(event)" x="10" y="40"/>
<mx:Script>
<![CDATA[
import org.alivepdf.colors.RGBColor;
import org.alivepdf.transitions.Transition;
import org.alivepdf.fonts.Style;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.events.ProcessingEvent;
import org.alivepdf.saving.Method;
import org.alivepdf.layout.Size;
import org.alivepdf.pages.Page;
import org.alivepdf.layout.Unit;
import org.alivepdf.layout.Orientation;
import org.alivepdf.pdf.PDF;
private var myPDF:PDF;
private var filePath:String = "pdf/sample.pdf";
[Embed( source="04.jpg", mimeType="application/octet-stream" )]
private var Jpg04:Class;
private function generatePDF(event:MouseEvent):void {
myPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
myPDF.setFont(FontFamily.ARIAL, Style.BOLD, 14);
myPDF.setAuthor("kimura");
myPDF.setTitle("AlivePDFSample");
myPDF.addEventListener(ProcessingEvent.COMPLETE, processingCompleteHandler);
myPDF.addPage();
myPDF.addText("Page 1", 10, 10);
myPDF.beginFill(new RGBColor(0xffcc00));
myPDF.drawCircle(80, 60, 30);
myPDF.beginFill(new RGBColor(0xff9900));
myPDF.drawPolygone([60, 100, 160, 120, 140, 170, 40, 130]);
myPDF.beginFill(new RGBColor(0xff6600));
myPDF.drawRoundRect(new Rectangle(160, 30, 30, 30), 5);
myPDF.endFill();
myPDF.addTransition(Transition.GLITTER);
myPDF.addPage();
myPDF.addText("Page 2", 10, 10);
myPDF.addImageStream(new Jpg04 as ByteArray, 10, 30, 100);
var field:TextField = new TextField();
var format:TextFormat = new TextFormat("MS Mincho", 28);
field.defaultTextFormat = format;
field.text = "日本語テスト";
myPDF.addImage(field, 10, 140, 30);
myPDF.addTransition(Transition.GLITTER);
myPDF.addPage();
myPDF.addText("Page 3", 10, 10);
try{
var stream:FileStream = new FileStream();
var file:File = File.desktopDirectory.resolvePath(filePath);
stream.open(file, FileMode.WRITE);
var bytes:ByteArray = myPDF.save(Method.LOCAL);
stream.writeBytes(bytes);
} catch (e:Error) {
txt.text = "ファイルをオープンできません";
} finally {
stream.close();
}
}
private function processingCompleteHandler(event:ProcessingEvent):void {
txt.text = "PDF作成が完了しました";
}
]]>
</mx:Script>
</mx:WindowedApplication>