### Upload File to Aspose Cloud Storage using Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Provides a Node.js example for uploading a local document to Aspose Cloud storage. This is a prerequisite for most cloud storage-based API operations. It uses streams for efficient file handling. ```typescript import { WordsApi, UploadFileRequest } from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Create a read stream from local file const fileContent = fs.createReadStream("local/path/document.docx"); // Create the upload request const uploadRequest = new UploadFileRequest({ fileContent: fileContent, path: "folder/document.docx" // Path in cloud storage }); // Upload the file wordsApi.uploadFile(uploadRequest) .then((result) => { console.log("File uploaded successfully"); console.log("Uploaded bytes:", result.body.uploaded); }) .catch((error) => { console.error("Upload failed:", error); }); ``` -------------------------------- ### Convert Document to PDF Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Provides examples for converting a Word document to PDF format, supporting both cloud storage and direct online conversion methods. ```APIDOC ## Convert Document to PDF Convert a Word document to PDF format. The SDK supports both cloud storage-based conversion and direct online conversion. ### Method POST ### Endpoint - Cloud Storage: /words/cloud/convert/{name} - Direct Online: /words/cloud/convert ### Parameters #### Method 1: Cloud Storage ##### Path Parameters - **name** (string) - Required - The name of the document. - **folder** (string) - Optional - The folder containing the document. ##### Request Body - **saveOptionsData** (PdfSaveOptionsData) - Required - Options for saving the PDF. ##### Request Example (Cloud Storage) ```typescript import * as model from "asposewordscloud"; const saveOptionsData = new model.PdfSaveOptionsData({ fileName: "output/document.pdf" }); const saveAsRequest = new model.SaveAsRequest({ name: "document.docx", saveOptionsData: saveOptionsData, folder: "input" }); wordsApi.saveAs(saveAsRequest) .then((result) => { console.log("Converted successfully:", result.body.saveResult.destDocument.href); }); ``` #### Method 2: Direct Online Conversion ##### Request Body - **document** (Stream) - Required - The document stream to convert. - **format** (string) - Required - The target format (e.g., "pdf"). ##### Request Example (Direct Online) ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const requestDocument = fs.createReadStream("document.docx"); const convertRequest = new model.ConvertDocumentRequest({ document: requestDocument, format: "pdf" }); wordsApi.convertDocument(convertRequest) .then((result) => { fs.writeFileSync("output.pdf", result.body); console.log("Document converted to PDF"); }); ``` ### Response #### Success Response (200) - **body** (Buffer/Stream) - The converted document content. ``` -------------------------------- ### GET /tables Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Retrieves a list of all tables present in a specified Word document. ```APIDOC ## GET /tables ### Description Retrieves all tables from a document located in the specified folder. ### Method GET ### Endpoint /words/{name}/tables ### Parameters #### Path Parameters - **name** (string) - Required - The filename of the document. #### Query Parameters - **folder** (string) - Optional - The folder where the document is stored. - **nodePath** (string) - Optional - The path to the node where tables are located. ### Response #### Success Response (200) - **tables** (object) - Contains a list of table links. #### Response Example { "tables": { "tableLinkList": [{"nodeId": "0.0.1"}] } } ``` -------------------------------- ### Manage Document Bookmarks with Aspose.Words Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Provides examples for retrieving, updating, inserting, and deleting bookmarks within Word documents using the Aspose.Words Cloud API. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Get all bookmarks const getBookmarksRequest = new model.GetBookmarksRequest({ name: "document.docx", folder: "input" }); wordsApi.getBookmarks(getBookmarksRequest).then((result) => { result.body.bookmarks.bookmarkList.forEach((bookmark) => { console.log("- Name:", bookmark.name, "| Text:", bookmark.text); }); }); // Get specific bookmark const getBookmarkRequest = new model.GetBookmarkByNameRequest({ name: "document.docx", bookmarkName: "myBookmark", folder: "input" }); wordsApi.getBookmarkByName(getBookmarkRequest).then((result) => { console.log("Bookmark text:", result.body.bookmark.text); }); // Update bookmark text const bookmarkData = new model.BookmarkData({ name: "myBookmark", text: "Updated bookmark content" }); const updateBookmarkRequest = new model.UpdateBookmarkRequest({ name: "document.docx", bookmarkName: "myBookmark", bookmarkData: bookmarkData, folder: "input", destFileName: "output/updated.docx" }); wordsApi.updateBookmark(updateBookmarkRequest).then((result) => { console.log("Bookmark updated"); }); // Insert new bookmark const bookmarkInsert = new model.BookmarkInsert({ startRange: new model.PositionInsideNode({ nodeId: "0.0.0.0", offset: 0 }), endRange: new model.PositionInsideNode({ nodeId: "0.0.0.0", offset: 10 }), name: "newBookmark", text: "Bookmarked text" }); const insertBookmarkRequest = new model.InsertBookmarkRequest({ name: "document.docx", bookmark: bookmarkInsert, folder: "input" }); wordsApi.insertBookmark(insertBookmarkRequest).then((result) => { console.log("Bookmark inserted"); }); // Delete bookmark const deleteBookmarkRequest = new model.DeleteBookmarkRequest({ name: "document.docx", bookmarkName: "myBookmark", folder: "input" }); wordsApi.deleteBookmark(deleteBookmarkRequest).then(() => { console.log("Bookmark deleted"); }); ``` -------------------------------- ### Compress Documents with Aspose.Words Cloud Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Provides examples for compressing documents to reduce file size. Includes both cloud storage-based compression and direct online streaming compression. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); const compressRequest = new model.CompressDocumentRequest({ name: "large_document.docx", compressOptions: new model.CompressOptions({}), folder: "input", destFileName: "output/compressed_document.docx" }); wordsApi.compressDocument(compressRequest).then((result) => { console.log("Document compressed"); }); const docStream = fs.createReadStream("large_document.docx"); const compressOnlineRequest = new model.CompressDocumentOnlineRequest({ document: docStream, compressOptions: new model.CompressOptions({}) }); wordsApi.compressDocumentOnline(compressOnlineRequest).then((result) => { const outputDoc = result.body.document.entries().next().value[1]; fs.writeFileSync("compressed.docx", outputDoc); }); ``` -------------------------------- ### Split Word Documents with Node.js SDK Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt This snippet demonstrates how to split a Word document into multiple smaller documents using the Aspose.Words Cloud SDK for Node.js. It includes examples for splitting by page range and splitting a document online. The SDK requires 'asposewordscloud' and 'fs' modules. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Split document by page range const splitRequest = new model.SplitDocumentRequest({ name: "multi_page_document.docx", format: "pdf", folder: "input", destFileName: "output/split_document", from: 1, to: 3 }); wordsApi.splitDocument(splitRequest) .then((result) => { console.log("Document split into", result.body.splitResult.pages.length, "pages"); result.body.splitResult.pages.forEach((page, index) => { console.log(`Page ${index + 1}:`, page.href); }); }); // Split document online const docStream = fs.createReadStream("multi_page_document.docx"); const splitOnlineRequest = new model.SplitDocumentOnlineRequest({ document: docStream, format: "pdf", destFileName: "split_output", from: 1, to: 2 }); wordsApi.splitDocumentOnline(splitOnlineRequest) .then((result) => { console.log("Online split complete"); }); ``` -------------------------------- ### GET /words/{name} Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Retrieves metadata and information about a Word document stored in the cloud. ```APIDOC ## GET /words/{name} ### Description Retrieve metadata and information about a Word document stored in the cloud. ### Method GET ### Endpoint /words/{name} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the document. #### Query Parameters - **folder** (string) - Optional - The folder where the document is stored. ### Request Example { "documentName": "document.docx", "folder": "input" } ### Response #### Success Response (200) - **document** (object) - Contains metadata like fileName, sourceFormat, isEncrypted, and isSigned. #### Response Example { "document": { "fileName": "document.docx", "sourceFormat": "Docx", "isEncrypted": false } } ``` -------------------------------- ### Get Document Information with Aspose.Words Cloud SDK for Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Retrieves metadata and information about a Word document stored in the cloud. It requires the document name and optionally a folder path. The output includes file name, source format, encryption status, signature status, and document properties. ```typescript import * as model from "asposewordscloud"; const wordsApi = new WordsApi(clientId, clientSecret); const getDocRequest = new model.GetDocumentRequest({ documentName: "document.docx", folder: "input" }); wordsApi.getDocument(getDocRequest) .then((result) => { const doc = result.body.document; console.log("File name:", doc.fileName); console.log("Source format:", doc.sourceFormat); console.log("Is encrypted:", doc.isEncrypted); console.log("Is signed:", doc.isSigned); console.log("Document properties:", doc.documentProperties); }); ``` -------------------------------- ### Manage Tables in Word Documents with Node.js SDK Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt This snippet shows how to perform various operations on tables within Word documents using the Aspose.Words Cloud SDK for Node.js. It covers getting all tables, inserting a new table, updating table properties, inserting a new row, and updating cell formatting. Dependencies include the 'asposewordscloud' SDK. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Get all tables from a document const getTablesRequest = new model.GetTablesRequest({ name: "document.docx", nodePath: "", folder: "input" }); wordsApi.getTables(getTablesRequest) .then((result) => { console.log("Tables found:", result.body.tables.tableLinkList.length); result.body.tables.tableLinkList.forEach((table) => { console.log("Table node ID:", table.nodeId); }); }); // Insert a new table const tableInsert = new model.TableInsert({ columnsCount: 5, rowsCount: 4 }); const insertTableRequest = new model.InsertTableRequest({ name: "document.docx", table: tableInsert, nodePath: "", folder: "input" }); wordsApi.insertTable(insertTableRequest) .then((result) => { console.log("Table inserted with", result.body.table.tableRowList.length, "rows and", result.body.table.tableRowList[0].tableCellList.length, "columns"); }); // Update table properties const tableProperties = new model.TableProperties({ alignment: model.TableProperties.AlignmentEnum.Center, allowAutoFit: true, bidi: false, bottomPadding: 5, cellSpacing: 2.0, styleOptions: model.TableProperties.StyleOptionsEnum.ColumnBands }); const updateTablePropertiesRequest = new model.UpdateTablePropertiesRequest({ name: "document.docx", properties: tableProperties, index: 0, nodePath: "", folder: "input" }); wordsApi.updateTableProperties(updateTablePropertiesRequest) .then((result) => { console.log("Table properties updated"); }); // Insert a new row const rowInsert = new model.TableRowInsert({ columnsCount: 5 }); const insertRowRequest = new model.InsertTableRowRequest({ name: "document.docx", row: rowInsert, nodePath: "sections/0/tables/0", folder: "input" }); wordsApi.insertTableRow(insertRowRequest) .then((result) => { console.log("Row inserted with", result.body.row.tableCellList.length, "cells"); }); // Update cell format const cellFormat = new model.TableCellFormat({ bottomPadding: 5.0, fitText: true, horizontalMerge: model.TableCellFormat.HorizontalMergeEnum.First, wrapText: true }); const updateCellFormatRequest = new model.UpdateTableCellFormatRequest({ name: "document.docx", format: cellFormat, tableRowPath: "sections/0/tables/0/rows/0", index: 0, folder: "input" }); wordsApi.updateTableCellFormat(updateCellFormatRequest) .then((result) => { console.log("Cell format updated"); }); ``` -------------------------------- ### Get Document Drawing Object by Index Source: https://github.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/blob/master/TestData/DocumentElements/DrawingObjects/sampleDrawingObject.txt This endpoint retrieves a specific drawing object from a document based on its index within a paragraph. It also provides links to render the drawing object in various image formats. ```APIDOC ## GET /v1.1/words/{name}/sections/{sectionIndex}/paragraphs/{paragraphIndex}/drawingObjects/{drawingObjectIndex} ### Description Retrieves a specific drawing object from a document by its index within a paragraph. It also provides links to render the drawing object in various image formats (JPEG, TIFF, PNG, BMP). ### Method GET ### Endpoint /v1.1/words/{name}/sections/{sectionIndex}/paragraphs/{paragraphIndex}/drawingObjects/{drawingObjectIndex} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the document. - **sectionIndex** (integer) - Required - The index of the section containing the paragraph. - **paragraphIndex** (integer) - Required - The index of the paragraph containing the drawing object. - **drawingObjectIndex** (integer) - Required - The index of the drawing object to retrieve. - **folder** (string) - Optional - The folder path where the document is located. ### Request Example ```json { "folder": "Temp\/SdkTests\/TestData\/DocumentElements\/DrawingObjects" } ``` ### Response #### Success Response (200) - **Link** (object) - Contains Href and Rel for the drawing object. - **NodeId** (string) - The unique identifier of the drawing object node. - **RelativeHorizontalPosition** (string) - The horizontal position of the drawing object relative to its container. - **RelativeVerticalPosition** (string) - The vertical position of the drawing object relative to its container. - **WrapType** (string) - The text wrapping style around the drawing object. - **RenderLinks** (array) - Links to render the drawing object in different image formats. - **Width** (integer) - The width of the drawing object. - **Height** (integer) - The height of the drawing object. - **ImageDataLink** (object) - Link to the image data of the drawing object. - **Left** (integer) - The distance from the left edge of the page to the left edge of the drawing object. - **Top** (integer) - The distance from the top edge of the page to the top edge of the drawing object. #### Response Example ```json { "Link": { "Href": "http://api-dev.aspose.cloud/v1.1/words/TestGetDocumentDrawingObjectByIndex.docx/sections/0/paragraphs/1/drawingObjects/0?folder=Temp%5cSdkTests%5cTestData%5cDocumentElements%5cDrawingObjects", "Rel": "self" }, "NodeId": "0.1.0", "RelativeHorizontalPosition": "Column", "RelativeVerticalPosition": "TextFrameDefault", "WrapType": "Inline", "RenderLinks": [ { "Href": "http://api-dev.aspose.cloud/v1.1/words/TestGetDocumentDrawingObjectByIndex.docx/sections/0/paragraphs/1/drawingObjects/0?folder=Temp%5cSdkTests%5cTestData%5cDocumentElements%5cDrawingObjects&format=jpeg", "Rel": "self" }, { "Href": "http://api-dev.aspose.cloud/v1.1/words/TestGetDocumentDrawingObjectByIndex.docx/sections/0/paragraphs/1/drawingObjects/0?folder=Temp%5cSdkTests%5cTestData%5cDocumentElements%5cDrawingObjects&format=tiff", "Rel": "self" }, { "Href": "http://api-dev.aspose.cloud/v1.1/words/TestGetDocumentDrawingObjectByIndex.docx/sections/0/paragraphs/1/drawingObjects/0?folder=Temp%5cSdkTests%5cTestData%5cDocumentElements%5cDrawingObjects&format=png", "Rel": "self" }, { "Href": "http://api-dev.aspose.cloud/v1.1/words/TestGetDocumentDrawingObjectByIndex.docx/sections/0/paragraphs/1/drawingObjects/0?folder=Temp%5cSdkTests%5cTestData%5cDocumentElements%5cDrawingObjects&format=bmp", "Rel": "self" } ], "Width": 300, "Height": 300, "ImageDataLink": { "Href": "http://api-dev.aspose.cloud/v1.1/words/TestGetDocumentDrawingObjectByIndex.docx/sections/0/paragraphs/1/drawingObjects/0/ImageData?folder=Temp%5cSdkTests%5cTestData%5cDocumentElements%5cDrawingObjects", "Rel": "self" }, "Left": 0, "Top": 0 } ``` ``` -------------------------------- ### Initializing the WordsApi Client Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Demonstrates how to initialize the WordsApi client with your Aspose Cloud credentials. ```APIDOC ## Initializing the WordsApi Client The WordsApi class is the main entry point for interacting with the Aspose.Words Cloud API. Initialize it with your client credentials obtained from the Aspose Cloud dashboard. ### Method Instantiate the WordsApi class. ### Parameters - **clientId** (string) - Required - Your Aspose Cloud client ID. - **clientSecret** (string) - Required - Your Aspose Cloud client secret. - **baseUrl** (string) - Optional - A custom base URL for the API endpoint. - **debug** (boolean) - Optional - Enable debug mode to log requests and responses. ### Request Example ```typescript import { WordsApi } from "asposewordscloud"; const clientId = "your-client-id"; const clientSecret = "your-client-secret"; const baseUrl = "https://api.aspose.cloud"; const wordsApi = new WordsApi(clientId, clientSecret, baseUrl); const wordsApiDebug = new WordsApi(clientId, clientSecret, baseUrl, true); ``` ``` -------------------------------- ### Initialize WordsApi Client in Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Demonstrates how to initialize the WordsApi client using client ID and secret. It shows how to set up the client for both default and debug modes, and optionally specify a custom base URL. ```typescript import { WordsApi, UploadFileRequest } from "asposewordscloud"; import * as fs from "fs"; // Initialize the API client with your credentials const clientId = "your-client-id"; const clientSecret = "your-client-secret"; // Optional: specify a custom base URL (defaults to Aspose Cloud) const baseUrl = "https://api.aspose.cloud"; // Create the API instance const wordsApi = new WordsApi(clientId, clientSecret, baseUrl); // Optional: enable debug mode to log all requests and responses const wordsApiDebug = new WordsApi(clientId, clientSecret, baseUrl, true); ``` -------------------------------- ### Convert DOCX to PDF using Aspose.Words Cloud SDK Source: https://github.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/blob/master/README.md This snippet demonstrates how to initialize the WordsApi, upload a local DOCX file to the cloud, and convert it to a PDF document using the SaveAsRequest. ```javascript const wordsApi = new WordsApi(clientId, clientSecret, baseUrl); const uploadRequest = new UploadFileRequest(); uploadRequest.path = "uploaded.docx"; uploadRequest.fileContent = createReadStream(localPath); wordsApi.uploadFile(uploadRequest) .then((_uploadResult) => { const request = new SaveAsRequest({ name: "uploaded.docx", saveOptionsData: new PdfSaveOptionsData({ fileName: "destination.pdf" }) }); wordsApi.saveAs(request) .then((_result) => { // Handle success }) .catch(function(_err) { // Handle saveAs error }); }) .catch(function(_err) { // Handle uploadFile error }); ``` -------------------------------- ### Create New Document in Cloud Storage using Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Shows how to create a new, empty Word document directly in Aspose Cloud storage using the Node.js SDK. It specifies the desired file name and output folder. ```typescript import * as model from "asposewordscloud"; const wordsApi = new WordsApi(clientId, clientSecret); // Create a new document in cloud storage const createRequest = new model.CreateDocumentRequest({ fileName: "NewDocument.docx", folder: "output" }); wordsApi.createDocument(createRequest) .then((result) => { console.log("Document created:", result.body.document.fileName); console.log("Source format:", result.body.document.sourceFormat); }) .catch((error) => { console.error("Failed to create document:", error); }); ``` -------------------------------- ### Execute Batch Requests with Aspose.Words Cloud Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Demonstrates how to group multiple API requests into a single batch operation to improve performance. It also shows how to chain requests using dependencies where the output of one request serves as the input for another. ```typescript import * as model from "asposewordscloud"; import { BatchPartRequest } from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); const request1 = new BatchPartRequest(new model.GetParagraphsRequest({ name: "document.docx", nodePath: "sections/0", folder: "input" })); const request2 = new BatchPartRequest(new model.GetParagraphRequest({ name: "document.docx", index: 0, nodePath: "sections/0", folder: "input" })); const request3 = new BatchPartRequest(new model.InsertParagraphRequest({ name: "document.docx", paragraph: new model.ParagraphInsert({ text: "This is a new paragraph" }), nodePath: "sections/0", folder: "input" })); wordsApi.batch(request1, request2, request3).then((result) => { console.log("Batch completed"); }); const downloadRequest = new BatchPartRequest(new model.GetDocumentWithFormatRequest({ name: "document.docx", format: "docx", folder: "input" })); const processRequest = new BatchPartRequest(new model.DeleteCommentsOnlineRequest({ document: downloadRequest.useAsSource() })); const convertRequest = new BatchPartRequest(new model.ConvertDocumentRequest({ document: processRequest.useAsSource(), format: "pdf" })); processRequest.dependsOn(downloadRequest); convertRequest.dependsOn(processRequest); wordsApi.batch(downloadRequest, processRequest, convertRequest).then((result) => { fs.writeFileSync("final.pdf", result.body[2]); }); ``` -------------------------------- ### Create New Document Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Explains how to create a new Word document in cloud storage with a specified file name and format. ```APIDOC ## Create New Document Create a new Word document in cloud storage with the specified file name and format. ### Method POST ### Endpoint /words/cloud/new ### Parameters #### Request Body - **fileName** (string) - Required - The name of the new document. - **folder** (string) - Optional - The folder in cloud storage where the document will be created. - **documentContent** (string) - Optional - Initial content for the document. - **format** (string) - Optional - The format of the document (e.g., "docx"). Defaults to "docx". ### Request Example ```typescript import * as model from "asposewordscloud"; const createRequest = new model.CreateDocumentRequest({ fileName: "NewDocument.docx", folder: "output" }); wordsApi.createDocument(createRequest) .then((result) => { console.log("Document created:", result.body.document.fileName); console.log("Source format:", result.body.document.sourceFormat); }) .catch((error) => { console.error("Failed to create document:", error); }); ``` ### Response #### Success Response (200) - **document** (DocumentInfo) - Information about the created document. - **fileName** (string) - The name of the document. - **sourceFormat** (string) - The format of the document. #### Response Example ```json { "document": { "fileName": "NewDocument.docx", "sourceFormat": "docx" } } ``` ``` -------------------------------- ### POST /words/{name}/reports/build Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Builds a report from a template stored in cloud storage using the LINQ Reporting Engine. ```APIDOC ## POST /words/{name}/reports/build ### Description Generates a document report by populating a template with data from JSON, XML, or CSV sources using the LINQ Reporting Engine. ### Method POST ### Endpoint /words/{name}/reports/build ### Parameters #### Path Parameters - **name** (string) - Required - The name of the template file in cloud storage. #### Request Body - **data** (string) - Required - The data source content. - **reportEngineSettings** (object) - Required - Configuration for the reporting engine including data source type and build options. ### Request Example { "data": "{\"persons\": [...]}", "reportEngineSettings": { "dataSourceType": "Json", "dataSourceName": "persons" } } ### Response #### Success Response (200) - **document** (object) - The generated report file details. #### Response Example { "document": { "fileName": "Report_Generated.docx" } } ``` -------------------------------- ### Upload File to Cloud Storage Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Shows how to upload a local document to Aspose Cloud storage, which is a prerequisite for many cloud storage-based API operations. ```APIDOC ## Upload File to Cloud Storage Upload a local document to Aspose Cloud storage before performing operations on it. This is required for cloud storage-based API methods. ### Method POST ### Endpoint /words/cloud/storage/file/{path} ### Parameters #### Path Parameters - **path** (string) - Required - The path in cloud storage where the file will be uploaded. #### Request Body - **fileContent** (Stream) - Required - The content of the file to upload. ### Request Example ```typescript import { WordsApi, UploadFileRequest } from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); const fileContent = fs.createReadStream("local/path/document.docx"); const uploadRequest = new UploadFileRequest({ fileContent: fileContent, path: "folder/document.docx" // Path in cloud storage }); wordsApi.uploadFile(uploadRequest) .then((result) => { console.log("File uploaded successfully"); console.log("Uploaded bytes:", result.body.uploaded); }) .catch((error) => { console.error("Upload failed:", error); }); ``` ### Response #### Success Response (200) - **uploaded** (integer) - The number of bytes uploaded. #### Response Example ```json { "uploaded": 12345 } ``` ``` -------------------------------- ### PUT /words/storage/file/{path} Source: https://github.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/blob/master/README.md Uploads a local file to the Aspose Cloud storage for further processing. ```APIDOC ## PUT /words/storage/file/{path} ### Description Uploads a file from the local machine to the specified path in the cloud storage. ### Method PUT ### Endpoint /words/storage/file/{path} ### Parameters #### Path Parameters - **path** (string) - Required - The destination path and filename in the cloud. #### Request Body - **fileContent** (binary) - Required - The raw content of the file to be uploaded. ### Request Example { "file": "binary_data" } ### Response #### Success Response (200) - **uploaded** (boolean) - Indicates if the file was uploaded successfully. #### Response Example { "uploaded": true } ``` -------------------------------- ### Convert Document to PDF in Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Illustrates two methods for converting a Word document to PDF using the Node.js SDK: one using cloud storage and another for direct online conversion without uploading. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Method 1: Convert document from cloud storage const saveOptionsData = new model.PdfSaveOptionsData({ fileName: "output/document.pdf" }); const saveAsRequest = new model.SaveAsRequest({ name: "document.docx", saveOptionsData: saveOptionsData, folder: "input" }); wordsApi.saveAs(saveAsRequest) .then((result) => { console.log("Converted successfully:", result.body.saveResult.destDocument.href); }); // Method 2: Convert document directly (online - no cloud storage needed) const requestDocument = fs.createReadStream("document.docx"); const convertRequest = new model.ConvertDocumentRequest({ document: requestDocument, format: "pdf" }); wordsApi.convertDocument(convertRequest) .then((result) => { fs.writeFileSync("output.pdf", result.body); console.log("Document converted to PDF"); }); ``` -------------------------------- ### Manage Revisions using Aspose.Words Cloud SDK for Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt This snippet demonstrates how to accept or reject all revisions within a document. It covers operations on documents stored in the cloud and online processing of local files. It requires the 'asposewordscloud' SDK and Node.js 'fs' module. Inputs are document file paths or streams, and outputs are processed documents. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Accept all revisions in cloud storage document const acceptRevisionsRequest = new model.AcceptAllRevisionsRequest({ name: "document_with_revisions.docx", folder: "input" }); wordsApi.acceptAllRevisions(acceptRevisionsRequest) .then((result) => { console.log("Revisions accepted. Result:", result.body.result.dest.href); }); // Accept all revisions online const docStream = fs.createReadStream("document_with_revisions.docx"); const onlineRequest = new model.AcceptAllRevisionsOnlineRequest({ document: docStream }); wordsApi.acceptAllRevisionsOnline(onlineRequest) .then((result) => { const outputDoc = result.body.document.entries().next().value[1]; fs.writeFileSync("clean_document.docx", outputDoc); console.log("Online revisions accepted"); }); // Reject all revisions const rejectRevisionsRequest = new model.RejectAllRevisionsRequest({ name: "document_with_revisions.docx", folder: "input" }); wordsApi.rejectAllRevisions(rejectRevisionsRequest) .then((result) => { console.log("All revisions rejected"); }); ``` -------------------------------- ### POST /words/{name}/compare Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Compare two Word documents and generate a comparison document showing the differences. ```APIDOC ## POST /words/{name}/compare ### Description Compare two Word documents and generate a comparison document showing the differences between them. ### Method POST ### Endpoint /words/{name}/compare ### Parameters #### Path Parameters - **name** (string) - Required - The name of the first document. #### Request Body - **compareData** (object) - Required - Contains author, dateTime, and fileReference for the second document. - **destFileName** (string) - Optional - The name of the resulting comparison document. ### Request Example { "name": "document1.doc", "compareData": { "author": "Author", "dateTime": "2024-01-15T00:00:00Z" }, "destFileName": "output/ComparisonResult.doc" } ### Response #### Success Response (200) - **document** (object) - The resulting comparison document metadata. #### Response Example { "document": { "fileName": "ComparisonResult.doc" } } ``` -------------------------------- ### Configuration API Source: https://github.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/blob/master/README.md This section details changes to API configuration, including app credentials and timeout settings. ```APIDOC ## API Configuration ### Description Allows configuration of API settings, including client ID/secret and request timeouts. ### Method POST ### Endpoint /config ### Request Body ```json { "clientId": "string", "clientSecret": "string", "timeout": 0 } ``` ### Response #### Success Response (200) - **ConfigResult** (object) - Contains the result of the configuration update. #### Response Example ```json { "ConfigResult": { "Message": "Configuration updated successfully." } } ``` ``` -------------------------------- ### Compare Documents with Aspose.Words Cloud SDK for Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Compares two Word documents and generates a comparison document highlighting differences. Supports comparing documents from cloud storage or online by providing local file streams. Requires document names, author, and date for comparison data. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Method 1: Compare documents from cloud storage const compareDataFileReference = model.FileReference.fromRemoteFilePath("folder/document2.doc"); const compareData = new model.CompareData({ author: "Comparison Author", dateTime: new Date("2024-01-15T00:00:00Z"), fileReference: compareDataFileReference }); const compareRequest = new model.CompareDocumentRequest({ name: "document1.doc", compareData: compareData, folder: "input", destFileName: "output/ComparisonResult.doc" }); wordsApi.compareDocument(compareRequest) .then((result) => { console.log("Comparison complete:", result.body.document.fileName); }); // Method 2: Compare documents online (both from local files) const doc1Stream = fs.createReadStream("document1.doc"); const doc2Stream = fs.createReadStream("document2.doc"); const fileReference = model.FileReference.fromLocalFileContent(doc2Stream); const compareOnlineRequest = new model.CompareDocumentOnlineRequest({ document: doc1Stream, compareData: new model.CompareData({ author: "Author", dateTime: new Date(), fileReference: fileReference }), destFileName: "ComparisonResult.doc" }); wordsApi.compareDocumentOnline(compareOnlineRequest) .then((result) => { console.log("Online comparison complete"); }); ``` -------------------------------- ### Append Documents using Aspose.Words Cloud SDK for Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt This snippet shows how to merge multiple documents into a single document. It covers appending documents from cloud storage and processing them online from local files. Dependencies include the 'asposewordscloud' SDK and Node.js 'fs' module. Inputs are document file paths or streams, and outputs are merged documents. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Append document from cloud storage const fileReference = model.FileReference.fromRemoteFilePath("input/document_to_append.docx"); const documentEntry = new model.DocumentEntry({ fileReference: fileReference, importFormatMode: model.DocumentEntry.ImportFormatModeEnum.KeepSourceFormatting }); const documentList = new model.DocumentEntryList({ documentEntries: [documentEntry] }); const appendRequest = new model.AppendDocumentRequest({ name: "main_document.docx", documentList: documentList, folder: "input", destFileName: "output/merged_document.docx" }); wordsApi.appendDocument(appendRequest) .then((result) => { console.log("Documents merged:", result.body.document.fileName); }); // Append documents online (from local files) const mainDocStream = fs.createReadStream("main_document.docx"); const appendDocStream = fs.createReadStream("document_to_append.docx"); const localFileReference = model.FileReference.fromLocalFileContent(appendDocStream); const onlineEntry = new model.DocumentEntry({ fileReference: localFileReference, importFormatMode: model.DocumentEntry.ImportFormatModeEnum.UseDestinationStyles }); const onlineRequest = new model.AppendDocumentOnlineRequest({ document: mainDocStream, documentList: new model.DocumentEntryList({ documentEntries: [onlineEntry] }) }); wordsApi.appendDocumentOnline(onlineRequest) .then((result) => { const outputDoc = result.body.document.entries().next().value[1]; fs.writeFileSync("merged.docx", outputDoc); console.log("Online merge complete"); }); ``` -------------------------------- ### Build Reports with LINQ Reporting Engine using Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Generates documents by populating templates with data from JSON, XML, or CSV sources. The snippet demonstrates both cloud-stored template processing and direct online file stream processing. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); const reportData = fs.readFileSync("data/ReportData.json", "utf8"); const reportEngineSettings = new model.ReportEngineSettings({ dataSourceType: model.ReportEngineSettings.DataSourceTypeEnum.Json, dataSourceName: "persons", reportBuildOptions: [ model.ReportBuildOptions.AllowMissingMembers, model.ReportBuildOptions.RemoveEmptyParagraphs ] }); const buildReportRequest = new model.BuildReportRequest({ name: "ReportTemplate.docx", data: reportData, reportEngineSettings: reportEngineSettings, folder: "templates" }); wordsApi.buildReport(buildReportRequest) .then((result) => { console.log("Report generated:", result.body.document.fileName); }); const templateStream = fs.createReadStream("ReportTemplate.docx"); const onlineRequest = new model.BuildReportOnlineRequest({ template: templateStream, data: reportData, reportEngineSettings: new model.ReportEngineSettings({ dataSourceType: model.ReportEngineSettings.DataSourceTypeEnum.Json, dataSourceName: "persons" }) }); wordsApi.buildReportOnline(onlineRequest) .then((result) => { fs.writeFileSync("GeneratedReport.docx", result.body); console.log("Online report generation complete"); }); ``` -------------------------------- ### POST /words/{name}/bookmarks Source: https://github.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/blob/master/README.md Inserts a new bookmark into the specified document. ```APIDOC ## POST /words/{name}/bookmarks ### Description Inserts a new bookmark into the document specified by the name parameter. ### Method POST ### Endpoint /words/{name}/bookmarks ### Parameters #### Path Parameters - **name** (string) - Required - The name of the document. #### Request Body - **Name** (string) - Required - The name of the bookmark. - **Text** (string) - Required - The text content of the bookmark. - **StartRange** (string) - Required - The starting range identifier. - **EndRange** (string) - Required - The ending range identifier. ### Request Example { "Name": "MyBookmark", "Text": "Sample text", "StartRange": "node_1", "EndRange": "node_2" } ### Response #### Success Response (200) - **Bookmark** (object) - The created bookmark object. #### Response Example { "Bookmark": { "Name": "MyBookmark", "Text": "Sample text" } } ``` -------------------------------- ### Paragraph and Table APIs Source: https://github.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/blob/master/README.md This section covers APIs for managing paragraphs, tables within headers/footers, and tab stops. ```APIDOC ## Paragraph and Table Manipulation APIs ### Description APIs to manage paragraphs, including updating format, inserting/deleting tab stops, and addressing paragraphs within tables in headers/footers. ### Method GET, POST, PUT, DELETE ### Endpoint /words/{name}/paragraphs/{index} /words/{name}/headersfooters/{headerFooterIndex}/tables/{tableIndex}/rows/{rowIndex}/cells/{cellIndex}/paragraphs/{paragraphIndex} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the document. - **index** (integer) - Required - The index of the paragraph. - **headerFooterIndex** (integer) - Required - The index of the header or footer. - **tableIndex** (integer) - Required - The index of the table. - **rowIndex** (integer) - Required - The index of the row. - **cellIndex** (integer) - Required - The index of the cell. - **paragraphIndex** (integer) - Required - The index of the paragraph within the cell. ### Request Body (Varies based on operation: get, insert, update, delete, tab stop management) ### Response #### Success Response (200) (Varies based on operation) #### Response Example ```json { "ParagraphFormat": { "StyleName": "string" } } ``` ``` -------------------------------- ### Manage Document Watermarks with Aspose.Words Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Demonstrates how to insert text or image watermarks into a document, process watermarks online via streams, and delete existing watermarks from a document. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); // Insert text watermark const textWatermarkData = new model.WatermarkDataText({ text: "CONFIDENTIAL" }); const insertWatermarkRequest = new model.InsertWatermarkRequest({ name: "document.docx", watermarkData: textWatermarkData, folder: "input", destFileName: "output/watermarked.docx" }); wordsApi.insertWatermark(insertWatermarkRequest).then((result) => { console.log("Text watermark added:", result.body.document.fileName); }); // Insert image watermark const imageFileReference = model.FileReference.fromRemoteFilePath("images/watermark.png"); const imageWatermarkData = new model.WatermarkDataImage({ image: imageFileReference }); const imageWatermarkRequest = new model.InsertWatermarkRequest({ name: "document.docx", watermarkData: imageWatermarkData, folder: "input", destFileName: "output/image_watermarked.docx" }); wordsApi.insertWatermark(imageWatermarkRequest).then((result) => { console.log("Image watermark added"); }); // Insert watermark online const docStream = fs.createReadStream("document.docx"); const onlineRequest = new model.InsertWatermarkOnlineRequest({ document: docStream, watermarkData: new model.WatermarkDataText({ text: "DRAFT" }) }); wordsApi.insertWatermarkOnline(onlineRequest).then((result) => { const outputDoc = result.body.document.entries().next().value[1]; fs.writeFileSync("watermarked.docx", outputDoc); }); // Delete watermark const deleteWatermarkRequest = new model.DeleteWatermarkRequest({ name: "watermarked.docx", folder: "input", destFileName: "output/no_watermark.docx" }); wordsApi.deleteWatermark(deleteWatermarkRequest).then((result) => { console.log("Watermark removed:", result.body.document.fileName); }); ``` -------------------------------- ### Search and Replace Text in Documents using Node.js Source: https://context7.com/aspose-words-cloud/aspose.words-cloud-sdk-for-node.js/llms.txt Performs text replacement and pattern searching within documents. Supports regex, case-sensitive matching, and whole-word matching for both cloud-hosted and local file streams. ```typescript import * as model from "asposewordscloud"; import * as fs from "fs"; const wordsApi = new WordsApi(clientId, clientSecret); const replaceTextParams = new model.ReplaceTextParameters({ oldValue: "Original Text", newValue: "Replacement Text", isMatchCase: true, isMatchWholeWord: false, isOldValueRegex: false }); const replaceRequest = new model.ReplaceTextRequest({ name: "document.docx", replaceText: replaceTextParams, folder: "input", destFileName: "output/document_updated.docx" }); wordsApi.replaceText(replaceRequest) .then((result) => { console.log("Replacements made:", result.body.matches); }); const documentStream = fs.createReadStream("document.docx"); const onlineReplaceRequest = new model.ReplaceTextOnlineRequest({ document: documentStream, replaceText: new model.ReplaceTextParameters({ oldValue: "aspose", newValue: "ASPOSE", isMatchCase: false, isMatchWholeWord: true, isOldValueRegex: false }) }); wordsApi.replaceTextOnline(onlineReplaceRequest) .then((result) => { const outputDoc = result.body.document.entries().next().value[1]; fs.writeFileSync("replaced.docx", outputDoc); }); const searchRequest = new model.SearchRequest({ name: "document.docx", pattern: "aspose", folder: "input" }); wordsApi.search(searchRequest) .then((result) => { console.log("Found", result.body.searchResults.resultsList.length, "matches"); result.body.searchResults.resultsList.forEach((match, index) => { console.log(`Match ${index + 1} at offset:`, match.rangeStart.offset); }); }); ```