Page 1 of 1

Alert/error in the generated document

PostPosted: Mon Aug 18, 2014 11:17 pm
by vinaykadiyam
Hi Jason,

After generating .docx file, we are getting an error/alert saying "This document contains fields that may refer to other file. Do you want to update the fields in this document?" though we do not have any reference to other files.

Any help would be appreciated.

Thanks,
Vinay.

Re: Alert/error in the generated document

PostPosted: Tue Aug 19, 2014 8:53 am
by jason
As with any request for assistance, I can only help if you provide the following so I can reproduce

- inputs
- minimal necessary/sufficient source code
- resulting output docx

You can attach to this thread, or email support@plutext.com if the input is sensitive.

What version of Word?

Re: Alert/error in the generated document

PostPosted: Wed Aug 20, 2014 8:28 pm
by vinaykadiyam
Apology for not giving any inputs.

I debugged more into it and found that that alert is coming in the "Table of Contents" generation. Below is the code for generating TOC.

// Generate TOC
private void generateTOC() {
ObjectFactory factory = Context.getWmlObjectFactory();
P p = factory.createP();
R r = factory.createR();
FldChar fldChar = factory.createFldChar();
fldChar.setFldCharType(STFldCharType.BEGIN);
fldChar.setDirty(true);
r.getContent().add(getWrappedFldChar(fldChar));
p.getContent().add(r);
R r1 = factory.createR();
Text text = new Text();
text.setSpace("preserve");
text.setValue("TOC \\o \"1-3\" \\h \\z \\u");
r1.getContent().add(factory.createRInstrText(text));
p.getContent().add(r1);
FldChar fldcharend = factory.createFldChar();
fldcharend.setFldCharType(STFldCharType.END);
R r2 = factory.createR();
r2.getContent().add(getWrappedFldChar(fldcharend));
p.getContent().add(r2);

MainDocumentPart mainDocumentPart = mlPackageWriteOnly
.getMainDocumentPart();
// Adding Print View and Setting Update Field to true
CTSettings ct = new CTSettings();
DocumentSettingsPart dsp = mainDocumentPart.getDocumentSettingsPart();
if (dsp == null) {
try {
dsp = new DocumentSettingsPart();
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CTView ctView = Context.getWmlObjectFactory().createCTView();
ctView.setVal(STView.PRINT);
ct.setView(ctView);
BooleanDefaultTrue b = new BooleanDefaultTrue();
b.setVal(true);
ct.setUpdateFields(b);
dsp.setJaxbElement(ct);
try {
mainDocumentPart.addTargetPart(dsp);
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Document wmlDocument = (Document) mainDocumentPart.getJaxbElement();
Body body = wmlDocument.getBody();
body.getContent().add(p);

// add page break
Br objBr = new Br();
objBr.setType(STBrType.PAGE);

mainDocumentPart.addObject(objBr);
}


Please let us know if have any commnets.

Thanks,
Vinay.

Re: Alert/error in the generated document

PostPosted: Wed Aug 20, 2014 9:46 pm
by vinaykadiyam
I have tried with code found in working example at http://dev.plutext.org/trac/docx4j/brow ... ddTOC.java. I could add TOC but it is adding to first page of the document which I do not want.

So, is there a way to add it after some text. Please attached doc for reference which is adding at start of the doc but I want to add it to 3 page.

Expecting TOc like in Required_XXXX.docx not like in WithPlutextXXXX.docx (please see attached files for reference).


Thanks,
Vinay

Re: Alert/error in the generated document

PostPosted: Wed Aug 20, 2014 10:40 pm
by jason
Of course you can adapt the code to insert the field at some other index in the content list.

But there is no API which says add it at a certain page.

I haven't look at your documents, but if you have hard coded page breaks at the end of page 1 and 2, then you can find the second of these, and insert after that.

Alternatively, you can mark the location in your input docx using a content control (or even a bookmark), then find it, and insert there.

Re: Alert/error in the generated document

PostPosted: Wed Aug 20, 2014 10:56 pm
by vinaykadiyam
Hi Jason,

I didn't get this. It would be helpful if you can explain more about it.
I haven't look at your documents, but if you have hard coded page breaks at the end of page 1 and 2, then you can find the second of these, and insert after that.

Alternatively, you can mark the location in your input docx using a content control (or even a bookmark), then find it, and insert there.



Thanks,
Vinay

Re: Alert/error in the generated document

PostPosted: Thu Aug 21, 2014 1:39 pm
by jason
It would help if you explain your requirements/document production process:

- do you need to insert complete TOC results, or is it enough to insert a TOC field and leave it to Word to generate the TOC from the field?

- if you need to generate the complete TOC results yourself, does that include page numbers?

- do you have control over the input documents? Like your example document, do they always have a cover page, and space on p3 for the TOC? (If you have control over the format of the input documents, and you can leave it to Word to generate the complete TOC, then why don't you just add the TOC field in Word and save the input docx?)