public synchronized void close(String... fieldsLeaveUnflatten) throws IOException, DocumentException {
        if(closed){
            throw new IllegalStateException("already closed");
        }
        closed = true;
        Set keySet = fields.getFields().keySet();
        if (fieldsLeaveUnflatten != null) {
            for (String exclude : fieldsLeaveUnflatten) {
                keySet.remove(exclude);
            }
        }
        for (Object keyobj : keySet) {
            String key = (String) keyobj;
            stamper.partialFormFlattening(key);
        }
        stamper.setFormFlattening(true);
        stamper.setFreeTextFlattening(true);
        stamper.close();
    }