We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Changing fonts in Runs does nothing

I try to put checkboxes from Windings 2 in my form instead of the form checkboxes.
This fails however, as I can’t seem to change the font on a run. The run.getFont().setName(“Windings 2”) does nothing.

I use this class to merge my checkboxes. - I’m using v 11.8 of the library currently, does this have something to say?

private class CheckboxMerge implements IFieldMergingCallback {
private DocumentBuilder documentBuilder = new DocumentBuilder(doc);
private HashMap<String, Boolean> fields = new HashMap<String, Boolean>();

private CheckboxMerge(String name, Boolean value) {
fields.put(name, value);
}

private CheckboxMerge(HashMap<String, Boolean> fields) {
this.fields = fields;
}

@Override
public void fieldMerging(FieldMergingArgs fieldMergingArgs) throws Exception {
if(fields.containsKey(fieldMergingArgs.getFieldName())) {
fieldMergingArgs.setText("");
documentBuilder.moveToMergeField(fieldMergingArgs.getFieldName());
Run run = new Run(doc);
run.getFont().setName(“Windings 2”);
run.setText(fields.get(fieldMergingArgs.getFieldName()) ? “R” : “£”);
documentBuilder.insertNode(run);
}
}

@Override
public void imageFieldMerging(ImageFieldMergingArgs arg0) throws Exception {
//Only merge checkboxes
}
}

Called with:

doc.getMailMerge().setFieldMergingCallback(new CheckboxMerge(“TextChechbox1”, true));
doc.getMailMerge().execute(new String[] {}, new Object[] {});

Afterwards I output as PDF

Hi there,


Thanks for your inquiry. Please use following code example to insert check-box symbol in the document. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + “Test+checkbox.docx”);<o:p></o:p>

doc.getMailMerge().setFieldMergingCallback(new CheckboxMerge("TestCheckbox1", true));

doc.getMailMerge().execute(new String[] { "TestCheckbox1" }, new Object[] { "" });

doc.save(MyDir + "Out.docx");

class CheckboxMerge implements IFieldMergingCallback {

private DocumentBuilder documentBuilder;

private HashMap fields = new HashMap();

private CheckboxMerge(String name, Boolean value) {

fields.put(name, value);

}

private CheckboxMerge(HashMap fields) {

this.fields = fields;

}

@Override

public void fieldMerging(FieldMergingArgs fieldMergingArgs) throws Exception {

if(fields.containsKey(fieldMergingArgs.getFieldName())) {

if(documentBuilder == null)

documentBuilder= new DocumentBuilder(fieldMergingArgs.getDocument());

documentBuilder.moveToMergeField(fieldMergingArgs.getFieldName());

if(fields.get(fieldMergingArgs.getFieldName()))

documentBuilder.write("" + (char)0x2611);

else

documentBuilder.write("" + (char)0x2610);

}

}

@Override

public void imageFieldMerging(ImageFieldMergingArgs arg0) throws Exception {

//Only merge checkboxes

}

}

Apparently on my system, the font does not support those unicode chars. - I only get the “unknown char” blob in my document.

Hi there,


Thanks for your inquiry. Please try following code example to insert check-boxes in the document. Hope this helps you.

Document doc = new Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

builder.getFont().setName("Wingdings 2");

builder.write("\u0052");

builder.write("\u00A3");

doc.save(MyDir + "Out.docx");

Still writes £ and R in the document in the document default font.

builder.getFont().setName(“Wingdings 2”); Does not seem to change anything.

Hi there,


Thanks for your inquiry. We suggest you please upgrade to latest version of Aspose.Words for Java 16.1.0 and let us know how it goes on your side. Hope this helps you.

If the problem still remains, please execute the following code example and attach the Out.docx here for testing. Please also share your environment detail e.g. Operating System, Jdk version etc. We will investigate the issue on our side and provide you more information.


Document doc = new Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);<o:p></o:p>

builder.getFont().setName(“Wingdings 2”);<o:p></o:p>

builder.write("\u0052");<o:p></o:p>

builder.write("\u00A3");<o:p></o:p>

doc.save(MyDir + “Out.docx”);

A post was split to a new topic: "Wingdings 2” font issue while document conversion