为什么在尝试创建Flex组件的PDF版本时,PDF是空白的?

时间:2011-05-19 14:56:47

标签: flex alivepdf

我有一个flex组件,一个VBox,里面有内容。文本组件主要是。

VBox正在举行一份我希望能够保存为PDF的报告。我使用AlivePdf来实现此目的,但在Adobe Reader(最新版本)中查看时生成的PDF是空白的。

当我在Notepad ++中打开PDF时,我可以看到其中肯定有内容,并且文件看起来结构正确。

这是我用来生成PDF的方法:

private function doPrint(whatToPrint:UIComponent):void
{
    var printPDF:PDF = new PDF( Orientation.LANDSCAPE, Unit.MM, Size.A4 );
    printPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
    printPDF.addPage();
    printPDF.addImage( whatToPrint, 0, 0, 0, 0, 'PNG', 100, 1, ResizeMode.FIT_TO_PAGE );

    // The string here looks to have produced a valid PDF but it doesn't render correctly
    var content:String = printPDF.save(Method.LOCAL);

    // Custom save file data in here, removed for clarity of issue
}

1 个答案:

答案 0 :(得分:1)

试试这个:

private function doPrint(whatToPrint:UIComponent):void
{
    var printPDF:PDF = new PDF( Orientation.LANDSCAPE, Unit.MM, Size.A4 );
    printPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );
    whatToPrint.validateNow();
    printPDF.addPage();
    printPDF.addImage( whatToPrint, 0, 0, 0, 0, 'PNG', 100, 1, ResizeMode.FIT_TO_PAGE );

    // The string here looks to have produced a valid PDF but it doesn't render correctly
    var content:String = printPDF.save(Method.LOCAL);

    // Custom save file data in here, removed for clarity of issue
}