Is there something like Format Painter

Hi team,
Is there anything like the Format Painter? or How to implement a similar function?

@Doraemon There is no such built-in functionality. The Format Painter is supposed to apply formatting from one part of content to another part of content. You can try implementing such functionality by applying nodes properties from one part of content to nodes from another part of content.

Thanks for your reply.
I will try it

1 Like

@alexey.noskov
I tried something like this.

public static void copyFont(Font source, Font target) {

        for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(Font.class)) {
            Method writeMethod = pd.getWriteMethod();
            Method readMethod = pd.getReadMethod();
            if (writeMethod == null || readMethod == null) {
                continue;
            }
            if (!writeMethod.isAnnotationPresent(Deprecated.class) && !readMethod.isAnnotationPresent(Deprecated.class)) {

                try {
                    Object val = readMethod.invoke(target);
                    if (val != null) {
                        writeMethod.invoke(source, val);
                    }
                } catch (Throwable th) {
                    LOGGER.error("Failed to set property:{} cause:{} ", pd.getName(), th.getMessage(), th);
                }

            }

        }


    }

But when i called setTintAndShade, the code throwed a exception

java.lang.IllegalStateException: TintAndShade cannot be applied to a non-theme color.
	at com.aspose.words.Font.setTintAndShade(Unknown Source) ~[aspose-words-24.2-jdk17.jar:24.2.0]

Is there a better way to copy font or format?

@Doraemon We have a feature request logged as WORDSNET-26633 to provide a feature to copy formatting from one Font object to another. We will keep you updated and let you know once it is available.

Unfortunately, currently there is no elegant way to copy all formatting from one Font object to another. The only way to process Font properties one by one.

@alexey.noskov
Thanks for your reply. I am looking forward to the new feature,

1 Like