Perché il PDF è vuoto quando si tenta di creare una versione PDF di un componente Flex?
-
15-11-2019 - |
Domanda
Ho un componente Flex, un VBOX, che ha contenuto al suo interno.Componenti di testo principalmente.
VBOX è in possesso di un rapporto che voglio essere in grado di salvare in PDF.Sto usando alivepdf per ottenere questo ma il PDF prodotto è vuoto se visualizzato in Adobe Reader (più recenteVersione).
Quando apro il PDF in Blocco note ++ posso vedere che ci sono sicuramente contenuti in là e il file sembra essere strutturato correttamente.
Questo è il metodo che sto usando per generare il 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
}
. Soluzione
Try this:
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
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow