Writing Java program to work with Ghostscript

Posted on 2006-06-14
Last Modified: 2013-12-02
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.

Question by:amai
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
LVL 86

Expert Comment

ID: 16900937
You can produce pdf directly. Use Adobe
LVL 92

Accepted Solution

objects earned 175 total points
ID: 16900939
LVL 86

Expert Comment

ID: 16900944
Typo: "Use Adobe" should have been "Use the Java component by Adobe"

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 16939714
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?
LVL 92

Expert Comment

ID: 16939734
can u post your code so far

Author Comment

ID: 16939868

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());

Author Comment

ID: 16939874
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?

Author Comment

ID: 16939994
I have up the points, since I seems to be extending the original question....

Author Comment

ID: 17003403
hi objects... any comments on the iText part?

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question