Hi,
I still have the problem with using Graphics2D to print Jtextpane to pdf file...
I have saw your example, but
there are some points I cannot
catch, I then modified it and tried to simplify it but I failed. Here is
a piece of my code hope you may hel me to figure out the problem.
Document pdfDoc = new
Document();
FileOutputStream pdfFile = new
FileOutputStream(new File(filePath));
PdfWriter
writer=PdfWriter.getInstance(pdfDoc, pdfFile);
pdfDoc.open();
PdfContentByte cb =
writer.getDirectContent();
cb.saveState();
//cb.concatCTM(1, 0, 0, 1, 0,
0);
DefaultFontMapper mapper = new
DefaultFontMapper();
PdfGraphics2D g2 =
(PdfGraphics2D)cb.createGraphics(612, 792, mapper);
ta.print(g2);
ta.getUI().getRootView(ta).paint(g2, null);
g2.dispose();
cb.restoreState();
pdfDoc.close();
I open a pdf document and get the Fileoutputstream, the writer and the
PdfContentByte cb. I then use cb to creat a PdfGraphics2D g2. And then
used ta.print(g2) which I believe have print the whole cntent in the
Jtextpane to g2. I dont know what ta.getUI().getRootView(ta).paint(g2,
null); is doing for. And when I test this piece of code I find that I
have successfully made a pdf file however with nothing in it. I dont
know why the content of the Jtextane didn't appear in the pdf file since
I have print it to g2......
Thanks a lot in advance~~
Chen
----- 原始邮件 -----
发件人:1T3XT BVBA <[email protected]>
收件人:[email protected]
主题:Re: [iText-questions] save all objects in JTextpane in one go
日期:2011-4-3 21:11:43
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
iText-questions mailing list
[email protected]
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