Skip to content

GroupDocs.Editor RESTful for .NET via jQuery

Viktor Stupak edited this page Jul 3, 2024 · 2 revisions

Working with Word Processing Documents using GroupDocs.Editor RESTful for .NET via jQuery

Table of Contents

  1. Introduction
  2. Endpoint 1: Retrieving Supported Formats for Word Processing
  3. Endpoint 2: Creating a New Word Processing Document
  4. Endpoint 3: Uploading a Word Processing Document
  5. Endpoint 4: Editing a Word Processing Document
  6. Endpoint 5: Retrieving Meta Information about a Word Processing Document
  7. Endpoint 6: Generating Previews of a Word Processing Document
  8. Endpoint 7: Retrieving Stylesheets from a Word Processing Document
  9. Endpoint 8: Downloading a Word Processing Document - Edited if Exists
  10. Conclusion

Introduction

GroupDocs.Editor RESTful for .NET via jQuery provides powerful capabilities for creating, uploading, editing, updating, and retrieving information about Word Processing documents. This guide demonstrates how to use these functionalities through eight key endpoints: retrieving supported formats, creating a new document, uploading an existing document, editing a document by converting it to an editable HTML format, retrieving meta information, generating previews, retrieving stylesheets, and downloading the document in a specified format.

Endpoint 1: Retrieving Supported Formats for Word Processing

The supportedFormats endpoint allows developers to retrieve the list of supported Word Processing document formats. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/supportedFormats

jQuery AJAX Example

