문제

itext를 통해 PDF를 통해 스윙 jcomponent를 인쇄하고 싶습니다.

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( );

불행히도 PDF 파일에는 아무것도 표시되지 않습니다. 이 문제를 해결하는 방법을 알고 있습니까?

도움이 되었습니까?

해결책

AddNotify 및 Validate 도움말을 추가하는 것을 알아 냈습니다.

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

다른 팁

나는 전화해야했다

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

나는 itext에 대해 그다지 잘 모르겠지만 ... 당신은 PdfWriter 어느 시점에서 맞습니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top