Question

Je souhaite imprimer mon Composé Swing JComponent via iText au format PDF.

JComponent com = new JPanel();
com.add( new JLabel("hello") );

PdfWriter writer = PdfWriter.getInstance( document, new FileOutputStream( dFile ) );
document.open( );

PdfContentByte cb = writer.getDirectContent( );
PdfTemplate tp = cb.createTemplate( pageImageableWidth, pageImageableHeight );
Graphics2D g2d = tp.createGraphics( pageImageableWidth, pageImageableHeight, new DefaultFontMapper( ) );
g2d.translate( pf.getImageableX( ), pf.getImageableY( ) );
g2d.scale( 0.4d, 0.4d );
com.paint( g2d );
cb.addTemplate( tp, 25, 200 );
g2d.dispose( );

Malheureusement, rien ne s'affiche dans le fichier PDF. Savez-vous comment résoudre ce problème?

Était-ce utile?

La solution

J'ai compris comment ajouter addNotify et valider des aides.

    com.addNotify( );
    com.validate( );

Autres conseils

je devais appeler

com.addNotify()
com.setSize()
com.validate()

Je ne connais pas grand chose à propos d'iText, mais ... vous avez bien fermé le PdfWriter à un moment donné, n'est-ce pas?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top