LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Producing a good FAX image (using Ghostscript and ImageMagick) (https://www.linuxquestions.org/questions/linux-software-2/producing-a-good-fax-image-using-ghostscript-and-imagemagick-838614/)

gnuweenie 10-17-2010 07:05 AM

Producing a good FAX image (using Ghostscript and ImageMagick)
 
Sometimes I have to send a FAX (as some recipients are about 20 years behind the times). Sometimes the document looks excellent on the screen, but what comes out the other end looks terrible. So I'm trying to come up with a way to produce the best quality FAX from a vector PDF (which is searchable with images and text). Part of the goal is to preview the fax in advance, so there are no surprises.

I start by converting the vector PDF to a raster (bitmap) postscript document:
Code:

pdf2ps document.pdf document.ps
I do that because ImageMagick does not handle vector PDFs well (while Ghostscript does handle it).

Then I use ImageMagick to display a FAX-converted representation:
Code:

convert document.ps -monochrome -threshold 80% -despeckle -resize "150x100%" -density 200 -format fax miff:- | display -
-monochrome -threshold 80% makes it a bi-level image.

-despeckle removes noisey dots if there were any colored backgrounds.

-resize "150x100%" compensates for the fact that the width of a FAX pixel is 1.5 times its height (this switch is absent on the actual file creation).

-density 200 FAXes are only 200 dpi. ImageMagick is not always smart about inferring parameters, so I do this to force ImageMagick to do the FAX format to spec.

In the end, I'm ending up with a very crappy image even though I started with a very high quality PDF. It was expected to look bad, but not as bad as what I'm ending up with. It's barely legible.

How can these steps above be improved?

H_TeXMeX_H 10-18-2010 05:44 AM

Well, it would be nice if you could somehow describe how bad, or provide an example ?

I would try a different program, a specialized one, maybe:
http://sourceforge.net/projects/hylapex/
or search.

gnuweenie 10-18-2010 10:25 AM

I think my problem is font mismatching. When I convert to postscript using pdf2ps, the quality is lousy before I even use ImageMagick to convert to a FAX-like image. But when I take the postscript and convert back to a PDF, the PDF quality is excellent. This means that pdf2ps is too smart (that is, it seems to preserve the vector graphics, when it's raster that I need).

Installing more PostScript fonts is too painful. Debian tries to install nothing, and in fact proposes that I remove packages. So this is more evidence that going to postscript was a bad move. I'm guessing hylapex will not solve this, because it depends on a postscript library.

What would be more interesting is a way to convert from vector PDF to a raster image (a tiff, or a PDF containing just a bitmap). I prefer small dedicated single purpose tools, rather than some monolithic feature rich application. It's just not obvious to me how to get a raster image from a vector PDF.

H_TeXMeX_H 10-18-2010 10:48 AM

Why not try using pdftoppm to get an image, then convert that with imagemagick ?

gnuweenie 10-18-2010 11:21 AM

Quote:

Originally Posted by H_TeXMeX_H (Post 4131433)
Why not try using pdftoppm to get an image, then convert that with imagemagick ?

That was a good call. I just installed xpdf-reader (to get the pdftoppm tool), and it seems to work well for feeding ImageMagick to get a good representation of the FAX quality. I played with letting pdftoppm do the dithering, and it was poor with images, so it's best to leave that to ImageMagick

If anyone else goes down this path, this is the approach to preview a PDF in FAX quality:
Code:

pdftoppm -r 200 document.pdf document
convert document-000001.ppm -monochrome -threshold 80% -despeckle -resize "150x100%" -density 200 -format fax miff:- | display -

Then to actually write the file for faxing, drop the resizing parameter:
Code:

convert document-000001.ppm -monochrome -threshold 80% -despeckle -density 200 -format fax document_g3fax.tiff


All times are GMT -5. The time now is 07:52 PM.