Solved

Writing Java program to work with Ghostscript

Posted on 2006-06-14
9
474 Views
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.

Thanks!
0
Comment
Question by:amai
  • 5
  • 2
  • 2
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You can produce pdf directly. Use Adobe
0
 
LVL 92

Accepted Solution

by:
objects earned 175 total points
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Typo: "Use Adobe" should have been "Use the Java component by Adobe"

0
 

Author Comment

by:amai
Comment Utility
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?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 92

Expert Comment

by:objects
Comment Utility
can u post your code so far
0
 

Author Comment

by:amai
Comment Utility
Hi,

here's the code:

public CopyOfJBrowser(String url) {

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

      try {

            mainPane = new JEditorPane(path);

      } catch (IOException ex) {
            ex.printStackTrace(System.err);
            System.exit(1);
            }
 

      mainPane.setEditable(false);
      mainPane.addHyperlinkListener(new linkListener());

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

      try{
            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"));
            document1.open();
            PdfContentByte cb = writer.getDirectContent();
            cb.saveState();
            DefaultFontMapper mapper = new DefaultFontMapper();
   
            PdfGraphics2D g2 = (PdfGraphics2D)cb.createGraphics(640, 840, mapper);
     
            mainPane.paint(g2);
            g2.dispose();
            document1.close();
            writer.close();
   
    }catch (Exception e){
          System.err.print( e.getMessage());
    }
 
}
0
 

Author Comment

by:amai
Comment Utility
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?
0
 

Author Comment

by:amai
Comment Utility
I have up the points, since I seems to be extending the original question....
0
 

Author Comment

by:amai
Comment Utility
hi objects... any comments on the iText part?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video teaches viewers about errors in exception handling.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now