var settings = {
  "url": "{{baseUrl}}/WordProcessing/supportedFormats",
  "method": "GET",
  "headers": {
    "Accept": "text/plain"
  },
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Response Body

{
  "doc": "MS Word 97-2007 Binary File Format (DOC)",
  "docx": "Office Open XML WordProcessingML Macro-Free Document (DOCX)",
  "dot": "MS Word 97-2007 Template (DOT)",
  "docm": "Office Open XML WordProcessingML Macro-Enabled Document (DOCM)",
  "dotx": "Office Open XML WordprocessingML Macro-Free Template (DOTX)",
  "dotm": "Office Open XML WordprocessingML Macro-Enabled Template (DOTM)",
  "xml": "Office Open XML WordprocessingML flat XML",
  "rtf": "Rich Text Format (RTF)",
  "odt": "Open Document Format Text Document (ODT)",
  "ott": "Open Document Format Text Document Template (OTT)"
}

Explanation

  1. URL Configuration: Specifies the endpoint URL for retrieving the supported Word Processing document formats.

Endpoint 2: Creating a New Word Processing Document

The createNew endpoint allows developers to create a new Word Processing document. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/createNew
  • Data:
    • fileName: The name of the new document (e.g., "document.docx").
    • format: The format of the new document (e.g., "docx").

jQuery AJAX Example

var settings = {
  "url": "{{baseUrl}}/WordProcessing/createNew",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "Accept": "text/plain"
  },
  "data": JSON.stringify({
    "fileName": "document.docx",
    "format": "docx"
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Response Body

{
  "originalFile": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/240c3e85-53ca-4074-8c9a-76c61d210e72/string.docx",
    "resourceType": 5,
    "fileName": "string.docx",
    "documentCode": "240c3e85-53ca-4074-8c9a-76c61d210e72"
  },
  "originalLoadOptions": {
    "password": ""
  },
  "documentCode": "240c3e85-53ca-4074-8c9a-76c61d210e72",
  "documentInfo": {
    "familyFormat": "WordProcessing",
    "pageCount": 1,
    "size": 7132,
    "isEncrypted": false,
    "format": "docx"
  }
}

ResourceType Enumeration

The resourceType field can have the following values:

  • Image (0)
  • Font (1)
  • Stylesheet (2)
  • Audio (3)
  • HtmlContent (4)
  • OriginalDocument (5)
  • Preview (6)
  • ConvertedDocument (7)

Explanation

  1. URL Configuration: Specifies the endpoint URL for creating a new Word Processing document.
  2. Data: Contains the fileName and format properties in JSON format.

Endpoint 3: Uploading a Word Processing Document

The upload endpoint allows for uploading an existing Word Processing document to the server. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/upload
  • Data:
    • A FormData object containing the file to be uploaded.

jQuery AJAX Example

var form = new FormData();
form.append("File", fileInput.files[0], "document.docx");

var settings = {
  "url": "{{baseUrl}}/WordProcessing/upload",
  "method": "POST",
  "headers": {
    "Accept": "text/plain"
  },
  "processData": false,
  "mimeType": "multipart/form-data",
  "contentType": false,
  "data": form
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Explanation

  1. FormData Object: Holds the file data to be uploaded.
  2. URL Configuration: Specifies the endpoint URL for uploading the Word Processing document.
  3. AJAX Settings:
    • processData: Set to false to prevent automatic data transformation.
    • mimeType: Set to multipart/form-data.
    • contentType: Set to false to let the browser set the content type.

HTML Input Element

Ensure you have an HTML file input element to select the file:

<input type="file" id="fileInput" />

Endpoint 4: Editing a Word Processing Document

The edit endpoint allows for converting a Word Processing document to an editable HTML format with resources. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/edit
  • Data:
    • documentCode: The unique code of the document to be edited.
    • editOptions: Options for editing the document, such as enabling pagination, language information, and font extraction.

jQuery AJAX Example

var settings = {
  "url": "{{baseUrl}}/WordProcessing/edit",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "Accept": "text/plain"
  },
  "data": JSON.stringify({
    "documentCode": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "editOptions": {
      "enablePagination": true,
      "enableLanguageInformation": true,
      "extractOnlyUsedFont": true,
      "fontExtraction": 0,
      "inputControlsClassName": "string",
      "useInlineStyles": true
    }
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
  $("body").html(response.htmlContent); // Display the HTML content
});

Explanation

  1. URL Configuration: Specifies the endpoint URL for editing the Word Processing document.
  2. Data: Contains the documentCode and editOptions properties in JSON format.
    • enablePagination: Enables pagination in the resultant HTML document.
    • enableLanguageInformation: Specifies whether language information is exported to the HTML markup.
    • extractOnlyUsedFont: Indicates whether to extract only the font resources used in the document.
    • fontExtraction: Responsible for extracting font resources.
    • inputControlsClassName: Specifies a class name to be placed in the class attributes of HTML elements representing fields in the document.
    • useInlineStyles: Controls where to store the styling and formatting data of the document.
  3. Response Handling: The response contains the converted document in HTML format, which is displayed in the body of the page.

Edit Options

Details

Properties

  • EnableLanguageInformation: Specifies whether language information is exported to the HTML markup in the form of lang HTML attributes. Useful for multi-language documents. Default is false.
  • EnablePagination: Allows enabling or disabling pagination in the resultant HTML document. Default is false.
  • ExtractOnlyUsedFont: Indicates whether to extract only font resources used in the textual content of the document.
  • FontExtraction: Responsible for extracting font resources used in the input WordProcessing document. Default is NotExtract (0).
  • InputControlsClassName: Allows specifying a class name for the class attributes in HTML elements representing fields in the document. Default is NULL.
  • UseInlineStyles: Controls whether styling and formatting data are stored in external stylesheets (false) or as inline styles in the HTML markup (true). Default is false.

FontExtraction Options

  • NotExtract (0): Does not extract any font resources.
  • ExtractAllEmbedded (1): Extracts all embedded font resources, regardless of whether they are custom or system.
  • ExtractEmbeddedWithoutSystem (2): Extracts only custom (not system) embedded font resources.
  • ExtractAll (3): Tries to extract all fonts used in the document, including system fonts.

Endpoint 5: Retrieving Meta Information about a Word Processing Document

The metaInfo endpoint allows developers to get meta information about a Word Processing document. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/metaInfo/{documentCode}
    • Replace {documentCode} with the actual document code.
  • Data: None required for this request.

jQuery AJAX Example

var settings = {
  "url": "https://localhost:7240/WordProcessing/metaInfo/e5bd83d0-1314-45c4-8412-a10485daaa62",
  "method": "GET",
  "headers": {
    "Accept": "text/plain"
  },
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Response Body

{
  "originalFile": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/93271567-6394-4e0c-bc8f-aa2241882b6c/SampleDoc1.docx",
    "resourceType": 5,
    "fileName": "SampleDoc1.docx",
    "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c"
  },
  "originalLoadOptions": {
    "password": ""
  },
  "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c",
  "documentInfo": {
    "familyFormat": "WordProcessing",
    "pageCount": 4,
    "size": 46364,
    "isEncrypted": false,
    "format": "docx"
  },
  "previewImages": {},
  "storageSubFiles": {
    "0": {
      "editOptions": {
        "enablePagination": true,
        "enableLanguageInformation": false,
        "extractOnlyUsedFont": false,
        "fontExtraction": 0,
        "inputControlsClassName": null,
        "useInlineStyles": false
      },
      "subCode": "0",
      "isEdited": false,
      "originalDocumentName": "SampleDoc1.docx",
      "editedHtmlName": "SampleDoc1.html",
      "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c",
      "resources": {
        "style.css": {
          "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/93271567-6394-4e0c-bc8f-aa2241882b6c/0/style.css",
          "resourceType": 2,
          "fileName": "style.css",
          "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c"
        },
        "PaginalStyles.css": {
          "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/93271567-6394-4e0c-bc8f-aa2241882b6c/0/PaginalStyles.css",
          "resourceType": 2,
          "fileName": "PaginalStyles.css",
          "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c"
        },
        "Рисунок 1.png": {
          "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/93271567-6394-4e0c-bc8f-aa2241882b6c/0/%D0%A0%D0%B8%D1%81%D1%83%D0%BD%D0%BE%D0%BA%201.png",
          "resourceType": 0,
          "fileName": "Рисунок 1.png",
          "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c"
        },
        "SampleDoc1.html": {
          "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/93271567-6394-4e0c-bc8f-aa2241882b6c/0/SampleDoc1.html",
          "resourceType": 4,
          "fileName": "SampleDoc1.html",
          "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c"
        }
      }
    }
  }
}

Explanation

  1. URL Configuration: Specifies the endpoint URL for retrieving meta information about the Word Processing document. Replace {documentCode} with the actual document code.
  2. Response Handling: The response contains meta information about the document, including the original file link, document format, page count, size, and various resources related to the document.

The response body provides detailed meta information about the document, which can be used for further processing or display in your application.

Endpoint 6: Generating Previews of a Word Processing Document

The previews endpoint allows developers to generate previews of a Word Processing document. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/previews/{documentCode}
    • Replace {documentCode} with the actual document code.
  • Data: None required for this request.

jQuery AJAX Example

var settings = {
  "url": "https://localhost:7240/WordProcessing/previews/fbbd4594-b63a-475d-b4d9-97b10238a987",
  "method": "POST",
  "headers": {
    "Accept": "text/plain"
  },
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Response Body

The response is a list of SVG images for each page of the document:

{
  "0": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/55c20555-0b56-4ab4-9a6e-2f5946bf6131/preview/0.svg",
    "resourceType": 6,
    "fileName": "0.svg",
    "documentCode": "55c20555-0b56-4ab4-9a6e-2f5946bf6131"
  },
  "1": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/55c20555-0b56-4ab4-9a6e-2f5946bf6131/preview/1.svg",
    "resourceType": 6,
    "fileName": "1.svg",
    "documentCode": "55c20555-0b56-4ab4-9a6e-2f5946bf6131"
  },
  "2": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/55c20555-0b56-4ab4-9a6e-2f5946bf6131/preview/2.svg",
    "resourceType": 6,
    "fileName": "2.svg",
    "documentCode": "55c20555-0b56-4ab4-9a6e-2f5946bf6131"
  },
  "3": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/55c20555-0b56-4ab4-9a6e-2f5946bf6131/preview/3.svg",
    "resourceType": 6,
    "fileName": "3.svg",
    "documentCode": "55c20555-0b56-4ab4-9a6e-2f5946bf6131"
  }
}

