Hello, Thank you for reminding me of using PdfGraphics2D to solve my save pdf file problme. Actually I am new to iText and I search some info of PdfGraphics2D. Here are my solutions:
public void setTexttoPdf(String filePath,JTextPane ta) throws IOException, DocumentException{ Document pdfDoc = new Document(); FileOutputStream pdfFile = new FileOutputStream(new File(filePath)); PdfWriter writer=PdfWriter.getInstance(pdfDoc, pdfFile); writer.setStrictImageSequence(true); pdfDoc.open(); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); DefaultFontMapper mapper = new DefaultFontMapper(); PdfGraphics2D g2 = (PdfGraphics2D)cb.createGraphics(612, 792, mapper); ta.paint(g2); ta.print(g2); cb.restoreState(); pdfDoc.close(); } Then I insert a picture(jpg) in my Jtextpane and tried to save it as a pdf file, but what I got is an empty pdf file. What's wrong with my code??? Thanks a lot for your favor~! Yours Chen
------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php