Writing Java program to work with Ghostscript

Can someone advise me on how to write a Java program to work with Ghostscript? I instend to "print" some contents from JEditorPane through Ghostscript, and produce PDF through it.

Who is Participating?
You can produce pdf directly. Use Adobe
Typo: "Use Adobe" should have been "Use the Java component by Adobe"

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

amaiAuthor Commented:
Hi objects,

I took a look at iText, and tried to use it. Understood that I could use PdfGraphics2D to achieve printing PDF through iText as jEditorPane can 'paint' into a Graphics object.

I tried painting, but it only painted 1 page of the whole document, the rest are being cut off. Do you think you can help me with this?
can u post your code so far
amaiAuthor Commented:

here's the code:

public CopyOfJBrowser(String url) {

      super("JBrowser HTML Printing Demo");
      path = url;

      try {

            mainPane = new JEditorPane(path);

      } catch (IOException ex) {

      mainPane.addHyperlinkListener(new linkListener());

      setContentPane(new JScrollPane(mainPane));
      setSize(kDefaultX, kDefaultY);

            com.lowagie.text.Document document1 = new com.lowagie.text.Document(PageSize.A4, 80, 50, 30, 65);
            PdfWriter writer = PdfWriter.getInstance(document1, new FileOutputStream("test4.pdf"));
            PdfContentByte cb = writer.getDirectContent();
            DefaultFontMapper mapper = new DefaultFontMapper();
            PdfGraphics2D g2 = (PdfGraphics2D)cb.createGraphics(640, 840, mapper);
    }catch (Exception e){
          System.err.print( e.getMessage());
amaiAuthor Commented:
I forgot to add, I have also a "problem" where when the pane is being displayed, it will not write into the PDF. only after I have closed the pane, the PDF content will be written. Why is this so?
amaiAuthor Commented:
I have up the points, since I seems to be extending the original question....
amaiAuthor Commented:
hi objects... any comments on the iText part?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.