0

I have a process to convert PDFs to PCL for automatic printing, but the quality is not good. Here's the test code that I have to show the poor quality:

gs -dBATCH -dNOPAUSE -q -sDEVICE=ljetplus -sOutputFile=grayscaletest.pcl -f grayscaletest.pdf

Here's what grayscaletest.pdf looks like before: grayscaletest.pdf And what grayscaletest.pcl looks like after: grayscaletest.pcl

I realize that it's doing this because of the device ljetplus, but that's the only device that I have found that will work for what I need. So, I want to convert all grays to black. I have tried the solution found here (GitHub) and here (superuser), but it did nothing. I can't even get this solution to work from PDF to PDF, it just stays the same.

GhostScript version is 9.06. Any help either improving the quality using ljetplus, or just converting everything to black and white without grayscale would be appreciated.

1 Answers1

1

Well that's a black and white output, its been halftoned to produce 1-bit output from 8-bit input. No matter what you do, if your device only supports 1-bit output then you're always going to have to apply some kind of screening to represent grayscale or colour.

You don't give any clues as to why ljetplus is the only device you can use. Without knowing why its going to be hard to offer any concrete advice.

However....

First thing is to update your version of Ghostscript. The current version is 9.27, the one you are using is > 6 years old.

The screen looks coarse, the default resolution of the ljetplus is 300 dpi, is that correct for your printer ? If not you will want to set a higher resolution, it'll give you a finer screen. Most PCL devices are 600 dpi or better these days.

Assuming that your PDF file doesn't contain a halftone, the next thing to do is to experiment with the screening options available in Ghostscript. You could try the switches described here:

https://www.ghostscript.com/doc/9.27/Use.htm#Rendering_parameters

You can also use PostScript screening, but that's harder to implement unless you understand PostScript already. There are also stochastic screens available in Ghostscript but not knowing how comfortable you are with PostScript I don't want to go down that route.

Yyou could of course use Ghostscript to render to a high resolution bitmap, dither that to monochrome with image manipulation too of your choice and then output it back to PDF or PostScript, or an image format that Ghostscript has a program to read (eg viewpbm.ps in the ghostpdl/lib directory).

ImageMagick can probably do all the steps above for you, then once you have a monochrome input file you can simply run it through Ghostscript to get a PCL output file.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • ljetplus was the only device that worked. It needs to work on many different printers, and not all have the same version of PCL. When I use other devices like pxlmono, it would just give me many pages of ASCII characters on most of the printers I tested on. I can probably convince our system administrator to update GhostScript, but it may take a while. We did consider ImageMagick near the beginning of this project, it may be worth looking into it again. You're right to assume that I have very little knowledge of PS coding, but I am willing to learn it. I'll update with what I try. – TheLittlePeace May 28 '19 at 19:25
  • Well PXL is a completely different language to PCL, its more modern. If you use the 'lowest common denominator' for all your printers then I'm afraid that you will experience quality degradation when compared with driving the printers natively. Unless you have a fleet of old printers I'd be surprised if many of them are really 300 dpi. If you do drvier 600 dpi printers at 300 dpi then you are going to end up with one quarter the number of shades of gray that could be used, which will obviously look worse than necessary. – KenS May 29 '19 at 07:06
  • We have a lovely mix of really old and really new printers, and there's no telling where these may need printed :) I tried the switches that you had linked, and none of them worked (probably because it's still in 1-bit). Are there any devices that I could try to use that print in at least 8-bit that work for any PCL capable printer? Perhaps in a newer version, so that I could use that to convince the system admin? – TheLittlePeace May 30 '19 at 13:11
  • 1
    There aren't any newer devices for PCL in newer versions of Ghostscript, PCL is a 'mature' technology, so we don't really need new devices. Available devices include cdeskjet, cdj550, cdjcolor, cdjmono, deskjet, djet500, djet500c, laserjet, lj250, ljet2p, ljet3, ljet3d, ljet4, ljet4d, ljetplus. I believe all of those are PCL printers, there are also pjxl, pjxl300, pxlcolor and pxlmono which are PCL XL devices. I'm afraid I don;t know which of those support colour or grayscale offhand. I'd suggest increasing the resolution to 600 as a first step though. – KenS May 30 '19 at 14:38
  • Regarding upgrading the version of Ghostscript, there are a number of critical vulnerabilities, including remote code execution, in the version you are using. Your sysadmin should seriously consider upgrading as a matter of urgency. You shoudl also add -dSAFER to your command line, if you don;t add that even upgrading to the new version won't help you. – KenS May 30 '19 at 14:39
  • Changing it to 600 DPI certainly did help. I didn't even think about it defaulting to a very low DPI, and I didn't put two and two together. Thank you! – TheLittlePeace May 30 '19 at 14:43
  • I'm glad it helped! – KenS May 30 '19 at 16:14
  • Alright, there is a new issue caused by changing the resolution, maybe I'm just doing it wrong - I have a little bit of PS to adjust the margins slightly so that the printer doesn't cut off the top: -c "<> setpagedevice". When I don't set the resolution, it works like a charm. When I specify -r600, it completely ignores my PS code... I've tried changing the order of the commands to no avail. Is there a different way I should be setting the resolution? – TheLittlePeace Jun 03 '19 at 13:31
  • That should work, but you are now mixing PostScript and PDF, so to some extent all bets are off. You can try not setting the resolution via -r and setting it via the setpagedevice call by adding /HWResolution [600 600] to that dictionary. – KenS Jun 03 '19 at 13:38
  • Neither worked... I'm going to post it as a new question since it's derailed from the original. I figured out _what_ it's doing, just not how to fix it. – TheLittlePeace Jun 04 '19 at 13:56