Last active
November 11, 2019 14:48
-
-
Save groupdocscloud/a22ef5f91f7f8565fee2bac658674b49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merger-Java-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.SecurityOperations; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to add password to document. | |
*/ | |
public class Merger_Java_AddDocumentPassword { | |
public static void main(String[] args) { | |
SecurityApi apiInstance = new SecurityApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/one-page.docx"); | |
fileInfo.setPassword("password"); | |
Options options = new Options(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/add-password.docx"); | |
AddPasswordRequest request = new AddPasswordRequest(options); | |
DocumentResult response = apiInstance.addPassword(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.PagesOperations; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to change document page orientation. | |
*/ | |
public class Merger_Java_ChangePageOrientation { | |
public static void main(String[] args) { | |
PagesApi apiInstance = new PagesApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/four-pages.docx"); | |
OrientationOptions options = new OrientationOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/change-page-orientation.docx"); | |
options.setPages(Arrays.asList(2, 4)); | |
options.setMode(OrientationOptions.ModeEnum.LANDSCAPE); | |
OrientationRequest request = new OrientationRequest(options); | |
DocumentResult response = apiInstance.orientation(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.SecurityOperations; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to check document password. | |
*/ | |
public class Merger_Java_CheckDocumentPasswordProtection { | |
public static void main(String[] args) { | |
SecurityApi apiInstance = new SecurityApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/password-protected.docx"); | |
CheckPasswordRequest request = new CheckPasswordRequest(fileInfo.getFilePath(), Utils.MYStorage, null); | |
PasswordResult response = apiInstance.checkPassword(request); | |
System.err.println("checkPassword: " + response.getIsPasswordSet()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Files; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Copy_File { | |
public static void main(String[] args) { | |
FileApi apiInstance = new FileApi(Utils.AppSID, Utils.AppKey); | |
try { | |
CopyFileRequest request = new CopyFileRequest("WordProcessing\\two-page.docx", | |
"WordProcessing\\two-page-copied.docx", Utils.MYStorage, Utils.MYStorage, null); | |
apiInstance.copyFile(request); | |
System.out.println( | |
"Expected response type is Void: 'Mergers/one-page1.docx' file copied as 'Mergers/one-page-copied.docx'."); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FileApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Folder; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Copy_Folder { | |
public static void main(String[] args) { | |
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey); | |
try { | |
CopyFolderRequest request = new CopyFolderRequest("Mergers", "Mergers1", Utils.MYStorage, | |
Utils.MYStorage); | |
apiInstance.copyFolder(request); | |
System.out.println("Expected response type is Void: 'Mergers' folder copied as 'Mergers1'."); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FolderApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Folder; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Create_Folder { | |
public static void main(String[] args) { | |
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey); | |
try { | |
CreateFolderRequest request = new CreateFolderRequest("Mergers", Utils.MYStorage); | |
apiInstance.createFolder(request); | |
System.out.println("Expected response type is Void: 'Mergers' folder created."); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FolderApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Files; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Delete_File { | |
public static void main(String[] args) { | |
FileApi apiInstance = new FileApi(Utils.AppSID, Utils.AppKey); | |
try { | |
DeleteFileRequest request = new DeleteFileRequest("Mergers1\\one-page1.docx", Utils.MYStorage, null); | |
apiInstance.deleteFile(request); | |
System.out.println("Expected response type is Void: 'Mergers1/one-page1.docx' deleted."); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FileApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Folder; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Delete_Folder { | |
public static void main(String[] args) { | |
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey); | |
try { | |
DeleteFolderRequest request = new DeleteFolderRequest("Mergers\\Mergers1", Utils.MYStorage, true); | |
apiInstance.deleteFolder(request); | |
System.out | |
.println("Expected response type is Void: 'Mergers/Mergers1' folder deleted recusrsively."); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FolderApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Files; | |
import java.io.File; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Download_File { | |
public static void main(String[] args) { | |
FileApi apiInstance = new FileApi(Utils.AppSID, Utils.AppKey); | |
try { | |
DownloadFileRequest request = new DownloadFileRequest("WordProcessing\\two-page.docx", Utils.MYStorage, null); | |
File response = apiInstance.downloadFile(request); | |
System.err.println("Expected response type is File: " + response.length()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FileApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.PagesOperations.ExtractPages; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to extract document pages by specifying their numbers. | |
*/ | |
public class Merger_Java_ExtractPagesByNumbers { | |
public static void main(String[] args) { | |
PagesApi apiInstance = new PagesApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/sample-10-pages.docx"); | |
ExtractOptions options = new ExtractOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/extract-pages-by-numbers.docx"); | |
options.setPages(Arrays.asList(2, 4, 7)); | |
ExtractRequest request = new ExtractRequest(options); | |
DocumentResult response = apiInstance.extract(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.PagesOperations.ExtractPages; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to extract document pages by specifying page numbers range. | |
*/ | |
public class Merger_Java_ExtractPagesByRange { | |
public static void main(String[] args) { | |
PagesApi apiInstance = new PagesApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/sample-10-pages.docx"); | |
ExtractOptions options = new ExtractOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/extract-pages-by-range.docx"); | |
options.setStartPageNumber(1); | |
options.setEndPageNumber(10); | |
options.setRangeMode(PageOptions.RangeModeEnum.EVENPAGES); | |
ExtractRequest request = new ExtractRequest(options); | |
DocumentResult response = apiInstance.extract(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Storage; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.*; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Get_Disc_Usage { | |
public static void main(String[] args) { | |
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey); | |
try { | |
GetDiscUsageRequest request = new GetDiscUsageRequest(Utils.MYStorage); | |
DiscUsage response = apiInstance.getDiscUsage(request); | |
System.out.println("Expected response type is DiscUsage: " + response.getUsedSize()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling StorageApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Storage; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.*; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Get_File_Versions { | |
public static void main(String[] args) { | |
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey); | |
try { | |
GetFileVersionsRequest request = new GetFileVersionsRequest("Mergers\\one-page.docx", Utils.MYStorage); | |
FileVersions response = apiInstance.getFileVersions(request); | |
System.out.println("Expected response type is FileVersions: " + response.getValue().size()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling StorageApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Folder; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.FilesList; | |
import com.groupdocs.cloud.Merger.model.*; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Get_Files_List { | |
public static void main(String[] args) { | |
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey); | |
try { | |
GetFilesListRequest request = new GetFilesListRequest("Mergers", Utils.MYStorage); | |
FilesList response = apiInstance.getFilesList(request); | |
System.out.println("Expected response type is FilesList."); | |
for (StorageFile storageFile : response.getValue()) { | |
System.out.println("Files: " + storageFile.getPath()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FolderApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to get document info. | |
*/ | |
public class Merger_Java_GetDocumentInformation { | |
public static void main(String[] args) { | |
InfoApi apiInstance = new InfoApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/password-protected.docx"); | |
fileInfo.setPassword("password"); | |
GetInfoRequest request = new GetInfoRequest(fileInfo); | |
InfoResult response = apiInstance.getInfo(request); | |
System.err.println("InfoResult.Pages.Count: " + response.getPages().size()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling InfoApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.api.InfoApi; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to obtain all supported file types. | |
*/ | |
public class Merger_Java_GetSupportedFileTypes { | |
public static void main(String[] args) { | |
InfoApi apiInstance = new InfoApi(Utils.GetConfiguration()); | |
try { | |
FormatsResult response = apiInstance.getSupportedFileFormats(); | |
for (Format format : response.getFormats()) { | |
System.out.println(format.getFileFormat()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling InfoApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.DocumentOperations; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to join multiple documents into one document. | |
*/ | |
public class Merger_Java_JoinMultipleDocuments { | |
public static void main(String[] args) { | |
DocumentApi apiInstance = new DocumentApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo1 = new FileInfo(); | |
fileInfo1.setFilePath("WordProcessing/four-pages.docx"); | |
JoinItem item1 = new JoinItem(); | |
item1.setFileInfo(fileInfo1); | |
FileInfo fileInfo2 = new FileInfo(); | |
fileInfo2.setFilePath("WordProcessing/one-page.docx"); | |
JoinItem item2 = new JoinItem(); | |
item2.setFileInfo(fileInfo2); | |
JoinOptions options = new JoinOptions(); | |
options.setJoinItems(Arrays.asList(item1, item2)); | |
options.setOutputPath("output/joined.docx"); | |
JoinRequest request = new JoinRequest(options); | |
DocumentResult response = apiInstance.join(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.DocumentOperations; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to join specific pages from several source documents. | |
*/ | |
public class Merger_Java_JoinPagesFromVariousDocuments { | |
public static void main(String[] args) { | |
DocumentApi apiInstance = new DocumentApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo1 = new FileInfo(); | |
fileInfo1.setFilePath("WordProcessing/sample-10-pages.docx"); | |
JoinItem item1 = new JoinItem(); | |
item1.setFileInfo(fileInfo1); | |
item1.setPages(Arrays.asList(3, 6, 8)); | |
FileInfo fileInfo2 = new FileInfo(); | |
fileInfo2.setFilePath("WordProcessing/four-pages.docx"); | |
JoinItem item2 = new JoinItem(); | |
item2.setFileInfo(fileInfo2); | |
item2.setStartPageNumber(1); | |
item2.setEndPageNumber(4); | |
item2.setRangeMode(JoinItem.RangeModeEnum.ODDPAGES); | |
JoinOptions options = new JoinOptions(); | |
options.setJoinItems(Arrays.asList(item1, item2)); | |
options.setOutputPath("output/joined-pages.docx"); | |
JoinRequest request = new JoinRequest(options); | |
DocumentResult response = apiInstance.join(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Files; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Move_File { | |
public static void main(String[] args) { | |
FileApi apiInstance = new FileApi(Utils.AppSID, Utils.AppKey); | |
try { | |
MoveFileRequest request = new MoveFileRequest("WordProcessing\\one-page.docx", "WordProcessing\\one-page1.docx", | |
Utils.MYStorage, Utils.MYStorage, null); | |
apiInstance.moveFile(request); | |
System.out.println( | |
"Expected response type is Void: 'WordProcessing/one-page.docx' file moved to 'WordProcessing1/one-page1.docx'."); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FileApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Folder; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Move_Folder { | |
public static void main(String[] args) { | |
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey); | |
try { | |
MoveFolderRequest request = new MoveFolderRequest("Mergers1", "Mergers\\Mergers1", | |
Utils.MYStorage, Utils.MYStorage); | |
apiInstance.moveFolder(request); | |
System.out.println( | |
"Expected response type is Void: 'Mergers1' folder moved to 'Mergers/Mergers1'."); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FolderApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.PagesOperations; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to move document page to a new position. | |
*/ | |
public class Merger_Java_MovePage { | |
public static void main(String[] args) { | |
PagesApi apiInstance = new PagesApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/four-pages.docx"); | |
MoveOptions options = new MoveOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/move-pages.docx"); | |
options.setPageNumber(1); | |
options.setNewPageNumber(2); | |
MoveRequest request = new MoveRequest(options); | |
DocumentResult response = apiInstance.move(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Storage; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.*; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Object_Exists { | |
public static void main(String[] args) { | |
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey); | |
try { | |
ObjectExistsRequest request = new ObjectExistsRequest("Mergers\\one-page.docx", Utils.MYStorage, null); | |
ObjectExist response = apiInstance.objectExists(request); | |
System.out.println("Expected response type is ObjectExist: " + response.getExists()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling StorageApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.DocumentOperations; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to generate document pages preview. | |
*/ | |
public class Merger_Java_PreviewDocument { | |
public static void main(String[] args) { | |
DocumentApi apiInstance = new DocumentApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/four-pages.docx"); | |
PreviewOptions options = new PreviewOptions(); | |
options.setFileInfo(fileInfo); | |
options.setPages(Arrays.asList(1, 3)); | |
options.setOutputPath("output/preview-page"); | |
options.setFormat(PreviewOptions.FormatEnum.PNG); | |
PreviewRequest request = new PreviewRequest(options); | |
MultiDocumentResult response = apiInstance.preview(request); | |
for (DocumentResult documentResult : response.getDocuments()) { | |
System.err.println("Output file path: " + documentResult.getPath()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.SecurityOperations; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to remove document password. | |
*/ | |
public class Merger_Java_RemoveDocumentPassword { | |
public static void main(String[] args) { | |
SecurityApi apiInstance = new SecurityApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/password-protected.docx"); | |
fileInfo.setPassword("password"); | |
Options options = new Options(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/remove-password.docx"); | |
RemovePasswordRequest request = new RemovePasswordRequest(options); | |
DocumentResult response = apiInstance.removePassword(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.PagesOperations; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to remove document pages. | |
*/ | |
public class Merger_Java_RemovePages { | |
public static void main(String[] args) { | |
PagesApi apiInstance = new PagesApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/four-pages.docx"); | |
RemoveOptions options = new RemoveOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/remove-pages.docx"); | |
options.setPages(Arrays.asList(2, 4)); | |
RemoveRequest request = new RemoveRequest(options); | |
DocumentResult response = apiInstance.remove(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.PagesOperations; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to rotate document pages. | |
*/ | |
public class Merger_Java_RotatePages { | |
public static void main(String[] args) { | |
PagesApi apiInstance = new PagesApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("Pdf/ten-pages.pdf"); | |
RotateOptions options = new RotateOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/rotate-pages.pdf"); | |
options.setPages(Arrays.asList(2, 4)); | |
options.setMode(RotateOptions.ModeEnum.ROTATE90); | |
RotateRequest request = new RotateRequest(options); | |
DocumentResult response = apiInstance.rotate(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples; | |
import examples.DocumentOperations.JoinMultipleDocuments; | |
import examples.DocumentOperations.JoinPagesFromVariousDocuments; | |
import examples.DocumentOperations.PreviewDocument; | |
import examples.DocumentOperations.SplitDocument.SplitToMultiPageDocuments; | |
import examples.DocumentOperations.SplitDocument.SplitToSinglePages; | |
import examples.DocumentOperations.SplitDocument.SplitToSinglePagesByRange; | |
import examples.DocumentOperations.SplitDocument.SplitToSinglePagesByRangeWithFilter; | |
import examples.PagesOperations.ChangePageOrientation; | |
import examples.PagesOperations.MovePage; | |
import examples.PagesOperations.RemovePages; | |
import examples.PagesOperations.RotatePages; | |
import examples.PagesOperations.SwapPages; | |
import examples.PagesOperations.ExtractPages.ExtractPagesByNumbers; | |
import examples.PagesOperations.ExtractPages.ExtractPagesByRange; | |
import examples.SecurityOperations.AddDocumentPassword; | |
import examples.SecurityOperations.CheckDocumentPasswordProtection; | |
import examples.SecurityOperations.RemoveDocumentPassword; | |
import examples.SecurityOperations.UpdateDocumentPassword; | |
public class RunExamples { | |
public static void main(String[] args) { | |
// Upload files | |
UploadResoruces.main(args); | |
// Info API examples | |
Merger_Java_GetSupportedFileTypes.main(args); | |
Merger_Java_GetDocumentInformation.main(args); | |
// Document API examples | |
Merger_Java_JoinMultipleDocuments.main(args); | |
Merger_Java_JoinPagesFromVariousDocuments.main(args); | |
Merger_Java_PreviewDocument.main(args); | |
Merger_Java_SplitToMultiPageDocuments.main(args); | |
Merger_Java_SplitToSinglePages.main(args); | |
Merger_Java_SplitToSinglePagesByRange.main(args); | |
Merger_Java_SplitToSinglePagesByRangeWithFilter.main(args); | |
// Pages API examples | |
Merger_Java_ChangePageOrientation.main(args); | |
Merger_Java_MovePage.main(args); | |
Merger_Java_RemovePages.main(args); | |
Merger_Java_RotatePages.main(args); | |
Merger_Java_SwapPages.main(args); | |
Merger_Java_ExtractPagesByNumbers.main(args); | |
Merger_Java_ExtractPagesByRange.main(args); | |
// Security API examples | |
Merger_Java_CheckDocumentPasswordProtection.main(args); | |
Merger_Java_AddDocumentPassword.main(args); | |
Merger_Java_UpdateDocumentPassword.main(args); | |
Merger_Java_RemoveDocumentPassword.main(args); | |
System.out.println("Completed"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.DocumentOperations.SplitDocument; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to split the document to several multi-page documents by specified page ranges. | |
*/ | |
public class Merger_Java_SplitToMultiPageDocuments { | |
public static void main(String[] args) { | |
DocumentApi apiInstance = new DocumentApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/sample-10-pages.docx"); | |
SplitOptions options = new SplitOptions(); | |
options.setFileInfo(fileInfo); | |
options.setPages(Arrays.asList(3, 6, 8)); | |
options.setOutputPath("output/split-to-multipage-document"); | |
options.setMode(SplitOptions.ModeEnum.INTERVALS); | |
SplitRequest request = new SplitRequest(options); | |
MultiDocumentResult response = apiInstance.split(request); | |
for (DocumentResult documentResult : response.getDocuments()) { | |
System.err.println("Output file path: " + documentResult.getPath()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.DocumentOperations.SplitDocument; | |
import java.util.Arrays; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to split the document to several one-page documents (by exact page numbers). | |
*/ | |
public class Merger_Java_SplitToSinglePages { | |
public static void main(String[] args) { | |
DocumentApi apiInstance = new DocumentApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/sample-10-pages.docx"); | |
SplitOptions options = new SplitOptions(); | |
options.setFileInfo(fileInfo); | |
options.setPages(Arrays.asList(1, 3)); | |
options.setOutputPath("output/split-document"); | |
options.setMode(SplitOptions.ModeEnum.PAGES); | |
SplitRequest request = new SplitRequest(options); | |
MultiDocumentResult response = apiInstance.split(request); | |
for (DocumentResult documentResult : response.getDocuments()) { | |
System.err.println("Output file path: " + documentResult.getPath()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.DocumentOperations.SplitDocument; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to split the document to several one-page documents (by start/end page numbers). | |
*/ | |
public class Merger_Java_SplitToSinglePagesByRange { | |
public static void main(String[] args) { | |
DocumentApi apiInstance = new DocumentApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/sample-10-pages.docx"); | |
SplitOptions options = new SplitOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/split-by-start-end-numbers"); | |
options.setStartPageNumber(3); | |
options.setEndPageNumber(7); | |
options.setMode(SplitOptions.ModeEnum.PAGES); | |
SplitRequest request = new SplitRequest(options); | |
MultiDocumentResult response = apiInstance.split(request); | |
for (DocumentResult documentResult : response.getDocuments()) { | |
System.err.println("Output file path: " + documentResult.getPath()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.DocumentOperations.SplitDocument; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to split the document to several one-page documents (by start/end page numbers and even/odd filter). | |
*/ | |
public class Merger_Java_SplitToSinglePagesByRangeWithFilter { | |
public static void main(String[] args) { | |
DocumentApi apiInstance = new DocumentApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/sample-10-pages.docx"); | |
SplitOptions options = new SplitOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/split-by-start-end-numbers-with-filter"); | |
options.setStartPageNumber(3); | |
options.setEndPageNumber(7); | |
options.setRangeMode(PageOptions.RangeModeEnum.ODDPAGES); | |
options.setMode(SplitOptions.ModeEnum.PAGES); | |
SplitRequest request = new SplitRequest(options); | |
MultiDocumentResult response = apiInstance.split(request); | |
for (DocumentResult documentResult : response.getDocuments()) { | |
System.err.println("Output file path: " + documentResult.getPath()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Storage; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.*; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Storage_Exist { | |
public static void main(String[] args) { | |
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey); | |
try { | |
StorageExistsRequest request = new StorageExistsRequest(Utils.MYStorage); | |
StorageExist response = apiInstance.storageExists(request); | |
System.out.println("Expected response type is StorageExist: " + response.getExists()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling StorageApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.PagesOperations; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to swap document pages. | |
*/ | |
public class Merger_Java_SwapPages { | |
public static void main(String[] args) { | |
PagesApi apiInstance = new PagesApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/four-pages.docx"); | |
SwapOptions options = new SwapOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/swap-pages.docx"); | |
options.setFirstPageNumber(2); | |
options.setSecondPageNumber(4); | |
SwapRequest request = new SwapRequest(options); | |
DocumentResult response = apiInstance.swap(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.SecurityOperations; | |
import com.groupdocs.cloud.merger.client.*; | |
import com.groupdocs.cloud.merger.model.*; | |
import com.groupdocs.cloud.merger.model.requests.*; | |
import com.groupdocs.cloud.merger.api.*; | |
import examples.Utils; | |
/** | |
* This example demonstrates how to update document password. | |
*/ | |
public class Merger_Java_UpdateDocumentPassword { | |
public static void main(String[] args) { | |
SecurityApi apiInstance = new SecurityApi(Utils.GetConfiguration()); | |
try { | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("WordProcessing/password-protected.docx"); | |
fileInfo.setPassword("password"); | |
UpdatePasswordOptions options = new UpdatePasswordOptions(); | |
options.setFileInfo(fileInfo); | |
options.setOutputPath("output/update-password.docx"); | |
options.setNewPassword("newPassword"); | |
UpdatePasswordRequest request = new UpdatePasswordRequest(options); | |
DocumentResult response = apiInstance.updatePassword(request); | |
System.err.println("Output file path: " + response.getPath()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling api:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.Working_With_Files; | |
import java.io.File; | |
import java.nio.file.Paths; | |
import com.groupdocs.cloud.Merger.api.*; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.*; | |
import com.groupdocs.cloud.Merger.model.requests.*; | |
import examples.Utils; | |
public class Merger_Java_Upload_File { | |
public static void main(String[] args) { | |
FileApi apiInstance = new FileApi(Utils.AppSID, Utils.AppKey); | |
try { | |
File fileStream = new File( | |
Paths.get("src\\main\\resources").toAbsolutePath().toString() + "\\WordProcessing\\one-page.docx"); | |
UploadFileRequest request = new UploadFileRequest("WordProcessing\\one-page.docx", fileStream, | |
Utils.MYStorage); | |
FilesUploadResult response = apiInstance.uploadFile(request); | |
System.out.println("Expected response type is FilesUploadResult: " + response.getUploaded().size()); | |
} catch (ApiException e) { | |
System.err.println("Exception while calling FileApi:"); | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples; | |
import java.io.File; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import com.groupdocs.cloud.merger.api.FileApi; | |
import com.groupdocs.cloud.merger.client.ApiException; | |
import com.groupdocs.cloud.merger.model.requests.*;; | |
public class UploadResoruces { | |
public static FileApi fileApi = new FileApi(Utils.GetConfiguration()); | |
public static String resourcesPath = Paths.get("examples\\src\\main\\resources").toAbsolutePath().toString(); | |
public static void main(String[] args) { | |
try { | |
System.out.println("File Upload Processing: "+ resourcesPath); | |
uploadFiles(resourcesPath); | |
System.out.println("File Upload Process End"); | |
} catch (ApiException e) { | |
System.err.println("Exception while file uploading:"); | |
e.printStackTrace(); | |
} | |
} | |
public static void uploadFiles(String path) throws ApiException { | |
File directory = new File(path); | |
File[] files = directory.listFiles(); | |
for (File file : files) { | |
String relativePath = getRelativePath(file.getAbsolutePath(), resourcesPath); | |
if (file.isFile()) { | |
uploadFile(file, relativePath); | |
} else if (file.isDirectory()) { | |
uploadFiles(file.getAbsolutePath().toString()); | |
} | |
} | |
} | |
public static String getRelativePath(String absolutePath, String basePath) { | |
Path absolute = Paths.get(absolutePath); | |
Path base = Paths.get(basePath); | |
Path relative = base.relativize(absolute); | |
return relative.toString(); | |
} | |
public static void uploadFile(File file, String relativePath) throws ApiException { | |
String filePath = relativePath.replace("\\", "/"); | |
System.out.println("Uploading File: " + filePath); | |
UploadFileRequest request = new UploadFileRequest(filePath, file, Utils.MYStorage); | |
fileApi.uploadFileWithHttpInfo(request); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples; | |
import com.groupdocs.cloud.Merger.api.FolderApi; | |
import com.groupdocs.cloud.Merger.client.ApiException; | |
import com.groupdocs.cloud.Merger.model.FilesList; | |
import com.groupdocs.cloud.Merger.model.StorageFile; | |
import com.groupdocs.cloud.Merger.model.requests.GetFilesListRequest; | |
public class Utils { | |
// TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud (free | |
// registration is required). | |
public static String AppSID = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"; | |
public static String AppKey = "XXXXXXXXXXXXXXXXXXXX"; | |
public static String MYStorage = "XXXXX"; | |
public static void getFolderFilesPath(String path) { | |
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey); | |
try { | |
GetFilesListRequest request = new GetFilesListRequest(path, Utils.MYStorage); | |
FilesList response = apiInstance.getFilesList(request); | |
for (StorageFile storageFile : response.getValue()) { | |
System.out.println("Files: " + storageFile.getPath()); | |
} | |
} catch (ApiException e) { | |
System.err.println("Exception while calling getFolderFilesPath with FolderApi:"); | |
e.printStackTrace(); | |
} | |
} | |
public static Configuration GetConfiguration() | |
{ | |
Configuration cfg = new Configuration(Utils.AppSID, Utils.AppKey); | |
cfg.setTimeout(60000); | |
return cfg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment