--- pdf.py 2011-09-08 19:48:40.000000000 -0700 +++ pdf1.py 2011-09-08 19:50:26.000000000 -0700 @@ -11,7 +11,7 @@ # Run ./jbig2 -s -p image1.jpeg image1.jpeg ... # python pdf.py output > out.pdf -dpi = 600 +#dpi = 600 class Ref: def __init__(self, x): @@ -121,16 +121,16 @@ except IOError: sys.stderr.write("error reading page file %s\n"% p) continue - (width, height) = struct.unpack('>II', contents[11:19]) + (width, height,xres,yres) = struct.unpack('>IIII', contents[11:27]) xobj = Obj({'Type': '/XObject', 'Subtype': '/Image', 'Width': str(width), 'Height': str(height), 'ColorSpace': '/DeviceGray', 'BitsPerComponent': '1', 'Filter': '/JBIG2Decode', 'DecodeParms': ' << /JBIG2Globals %d 0 R >>' % symd.id}, contents) - contents = Obj({}, 'q %f 0 0 %f 0 0 cm /Im1 Do Q' % (float(width * 72) / dpi, float(height * 72) / dpi)) + contents = Obj({}, 'q %f 0 0 %f 0 0 cm /Im1 Do Q' % (float(width * 72) / xres, float(height * 72) / yres)) resources = Obj({'ProcSet': '[/PDF /ImageB]', 'XObject': '<< /Im1 %d 0 R >>' % xobj.id}) page = Obj({'Type': '/Page', 'Parent': '3 0 R', - 'MediaBox': '[ 0 0 %f %f ]' % (float(width * 72) / dpi, float(height * 72) / dpi), + 'MediaBox': '[ 0 0 %f %f ]' % (float(width * 72) / xres, float(height * 72) / yres), 'Contents': ref(contents.id), 'Resources': ref(resources.id)}) [doc.add_object(x) for x in [xobj, contents, resources, page]]