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

Free Support Forum - aspose.com

Protection of selected ranges supported?

Hello,

I’m trying to protect the document header and footer for editing. Currently I’m using sections and protecting it using “allowing only form fields editing” but we found that on doing this MS Word will disable some ms word tools (like text fields, symbols, etc). The user needs those tools available for editing the document body.

Now I’m trying to replicate the steps described on https://support.office.com/en-us/article/Allow-changes-to-parts-of-a-protected-document-187ed01c-8795-43e1-9fd0-c9fca419dadf using code api but I had no success yet.

Is this supported in Aspose Words? I understand this is called “protection of selected ranges” and I found some topics on this forum referencing WORDSNET-1067.

I’m using version Aspose Words 14.4 jdk16. If this is supported in a newer version I’d like to know too.

Thank you very much!



Hi Renato,


Thanks for your inquiry. Yes, the subjected feature is supported in Aspose.Words. EditableRangeStart class represents a start of an editable range in a Word document. EditableRangeEnd class represents an end of an editable range in a Word document.

A complete editable range in a Word document consists of a EditableRangeStart and a matching EditableRangeEnd with the same Id. EditableRangeStart and EditableRangeEnd are just markers inside a document that specify where the editable range starts and ends.

Please note that currently editable ranges are supported only at the inline-level, that is inside Paragraph, but editable range start and editable range end can be in different paragraphs. Badly formed editable range will be ignored when the document is saved.

Please check following code example to protect header and footer of first section of the document. Hopefully it will help you to accomplish the task.

com.aspose.words.Document doc = new
com.aspose.words.Document(
“in.docx”);<o:p></o:p>

doc.protect(ProtectionType.READ_ONLY);

DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToParagraph(0, 0);

builder.startEditableRange();

builder.moveToParagraph(doc.getFirstSection().getBody().getParagraphs().getCount() -1, -1);

builder.endEditableRange();

doc.save("Out.docx");


Best Regards,

Hello!
Thanks for the direction but unfortunately my api is missing the method builder.startEditableRange().
As I said I’m using version 14.4, can you check in which version this method was implemented?

Thank you very much!


Hello again!

I came up with this code, using aspose trial:

Document contentDoc = new Document(Teste.class.getResourceAsStream(“originaldocx”));
contentDoc.protect(ProtectionType.READ_ONLY);
DocumentBuilder builder = new DocumentBuilder(contentDoc);
for(Section section: contentDoc.getSections()){
section.setProtectedForForms(false);
builder.moveToSection(contentDoc.indexOf(section));
builder.moveTo(section.getBody().getFirstChild());
EditableRangeStart s = builder.startEditableRange();
builder.moveTo(section.getBody().getLastChild());
builder.endEditableRange(s);

}

Unfortunately some of my documents have text box and the user should be able to edit its content (ane even create new ones, but I guess this is a word problem). I guess there is no solution for this, right? There is some way to select the textbox and start and finish a range inside the text box?


Hi Renato,

Renato Amaral:
Hello!
Thanks for the direction but unfortunately my api is missing the method builder.startEditableRange().
As I said I'm using version 14.4, can you check in which version this method was implemented?

Thank you very much!



Thanks for your feedback. Please note, we have introduced the subjected feature in Aspose.Words for Java 15.9.

Best Regards,