Most common computer images are stored as arrays of pixel data or raster graphics. Formats such as PNG, and JPEG are classic examples of this. Vector Graphics are stored as operations that are instead “code” for drawing the image on the fly.

In this article we will explore using a few different open source libraries to convertEMF, Postscript and PCL files. The libraries we will explore are FreeHEP, Ghost4J, and OpenPCL.

FreeHEP has a vector graphics package that supports EMF, Postscript and PDF. This library turns out to have pretty good support for EMF. It has not completely implemented the EMF spec (http://msdn.microsoft.com/en-us/library/cc230514). Using the spec, you can enhance the code if needed, but it serves well for our purposes. Below is an example of code used to convert from EMF to PDF.

Now on to Postscript. Unfortunately, FreeHEP does not have enough there to support rendering complex documents. Ghostscript is an extremely mature package with robust support for PostScript. Using Ghost4J’s PDFConverter example, we can convert a PostScript document to PDF. Below is an example of code used to convert from PostScript to PDF.

Lastly, lets look at PCL. In the OpenPCL library, they have a component called PclRenderImage. This code can be used to render a PCL file to a BufferedImage. Below is sample code that converts the first page to a PNG image.

If all you need is to display a PCL document, then writing out the images and wrapping them as a PDF or leaving them as is should suffice. If you would like a fully text searchable document, the PclRenderImage library can be modified to write to a Graphics2D device instead of a BufferedImage. Once this is accomplished, FreeHep’s PDFGraphics2D could be used to render PCL to PDF.