Accessing Word Automation Services using pnpjs

55 views Asked by At

We are investigating using SharePoint, SP, Word Automation Services, WAS, on demand to render Table of Contents, ToCs in word documents we are generating, prior to sending them to a third party vendor. Avoiding the need to open the Word Document to answer this prompt: Word ToC update Fields prompt

See https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee558830(v=office.14) "Supports all automatic tasks that execute when a document opens, such as: Updating the Table of Contents, the Table of Authorities, and index fields." And https://learn.microsoft.com/en-us/sharepoint/dev/general-development/what-s-new-in-word-automation-services-for-developers#perform-file-conversions-on-streams for operating on streams "Perform file conversions on streams The other new feature in Word Automation Services in Microsoft SharePoint is support for converting streams. In SharePoint 2010, you could only convert files that were stored in SharePoint libraries. Now you can also convert files that are stored outside SharePoint using streams." We would like to know if there is some way to use pnpjs to make synchronous WAS calls to SP sending the word doc, as a stream, with the newly generated ToC, have SP process the ToC through WAS getting back the fully calculated ToC and then send the result to a 3rd party.

All code would be executed via a nodejs application and would require us setting up SP with WAS somewhere.

If someone knows of a better way to handle ToCs in Word without having to set up SP just for the WAS service we are certainly open to suggestions.

We have tried Aspose's service but that service does not handle a newly generated file in which the prompt has not yet been answered (which does not work for us) it will update the ToC if the prompt has been answered then the values in the ToC have changed, just not the original prompt on creation.

1

There are 1 answers

2
Alexey Noskov On

MS Word shows such dialog box when some of fields in your document are marked as dirty, i.e. requires update. You can reset this flag using Aspose.Words to avoid the warning:

Document doc = new Document(@"C:\Temp\in.doc");

// Process the document, update TOC etc...
// ...

// Resert IsDirty flag of all fields in the document.
doc.Range.Fields.ToList().ForEach(f => f.IsDirty = false);

doc.Save(@"C:\Temp\out.docx");