花了我几分钟时间来解决使用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.