Hi
Please can anyone tell me what is wrong in my code. It does not work : 
the created pdf is empty.
Here is the code :

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.text.rtf.RTFEditorKit;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.DefaultFontMapper;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfGraphics2D;
import com.lowagie.text.pdf.PdfWriter;

public class RtfTest {

  public static void main(String agrv[]) {

      try {
          FileInputStream fis = new FileInputStream("C:/LICENSE.rtf");

          RTFEditorKit rtfEditorKit = new RTFEditorKit();
          JEditorPane jEditorPane = new JEditorPane();

          jEditorPane.setEditorKit(rtfEditorKit);
          rtfEditorKit.read(fis, jEditorPane.getDocument(), 0);

          String contents = jEditorPane.getDocument().getText(0, 
jEditorPane.getDocument().getLength());

          com.lowagie.text.Document document1 = new 
com.lowagie.text.Document(PageSize.A4, 50, 50, 50, 50);
          FileOutputStream fos = new FileOutputStream("C:/graphics2D.pdf");

          PdfWriter writer = PdfWriter.getInstance(document1, fos);

          document1.open();

          PdfContentByte cb = writer.getDirectContent();
          cb.saveState();
          DefaultFontMapper mapper = new DefaultFontMapper();

          PdfGraphics2D g2 = (PdfGraphics2D) cb.createGraphics(612, 792, 
mapper);

          jEditorPane.paint(g2);

          g2.dispose();
          document1.close();
          fos.close();
          writer.close
           .......

Many thanks.
lokmane.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to