Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merger-Node-v2
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.securityApi = merger_cloud.SecurityApi.fromKeys(appSid, appKey);
let options = new merger_cloud.Options();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/one-page.docx";
options.fileInfo.password = "Password";
options.outputPath = "Output/add-password.docx";
let result = await securityApi.addPassword(new merger_cloud.AddPasswordRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.pagesApi = merger_cloud.PagesApi.fromKeys(appSid, appKey);
let options = new merger_cloud.OrientationOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/four-pages.docx";
options.outputPath = "Output/change-page-orientation.docx";
options.pages = [2, 4];
options.mode = merger_cloud.OrientationOptions.ModeEnum.Landscape;
let result = await pagesApi.orientation(new merger_cloud.OrientationRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.securityApi = merger_cloud.SecurityApi.fromKeys(appSid, appKey);
let result = await securityApi.checkPassword(new merger_cloud.CheckPasswordRequest("WordProcessing/password-protected.docx"));
"use strict";
class Merger_Node_Copy_File {
static Run() {
var request = new groupdocs_merger_cloud_1.CopyFileRequest("Mergerdocs/one-page1.docx", "Mergerdocs/one-page-copied.docx", myStorage, myStorage);
fileApi.copyFile(request)
.then(function (response) {
console.log("Expected response type is Void: 'Mergerdocs/one-page1.docx' file copied as 'Mergerdocs/one-page-copied.docx'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Copy_File;
"use strict";
class Merger_Node_Copy_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.CopyFolderRequest("Mergerdocs", "Mergerdocs1", myStorage, myStorage);
folderApi.copyFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Mergerdocs' folder copied as 'Mergerdocs1'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Copy_Folder;
"use strict";
class Merger_Node_Create_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.CreateFolderRequest("Mergerdocs", myStorage);
folderApi.createFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Mergerdocs' folder created.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Create_Folder;
"use strict";
class Merger_Node_Delete_File {
static Run() {
var request = new groupdocs_merger_cloud_1.DeleteFileRequest("Mergerdocs1/one-page1.docx", myStorage);
fileApi.deleteFile(request)
.then(function (response) {
console.log("Expected response type is Void: 'Mergerdocs1/one-page1.docx' deleted.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Delete_File;
"use strict";
class Merger_Node_Delete_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.DeleteFolderRequest("Mergerdocs/Mergerdocs1", myStorage, true);
folderApi.deleteFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Mergerdocs/Mergerdocs1' folder deleted recursively.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Delete_Folder;
"use strict";
class Merger_Node_Download_File {
static Run() {
var request = new groupdocs_merger_cloud_1.DownloadFileRequest("Mergerdocs/one-page.docx", myStorage);
fileApi.downloadFile(request)
.then(function (response) {
console.log("Expected response type is Stream: " + response.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Download_File;
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.pagesApi = merger_cloud.PagesApi.fromKeys(appSid, appKey);
let options = new merger_cloud.ExtractOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/sample-10-pages.docx";
options.outputPath = "Output/extract-pages-by-numbers.docx";
options.pages = [2, 4, 7];
let result = await pagesApi.extract(new merger_cloud.ExtractRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.pagesApi = merger_cloud.PagesApi.fromKeys(appSid, appKey);
let options = new merger_cloud.ExtractOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/sample-10-pages.docx";
options.outputPath = "Output/extract-pages-by-range.docx";
options.startPageNumber = 1;
options.endPageNumber = 10;
options.rangeMode = merger_cloud.ExtractOptions.RangeModeEnum.EvenPages;
let result = await pagesApi.extract(new merger_cloud.ExtractRequest(options));
"use strict";
class Merger_Node_Get_Disc_Usage {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.GetDiscUsageRequest(myStorage);
storageApi.getDiscUsage(request)
.then(function (response) {
console.log("Expected response type is DiscUsage: " + response.usedSize);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Get_Disc_Usage;
"use strict";
class Merger_Node_Get_File_Versions {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.GetFileVersionsRequest("Mergerdocs/one-page.docx", myStorage);
storageApi.getFileVersions(request)
.then(function (response) {
console.log("Expected response type is FileVersions: " + response.value.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Get_File_Versions;
"use strict";
class Merger_Node_Get_Files_List {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.GetFilesListRequest("Mergerdocs/sample.docx", myStorage);
folderApi.getFilesList(request)
.then(function (response) {
console.log("Expected response type is FilesList: " + response.value.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Get_Files_List;
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.infoApi = merger_cloud.InfoApi.fromKeys(appSid, appKey);
let fileInfo = new merger_cloud.FileInfo();
fileInfo.filePath = "WordProcessing/password-protected.docx";
fileInfo.password = "password";
fileInfo.storageName = myStorage;
let request = new merger_cloud.GetInfoRequest(fileInfo);
let response = await infoApi.getInfo(request);
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.infoApi = merger_cloud.InfoApi.fromKeys(appSid, appKey);
let response = await infoApi.getSupportedFileFormats();
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.documentApi = merger_cloud.DocumentApi.fromKeys(appSid, appKey);
let item1 = new merger_cloud.JoinItem();
item1.fileInfo = new merger_cloud.FileInfo();
item1.fileInfo.filePath = "WordProcessing/four-pages.docx";
let item2 = new merger_cloud.JoinItem();
item2.fileInfo = new merger_cloud.FileInfo();
item2.fileInfo.filePath = "WordProcessing/one-page.docx";
let options = new merger_cloud.JoinOptions();
options.joinItems = [item1, item2];
options.outputPath = "Output/joined.docx";
let result = await documentApi.join(new merger_cloud.JoinRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.documentApi = merger_cloud.DocumentApi.fromKeys(appSid, appKey);
let item1 = new merger_cloud.JoinItem();
item1.fileInfo = new merger_cloud.FileInfo();
item1.fileInfo.filePath = "WordProcessing/sample-10-pages.docx";
item1.pages = [3, 6, 8];
let item2 = new merger_cloud.JoinItem();
item2.fileInfo = new merger_cloud.FileInfo();
item2.fileInfo.filePath = "WordProcessing/four-pages.docx";
item2.startPageNumber = 1
item2.endPageNumber = 4
item2.rangeMode = merger_cloud.JoinItem.RangeModeEnum.OddPages;
let options = new merger_cloud.JoinOptions();
options.joinItems = [item1, item2];
options.outputPath = "Output/joined-pages.docx";
let result = await documentApi.join(new merger_cloud.JoinRequest(options));
"use strict";
class Merger_Node_Move_File {
static Run() {
var request = new groupdocs_merger_cloud_1.MoveFileRequest("Mergerdocs/one-page1.docx", "Mergerdocs1/one-page1.docx", myStorage, myStorage);
fileApi.moveFile(request)
.then(function (response) {
console.log("Expected response type is Void: 'Mergerdocs/one-page1.docx' file moved to 'Mergerdocs1/one-page1.docx'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Move_File;
"use strict";
class Merger_Node_Move_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.MoveFolderRequest("Mergerdocs1", "Mergerdocs/Mergerdocs1", myStorage, myStorage);
folderApi.moveFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Mergerdocs1' folder moved to 'Mergerdocs/Mergerdocs1'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Move_Folder;
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.pagesApi = merger_cloud.PagesApi.fromKeys(appSid, appKey);
let options = new merger_cloud.MoveOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/four-pages.docx";
options.outputPath = "Output/move-pages.docx";
options.pageNumber = 1;
options.newPageNumber = 2;
let result = await pagesApi.move(new merger_cloud.MoveRequest(options));
"use strict";
class Merger_Node_Object_Exists {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.ObjectExistsRequest("Mergerdocs/one-page.docx", myStorage);
storageApi.objectExists(request)
.then(function (response) {
console.log("Expected response type is ObjectExist: " + response.exists);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Object_Exists;
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.documentApi = merger_cloud.DocumentApi.fromKeys(appSid, appKey);
let options = new merger_cloud.PreviewOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/four-pages.docx";
options.outputPath = "Output/preview-page";
options.pages = [1, 3];
options.format = merger_cloud.PreviewOptions.FormatEnum.Png;
let result = await documentApi.preview(new merger_cloud.PreviewRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.securityApi = merger_cloud.SecurityApi.fromKeys(appSid, appKey);
let options = new merger_cloud.Options();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/password-protected.docx";
options.fileInfo.password = "password";
options.outputPath = "Output/remove-password.docx";
let result = await securityApi.removePassword(new merger_cloud.RemovePasswordRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.pagesApi = merger_cloud.PagesApi.fromKeys(appSid, appKey);
let options = new merger_cloud.RemoveOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/four-pages.docx";
options.outputPath = "Output/remove-pages.docx";
options.pages = [2, 4];
let result = await pagesApi.remove(new merger_cloud.RemoveRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.pagesApi = merger_cloud.PagesApi.fromKeys(appSid, appKey);
let options = new merger_cloud.RotateOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "Pdf/ten-pages.pdf";
options.outputPath = "Output/rotate-pages.pdf";
options.pages = [2, 4];
options.mode = merger_cloud.RotateOptions.ModeEnum.Rotate90;
let result = await pagesApi.rotate(new merger_cloud.RotateRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.documentApi = merger_cloud.DocumentApi.fromKeys(appSid, appKey);
let options = new merger_cloud.SplitOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/sample-10-pages.docx";
options.outputPath = "Output/split-to-multipage-document";
options.pages = [3, 6, 8];
options.mode = merger_cloud.SplitOptions.ModeEnum.Intervals;
let result = await documentApi.split(new merger_cloud.SplitRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.documentApi = merger_cloud.DocumentApi.fromKeys(appSid, appKey);
let options = new merger_cloud.SplitOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/sample-10-pages.docx";
options.outputPath = "Output/split-document";
options.pages = [1, 3];
options.mode = merger_cloud.SplitOptions.ModeEnum.Pages;
let result = await documentApi.split(new merger_cloud.SplitRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.documentApi = merger_cloud.DocumentApi.fromKeys(appSid, appKey);
let options = new merger_cloud.SplitOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/sample-10-pages.docx";
options.outputPath = "Output/split-by-start-end-numbers";
options.startPageNumber = 3;
options.endPageNumber = 7;
options.mode = merger_cloud.SplitOptions.ModeEnum.Pages;
let result = await documentApi.split(new merger_cloud.SplitRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.documentApi = merger_cloud.DocumentApi.fromKeys(appSid, appKey);
let options = new merger_cloud.SplitOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/sample-10-pages.docx";
options.outputPath = "Output/split-by-start-end-numbers-with-filter";
options.startPageNumber = 3;
options.endPageNumber = 7;
options.rangeMode = merger_cloud.SplitOptions.RangeModeEnum.OddPages;
options.mode = merger_cloud.SplitOptions.ModeEnum.Pages;
let result = await documentApi.split(new merger_cloud.SplitRequest(options));
"use strict";
class Merger_Node_Storage_Exist {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_merger_cloud_1.StorageExistsRequest(myStorage);
storageApi.storageExists(request)
.then(function (response) {
console.log("Expected response type is StorageExist: " + response.exists);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Merger_Node_Storage_Exist;
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.pagesApi = merger_cloud.PagesApi.fromKeys(appSid, appKey);
let options = new merger_cloud.SwapOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/four-pages.docx";
options.outputPath = "Output/swap-pages.docx";
options.firstPageNumber = 2;
options.secondPageNumber = 4;
let result = await pagesApi.swap(new merger_cloud.SwapRequest(options));
// For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-node-samples
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.securityApi = merger_cloud.SecurityApi.fromKeys(appSid, appKey);
let options = new merger_cloud.UpdatePasswordOptions();
options.fileInfo = new merger_cloud.FileInfo();
options.fileInfo.filePath = "WordProcessing/password-protected.docx";
options.fileInfo.password = "password";
options.outputPath = "Output/update-password.docx";
options.newPassword = "NewPassword";
let result = await securityApi.updatePassword(new merger_cloud.UpdatePasswordRequest(options));
"use strict";
class Merger_Node_Upload_File {
static Run() {
// Open file in IOStream from local/disc.
var resourcesFolder = './Resources/Mergerdocs/one-page.docx';
fs.readFile(resourcesFolder, (err, fileStream) => {
var request = new groupdocs_merger_cloud_1.UploadFileRequest("Mergerdocs/one-page1.docx", fileStream, myStorage);
fileApi.uploadFile(request)
.then(function (response) {
console.log("Expected response type is FilesUploadResult: " + response.uploaded.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
});
}
}
module.exports = Merger_Node_Upload_File;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment