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

Free Support Forum - aspose.com

Cant able to set font style for DATE field

HI,


I am using Aspose latest version for document conversion. I tried to insert DATE field and apply some font styles to it as below

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();

Field fld = builder.insertField(“AUTHOR”, “Test”);//No i18n

FieldSeparator fldSp = fld.getSeparator();
Run run = (Run)fldSp.getNextSibling();
run.getFont().setName(“impact”);
run.getFont().setBold(true);

Field fld2 = builder.insertField(“DATE”, “March 23, 2013”);//No i18n

fldSp = fld2.getSeparator();
run = (Run)fldSp.getNextSibling();
run.getFont().setName(“impact”);
run.getFont().setBold(true);

fld.update();
doc.save(“out.docx”, SaveFormat.DOCX);

After conversion. I can able to see the font style for AUTHOR field not for DATE field.
Am i doing anything wrong ?

Please help me

Hi Anbu,


Thanks for your inquiry. Please try run the following code snippet to be able to achieve what you need:
...
.
Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();

builder.getFont().setName(“impact”);
builder.getFont().setBold(true);

Field fld = builder.insertField(“AUTHOR”, “Test”);//No i18n

FieldSeparator fldSp = fld.getSeparator();
Run run = (Run)fldSp.getNextSibling();
.
.

I hope, this helps.

Best regards,

Thanks for the reply.

Actually you are trying to apply bold for the whole paragraph.
What i need to do is bold the date field alone.
like this

Date : 31-May-2013 ,

<o:p></o:p>

Hi Anbu,


Thanks for your inquiry. To achieve this, you can find all Run nodes i.e. contained inside FieldStart and FieldEnd characters and set their Font.Bold property as follows:
Field fld2 = builder.insertField(“DATE”, “March 23, 2013”);

Node currentNode = fld2.getStart();
boolean isContinue = true;
while (currentNode != null && isContinue)
{
if (currentNode.getNodeType() == NodeType.FIELD_END)
isContinue = false;

<font color="RED"><b>if</b></font> <font color="BLUE"><b>(</b></font>currentNode<font color="BLUE"><b>.</b></font>getNodeType<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font> <font color="BLUE">=</font><font color="BLUE">=</font> NodeType<font color="BLUE"><b>.</b></font>RUN<font color="BLUE"><b>)</b></font>
    <font color="BLUE"><b>(</b></font><font color="BLUE"><b>(</b></font>Run<font color="BLUE"><b>)</b></font>currentNode<font color="BLUE"><b>)</b></font><font color="BLUE"><b>.</b></font>getFont<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>.</b></font>setBold<font color="BLUE"><b>(</b></font>true<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>

Node nextNode <font color="BLUE">=</font> currentNode<font color="BLUE"><b>.</b></font>nextPreOrder<font color="BLUE"><b>(</b></font>currentNode<font color="BLUE"><b>.</b></font>getDocument<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
currentNode <font color="BLUE">=</font> nextNode<font color="BLUE"><b>;</b></font>

}

I hope, this helps.

Best regards,