如何在Pdf中写入图像

时间:2013-07-14 21:29:27

标签: actionscript-3 flex flash-builder

我必须使用Flex在pdf中编写文本和图像,但图像不会出现。你能看出错误是什么吗?这是我的代码:

...

private var image:Loader = new Loader;
private var pdf:PDF;

protected function onBtnGeneratePDF(event:MouseEvent):void
{
pdf = new PDF( Orientation.PORTRAIT, Unit.MM, Size.A4 );
pdf.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );

var newPage:Page = new Page ( Orientation.PORTRAIT, Unit.MM, Size.A4 );
pdf.addPage( newPage );

image.load(new URLRequest("bear.jpg"));
image.contentLoaderInfo.addEventListener(Event.CO MPLETE, done);

var fs:FileStream = new FileStream(); 
var file:File = File.desktopDirectory.resolvePath("testPdf.pdf"); 
fs.open(file, FileMode.WRITE); 
var bytes:ByteArray = pdf.save(Method.LOCAL); 
fs.writeBytes(bytes); 
fs.close();
}

private function done (e:Event):void {
pdf.addImage(image, null, 20, 20);
}

]]>
</fx:Script>

<s:Button x="10" y="179" label="Generate PDF" click="onBtnGeneratePDF(event)"/>

...

1 个答案:

答案 0 :(得分:0)

我不知道为什么这不起作用,但你也可以检查一下ActionScript3 PDF库AlivePDF。请查看此tutorial以及此tutorial