--- src/gdevgdi.c.orig	2002-08-02 23:08:26.000000000 -0400
+++ src/gdevgdi.c	2003-06-25 14:18:36.000000000 -0400
@@ -248,7 +248,63 @@
 	    /*compression_type =  (ul_scan_size > ul_tiff_size) ? GDI_COMP_MODITIFF : GDI_COMP_SCANLINE;*/
             switch (compression_type) {
 	    case GDI_COMP_MODITIFF:
+#define FUDGE_BIG_BANDS
+#ifndef FUDGE_BIG_BANDS
                 ul_comp_size = FrameTiffComp(obp, ibp, band_height, band_width_bytes, GDI_REAL_COMP);
+#else
+	      {
+		/* Very ugly.  The printer will hose if the compressed
+                   band size is over 65536, so we "fudge" the data in
+                   this case repeatedly until we get what we want. 
+
+		   The fudge algorithm is simple, this is kinda-sorta
+		   RLE, so we just round groups of bits in groups of
+		   2, then 3, then 4, etc until the thing works.  */
+#define MAXBAND 0xffff
+#define ASSERT(x)
+		int fudge=0;
+		byte *use_band=ibp;
+		do {
+		  ul_comp_size = FrameTiffComp(obp, use_band, 
+					       band_height, band_width_bytes, 
+					       GDI_REAL_COMP);
+		  if (ul_comp_size > MAXBAND-8) {
+		    int f, g, h;
+		    if (!fudge) {
+		      ASSERT(use_band == ibp);
+		      use_band = (byte*)gs_malloc(ul_band_size, 1, "gdi_print_page/fudge");
+		      fudge=1;
+		    }
+		    memcpy(use_band, ibp, ul_band_size);
+		    fudge++;
+		    ASSERT(fudge>=2);
+		    {
+#define FUDGE2(x) ( (((((x)>>6)&0x3)?3:0)<<6)	\
+		    | (((((x)>>4)&0x3)?3:0)<<4)	\
+		    | (((((x)>>2)&0x3)?3:0)<<2)	\
+		    | (((((x)>>0)&0x3)?3:0)) )
+#define FUDGE4(x) ( (((((x)>>4)&0xf)?0xf:0)<<4)	\
+		    | (((((x)>>0)&0xf)?0xf:0)) )
+#define FUDGE8(x) ( (((((x)>>0)&0xff)?0xf:0)) )
+#define FUDGE(fudge, x) ( (fudge == 2 ? FUDGE2(x) 	\
+			   : fudge == 3 ? FUDGE4(x)	\
+			   : fudge == 4 ? FUDGE8(x)	\
+			   : 0 ) )
+
+		      for(f=0;f<ul_band_size; f++) {
+			use_band[f] = FUDGE(fudge, ibp[f]);
+		      }
+		    }
+		  }
+		} while (ul_comp_size > MAXBAND-8);
+	      oh_well:
+		if (fudge > 1) {
+		  ASSERT(use_band != ibp);
+		  gs_free(use_band, ul_band_size, 1, "gdi_print_page/fudge");
+		  /*fprintf(stderr, "smartgdi: band %d fudge factor is %d\n", i, fudge);*/
+		}
+	      }
+#endif
 		break;
 	    case GDI_COMP_SCANLINE:
                 ul_comp_size = bmp2run(obp, ibp, band_height, band_width_bytes, GDI_REAL_COMP);

