def extract_docfile(bibdata, remove=False):
    """ Try extracting document file from bib data.
        Returns None if not found.

        :param remove: remove field after extracting information (default: False)
    """
    try:
        if 'file' in bibdata:
            field = bibdata['file']
            for f in field.split(':'):
                if len(f) > 0:
                    break
            if remove:
                bibdata.pop('file')
            if f[0] != '/':
                f = '/' + f
            return f
        if 'attachments' in bibdata:
            return bibdata['attachments']
        if 'pdf' in bibdata:
            return bibdata['pdf']
    except (KeyError, IndexError):
        return None
