You missed 1T3XT BVBA's earlier post.
>> Check out the paintToPdf method in this old example from the first book:
>>
https://itext.svn.sourceforge.net/svnroot/itext/examples/src/in_action/chapter12/JTextPaneToPdf.java
>> If ta is a JTextPane, g2 a PdfGraphics2D object and alloc a
Rectangle, you can do:
>> ta.getUI().getRootView(ta).paint(g2, alloc);
not
ta.paint(g2) or ta.print(g2)
Neither of those will work.
FYI, I am the author of that original example.
You can definitely to what you want to do here, you just have to follow
the rules.
-Bill Ensley
www.bearprinting.com
On 4/3/2011 8:43 AM, momom...@sina.com wrote:
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
--
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