14.11 PCL

PCL is not a standard image format, rather it is a page description language for printers. Unfortunately, the exact implementation of PCL varies from printer to printer, so it can be necessary to tweak the output according to the exact intended destination.

Accordingly, we have a pcl_options structure to allow this to happen. To use this, you simply define a pcl_options structure on the stack:

pcl_options options = { 0 };

Next you populate those options. Typically this is done by requesting a preset from our current defined set.

/* 
   fz_pcl_preset: Retrieve a set of fz_pcl_options suitable for a given 
   preset. 
 
   opts: pointer to options structure to populate. 
 
   preset: Preset to fetch. Currently defined presets include: 
      ljet4HP DeskJet 
      dj500HP DeskJet 500 
      fs600Kyocera FS-600 
      lj  HP LaserJet, HP LaserJet Plus 
      lj2  HP LaserJet IIp, HP LaserJet IId 
      lj3  HP LaserJet III 
      lj3d  HP LaserJet IIId 
      lj4  HP LaserJet 4 
      lj4plHP LaserJet 4 PL 
      lj4d  HP LaserJet 4d 
      lp2563bHP 2563B line printer 
      oce9050Oce 9050 Line printer 
 
   Throws exception on unknown preset. 
*/ 
void fz_pcl_preset(fz_context *ctx, fz_pcl_options *opts, const char *preset);

These options can then be tweaked further using fz_pcl_option:

/* 
   fz_pcl_option: Set a given PCL option to a given value in the 
   supplied options structure. 
 
   opts: The option structure to modify, 
 
   option: The option to change. 
 
   val: The value that the option should be set to. Acceptable ranges of 
   values depend on the option in question. 
 
   Throws an exception on attempt to set an unknown option, or an 
   illegal value. 
 
   Currently defined options/values are as follows: 
 
      spacing,0      No vertical spacing capability 
      spacing,1      PCL 3 spacing (<ESC>*p+<n>Y) 
      spacing,2      PCL 4 spacing (<ESC>*b<n>Y) 
      spacing,3      PCL 5 spacing (<ESC>*b<n>Y and clear seed 
                        row) 
      mode2,0 or 1    Disable/Enable mode 2 graphics compression 
      mode3,0 or 1    Disable/Enable mode 3 graphics compression 
      mode3,0 or 1    Disable/Enable mode 3 graphics compression 
      eog_reset,0 or 1  End of graphics (<ESC>*rB) resets all 
                        parameters 
      has_duplex,0 or 1  Duplex supported (<ESC>&l<duplex>S) 
      has_papersize,0 or 1Papersize setting supported 
                        (<ESC>&l<sizecode>A) 
      has_copies,0 or 1  Number of copies supported 
                        (<ESC>&l<copies>X) 
      is_ljet4pjl,0 or 1Disable/Enable HP 4PJL model-specific output 
      is_oce9050,0 or 1  Disable/Enable Oce 9050 model-specific 
                        output 
*/ 
void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, int val);

14.11.1 Color

Color PCL output can be generated from RGB pixmaps with alpha (though the alpha is ignored) using:

void fz_save_pixmap_as_pcl(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pcl_options *pcl); 
 
void fz_write_pixmap_as_pcl(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap, const fz_pcl_options *pcl); 
 
fz_band_writer *fz_new_color_pcl_band_writer(fz_context *ctx, fz_output *out, const fz_pcl_options *options);

This is 24bpp RGB output, relying on the printers ability to dither. Blank lines are skipped, repeated lines are coded efficiently, and other lines are coded using deltas. Nonetheless file sizes can still be large with this output method.

14.11.2 Mono

Monochrome PCL output can be generated from monochrome bitmaps. These are generated by rendering to greyscale (no alpha) pixmaps and dithering down. The functions in question are:

fz_band_writer *fz_new_mono_pcl_band_writer(fz_context *ctx, fz_output *out, const fz_pcl_options *options); 
 
void fz_write_bitmap_as_pcl(fz_context *ctx, fz_output *out, const fz_bitmap *bitmap, const fz_pcl_options *pcl); 
 
void fz_save_bitmap_as_pcl(fz_context *ctx, fz_bitmap *bitmap, char *filename, int append, const fz_pcl_options *pcl);