'Write the image *data* into the pdf file using png
predictors with Flate compression.'

def _writePng(self, data):

    buffer = BytesIO()
    _png.write_png(data, buffer)
    buffer.seek(8)
    written = 0
    header = bytearray(8)
    while True:
        n = buffer.readinto(header)
        assert (n == 8)
        (length, type) = struct.unpack('!L4s', bytes(header))
        if (type == 'IDAT'):
            data = bytearray(length)
            n = buffer.readinto(data)
            assert (n == length)
            self.currentstream.write(bytes(data))
            written += n
        elif (type == 'IEND'):
            break
        else:
            buffer.seek(length, 1)
        buffer.seek(4, 1)