Explanation

  1. URL Configuration: Specifies the endpoint URL for generating previews of the Word Processing document. Replace {documentCode} with the actual document code

. 2. Response Handling: The response contains a list of SVG images for each page of the document, with links to the files. Each page's preview is provided as an SVG file, which can be accessed via the fileLink.

The response body provides links to SVG previews of each page of the document, which can be used for displaying previews in your application.

Endpoint 7: Retrieving Stylesheets from a Word Processing Document

The stylesheets endpoint allows developers to retrieve all stylesheets from a Word Processing document. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/stylesheets/{documentCode}
    • Replace {documentCode} with the actual document code.
  • Data: None required for this request.

jQuery AJAX Example

var settings = {
  "url": "https://localhost:7240/WordProcessing/stylesheets/93271567-6394-4e0c-bc8f-aa2241882b6c",
  "method": "POST",
  "headers": {
    "Accept": "text/plain"
  },
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Response Body

The response contains all stylesheets extracted from the document.

{
  "0": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/93271567-6394-4e0c-bc8f-aa2241882b6c/styles/0.css",
    "resourceType": 2,
    "fileName": "0.css",
    "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c"
  },
  "1": {
    "fileLink": "https://s3.us-west-2.amazonaws.com/groupdocseditor/93271567-6394-4e0c-bc8f-aa2241882b6c/styles/1.css",
    "resourceType": 2,
    "fileName": "1.css",
    "documentCode": "93271567-6394-4e0c-bc8f-aa2241882b6c"
  }
}

