fig2pdf

Xfig and Transfig (fig2dev) already produce PDF output, so why does this program, which is less fully functional than fig2dev exist? In practice fig2dev converts to PDF by producing EPS, and then calling ghostscript to convert. This has advantages and disadvantages.

The EPS is generated using jpeg2ps code to embed JPEGs losslessly, but bizarrely PNGs (and similar) are stored in the EPS uncompressed and hex encoded. This is why when one wants EPS output from Xfig, and wishes to include non-JPEG bitmaps, it is a good idea to convert the bitmaps to EPS first oneself, preferably using something of the excellence of bmp2eps.

Early versions of fig2dev let gs re-encode bitmaps at will. JPEGs were decompressed and recompressed with a different quality factor, and losslessly compressed images could end up with lossy "JPEG" encoding. Since 3.2.5 fig2dev passes options to gs so as to encode all images in its output losslessly using flate (zlib) encoding with PNG predictors. This means that JPEGs can be greatly inflated, but no quality is lost.

The code here, written mostly for the amusement of its author, draws on bmp2eps to embed JPEGs in its PDF output unchanged, and to recompress everything else losslessly. As it writes PDF directly, the output is arguably cleaner and more likely to be acceptable to PDF editors. Each XFig object becomes one (or more) PDF objects.

The list of things which fig2pdf cannot do is quite long, and involves embedding fonts, PDF images, and EPS images. However, to dwell on its successes, there follows a screenshot of Xfig displaying the image used to test fig2pdf:

The Xfig source for this image is here, and the PDF which fig2pdf produces here.

I regard this code as being an alpha-quality demonstration which I hope will inspire someone else to rewrite it properly. Are you really sure you want it? If you must, try fig2pdf.tar.gz and be aware that the README states:

Supported
---------

Polylines, ellipses, arcs, boxes, boxes with rounded corners.
Depths.
Rotations.
User defined colours.
Fills with colours, including intensity.
Fonts from the "PDF 14" set
(Times x 4, Courier x 4, Helvetica x 4, Symbol, Zapf Dingbats)
Including pictures which are jpeg, png, gif, pnm, pgm, pbm.
LaTeX specials via pdflatex
EPS pictures via gs

Partially supported
-------------------

Approximated and interpolated splines -- a rather poor approximation
is used.

Not yet supported (but might be if there is demand)
-----------------

Fill patterns.
Pictures in PCX format.
A better approximation for splines.
Embedding fonts.

Extremely unlikely ever to be supported
----------------------------------------

Including pictures which are pdf.
X-splines.