首页 > 未分类 > 用AS3创建PDF文档例子

用AS3创建PDF文档例子

2007年10月18日 已被阅读过 39 次

它花了我几分钟时间来解决使用AlivePDF来在磁盘中写入一个PDF,希望这简短的例子能帮助到你

public class ProjectPDFExporter
{
private var filename:String = "test.pdf";
private var pdf:PDF;
public function exportPdf(filename:String) : void
{
this.filename = filename;
pdf = new PDF();
pdf.addEventListener(Event.COMPLETE, onComplete);
pdf.setDisplayMode (Display.FULL_PAGE,
Layout.SINGLE_PAGE);
pdf.addPage();
pdf.setFont( FontFamily.ARIAL );
pdf.addText("My Teax",1,10);
pdf.setFont( FontFamily.ARIAL , "", 32);
pdf.addText("Some more text",10,30);
pdf.finish();
}
protected function onComplete(event:Event)
{
var f:FileStream = new FileStream();
var file:File =
File.applicationStorageDirectory.resolve( filename );
f.open( file, FileMode.WRITE);
var bytes:ByteArray = pdf.getPDF()
f.writeBytes(bytes);
f.close();
}
}

Also, it looks like the first version of AlivePDF.swc is missing at least one class (FontFamily), so you’re probably safer using the source instead of the swc for now.
The more I look into it, the more I’m impressed by this library. I’m really surprised Adobe had never made something similar before.

原文:http://www.rogue-development.com/blog/2007/08/alive-pdf-flex-example.html

分类: 未分类 标签: ,
分享到新浪微博
本文的评论功能被关闭了.