Explanation

  1. URL Configuration: Specifies the endpoint URL for retrieving all stylesheets from the Word Processing document. Replace {documentCode} with the actual document code.
  2. Response Handling: The response contains a list of CSS files (stylesheets) extracted from the document, with links to the files. Each stylesheet is provided as a CSS file, which can be accessed via the fileLink.

The response body provides links to the extracted stylesheets from the document, which can be used for further processing or display in your application.

Endpoint 8: Downloading a Word Processing Document - Edited if Exists

The downloadInFormat endpoint allows developers to download a Word Processing document in a specified format, including any edits if they exist. Below is an example of how to implement this using jQuery.

Endpoint Details

  • URL: {{baseUrl}}/WordProcessing/downloadInFormat
  • Data:
    • documentCode: The unique code of the document to be downloaded.
    • format: The target format for the download (e.g., "rtf").
    • saveOptions: Options for saving the document, such as enabling pagination, specifying the output format, and optimizing memory usage.

jQuery AJAX Example

var settings = {
  "url": "https://localhost:7240/WordProcessing/downloadInFormat",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "Accept": "text/plain"
  },
  "data": JSON.stringify({
    "documentCode": "fbbd4594-b63a-475d-b4d9-97b10238a987",
    "format": "rtf",
    "saveOptions": {
      "enablePagination": true,
      "outputFormat": "rtf",
      "optimizeMemoryUsage": true
    }
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

Explanation

  1. URL Configuration: Specifies the endpoint URL for downloading the Word Processing document in the target format.
  2. Data: Contains the documentCode, format, and saveOptions properties in JSON format.
    • documentCode: The unique identifier for the document to be downloaded.
    • format: The target format for the download (e.g., "rtf").
    • saveOptions: Options for saving the document.
      • enablePagination: Enables pagination in the resultant document.
      • outputFormat: Specifies the output format for the document.
      • optimizeMemoryUsage: Optimizes memory usage during the document conversion process.

Response

The response will be a file in the target format specified in the request.

More WordProcessingSaveOptions

For more details on available options for saving Word Processing documents, refer to the GroupDocs.Editor WordProcessingSaveOptions documentation.

This reference provides comprehensive information on the various properties and methods available for configuring document save options, allowing for greater customization and control over the output format and quality of the saved documents.

By utilizing this endpoint, developers can easily download the Word Processing document in the desired format, including any edits made to the document. This functionality provides flexibility for exporting documents in various formats to meet different application requirements.

Conclusion

By utilizing the supportedFormats, createNew, upload, edit, metaInfo, previews, stylesheets, and downloadInFormat endpoints of GroupDocs.Editor RESTful for .NET via jQuery, developers can easily manage Word Processing documents within their web applications. These functionalities provide a robust foundation for building sophisticated document management systems.

For more advanced usage and additional features, refer to the GroupDocs.Editor documentation.

Clone this wiki locally