I have a word document with numerous content controls which I am wanting to lock down by selecting them and then on the developer tab I select the group option which stops anyone changing text within the document i.e. they are only able to amend values in the content controls.
Is the group feature available in aspose and if so can you provide me with a code example of its use?
Document doc = new Document();
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.RICH_TEXT, MarkupLevel.BLOCK);
Paragraph para = new Paragraph(doc);
Run before = new Run(doc, "This is simple text in SDT. ");
StructuredDocumentTag groupSdt = new StructuredDocumentTag(doc, SdtType.GROUP, MarkupLevel.INLINE);
Run groupedTextRange = new Run(doc, "This text is grouped and can’t be edited. ");
Run after = new Run(doc, “This is simple text again.”);
doc.save(getMyDir() + “out.docx”);
Thanks for that information, I tried the code out and it was very useful.
What I am trying to do is add protection to a form. Within word I can select all, then choose the group option and
all the document is locked for updates apart from the structured document tags.
I was trying to do this programatically, along the lines of the code below, but the layout doesn’t seem to be
quite correct as I appear to be losing paragraphs.
SectionCollection sections = document.getSections();
Section section = sections.get(0);
Body body = section.getBody();
StructuredDocumentTag groupSdt = new StructuredDocumentTag(document, SdtType.GROUP, MarkupLevel.BLOCK);
NodeCollection nc = body.getChildNodes();
Are you able to provide me with a way of selecting all and grouping?
Thanks for your help. I’ve attached 2 documents the input one and expected one. The expected one was created by taking the input document, selecting all and then grouping it, all within Word.
I tried your suggestion and it works thanks, but there does seem to be a slight problem with it.
If I group the document using this code, then later, within word, if I select all and choose ungroup the document becomes corrupted.