Skip to content

Instantly share code, notes, and snippets.

@groupdocscloud
Last active December 9, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocscloud/cb5b0d1ae842f50f90382640823a2004 to your computer and use it in GitHub Desktop.
Save groupdocscloud/cb5b0d1ae842f50f90382640823a2004 to your computer and use it in GitHub Desktop.
Editor-Java-v2
package examples.Working_With_Files;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_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: 'Editors/one-page1.docx' file copied as 'Editors/one-page-copied.docx'.");
} catch (ApiException e) {
System.err.println("Exception while calling FileApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Folder;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_Java_Copy_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
CopyFolderRequest request = new CopyFolderRequest("Editors", "Editors1", Utils.MYStorage,
Utils.MYStorage);
apiInstance.copyFolder(request);
System.out.println("Expected response type is Void: 'Editors' folder copied as 'Editors1'.");
} catch (ApiException e) {
System.err.println("Exception while calling FolderApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Folder;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_Java_Create_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
CreateFolderRequest request = new CreateFolderRequest("Editors", Utils.MYStorage);
apiInstance.createFolder(request);
System.out.println("Expected response type is Void: 'Editors' folder created.");
} catch (ApiException e) {
System.err.println("Exception while calling FolderApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Files;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_Java_Delete_File {
public static void main(String[] args) {
FileApi apiInstance = new FileApi(Utils.AppSID, Utils.AppKey);
try {
DeleteFileRequest request = new DeleteFileRequest("Editors1\\one-page1.docx", Utils.MYStorage, null);
apiInstance.deleteFile(request);
System.out.println("Expected response type is Void: 'Editors1/one-page1.docx' deleted.");
} catch (ApiException e) {
System.err.println("Exception while calling FileApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Folder;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_Java_Delete_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
DeleteFolderRequest request = new DeleteFolderRequest("Editors\\Editors1", Utils.MYStorage, true);
apiInstance.deleteFolder(request);
System.out
.println("Expected response type is Void: 'Editors/Editors1' folder deleted recusrsively.");
} catch (ApiException e) {
System.err.println("Exception while calling FolderApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Files;
import java.io.File;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_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();
}
}
}
package examples.Working_With_Storage;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.*;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_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();
}
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-java-samples
String MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
String MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
InfoApi apiInstance = new InfoApi(configuration);
FormatsResult response = apiInstance.getSupportedFileFormats();
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-java-samples
String MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
String MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
InfoApi apiInstance = new InfoApi(configuration);
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("WordProcessing/password-protected.docx");
fileInfo.setPassword("password");
GetInfoRequest request = new GetInfoRequest(fileInfo);
InfoResult response = apiInstance.getInfo(request);
package examples.Working_With_Storage;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.*;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_Java_Get_File_Versions {
public static void main(String[] args) {
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey);
try {
GetFileVersionsRequest request = new GetFileVersionsRequest("Editors\\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();
}
}
}
package examples.Working_With_Folder;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.FilesList;
import com.groupdocs.cloud.Editor.model.*;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_Java_Get_Files_List {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
GetFilesListRequest request = new GetFilesListRequest("Editors", 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();
}
}
}
package examples.Working_With_Files;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_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();
}
}
}
package examples.Working_With_Folder;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_Java_Move_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
MoveFolderRequest request = new MoveFolderRequest("Editors1", "Editors\\Editors1",
Utils.MYStorage, Utils.MYStorage);
apiInstance.moveFolder(request);
System.out.println(
"Expected response type is Void: 'Editors1' folder moved to 'Editors/Editors1'.");
} catch (ApiException e) {
System.err.println("Exception while calling FolderApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Storage;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.*;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Annotation_Java_Object_Exists {
public static void main(String[] args) {
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey);
try {
ObjectExistsRequest request = new ObjectExistsRequest("Editors\\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();
}
}
}
package examples.Working_With_Storage;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.*;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Annotation_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();
}
}
}
package examples.Working_With_Files;
import java.io.File;
import java.nio.file.Paths;
import com.groupdocs.cloud.Editor.api.*;
import com.groupdocs.cloud.Editor.client.ApiException;
import com.groupdocs.cloud.Editor.model.*;
import com.groupdocs.cloud.Editor.model.requests.*;
import examples.Utils;
public class Editor_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();
}
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-java-samples
String MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
String MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
// Create necessary API instances
EditApi editApi = new EditApi(configuration);
FileApi fileApi = new FileApi(configuration);
// The document already uploaded into the storage.
// Load it into editable state
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("Spreadsheet/sample.tsv");
DelimitedTextLoadOptions loadOptions = new DelimitedTextLoadOptions();
loadOptions.setFileInfo(fileInfo);
loadOptions.setOutputPath("output");
LoadResult loadResult = editApi.load(new LoadRequest(loadOptions));
// Download html document
File file = fileApi.downloadFile(new DownloadFileRequest(loadResult.getHtmlPath(), null, null));
// Edit something...
List<String> lines = Files.readAllLines(file.toPath());
List<String> newLines = new ArrayList<String>();
for (String line : lines) {
newLines.add(line.replaceAll("32", "66"));
}
Files.write(file.toPath(), newLines);
// Upload html back to storage
fileApi.uploadFile(new UploadFileRequest(loadResult.getHtmlPath(), file, Common.MYStorage));
// Save html back to tsv
DelimitedTextSaveOptions saveOptions = new DelimitedTextSaveOptions();
saveOptions.setFileInfo(fileInfo);
saveOptions.setOutputPath("output/edited.tsv");
saveOptions.setHtmlPath(loadResult.getHtmlPath());
saveOptions.setResourcesPath(loadResult.getResourcesPath());
DocumentResult saveResult = editApi.save(new SaveRequest(saveOptions));
System.out.println("Document edited: " + saveResult.getPath());
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-java-samples
String MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
String MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
// Create necessary API instances
EditApi editApi = new EditApi(configuration);
FileApi fileApi = new FileApi(configuration);
// The document already uploaded into the storage.
// Load it into editable state
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("Presentation/with-notes.pptx");
PresentationLoadOptions loadOptions = new PresentationLoadOptions();
loadOptions.setFileInfo(fileInfo);
loadOptions.setOutputPath("output");
loadOptions.setSlideNumber(0);
LoadResult loadResult = editApi.load(new LoadRequest(loadOptions));
// Download html document
File file = fileApi.downloadFile(new DownloadFileRequest(loadResult.getHtmlPath(), null, null));
// Edit something...
List<String> lines = Files.readAllLines(file.toPath());
List<String> newLines = new ArrayList<String>();
for (String line : lines) {
newLines.add(line.replaceAll("Slide sub-heading", "Hello world!"));
}
Files.write(file.toPath(), newLines);
// Upload html back to storage
fileApi.uploadFile(new UploadFileRequest(loadResult.getHtmlPath(), file, Common.MYStorage));
// Save html back to pptx
PresentationSaveOptions saveOptions = new PresentationSaveOptions();
saveOptions.setFileInfo(fileInfo);
saveOptions.setOutputPath("output/edited.pptx");
saveOptions.setHtmlPath(loadResult.getHtmlPath());
saveOptions.setResourcesPath(loadResult.getResourcesPath());
DocumentResult saveResult = editApi.save(new SaveRequest(saveOptions));
System.out.println("Document edited: " + saveResult.getPath());
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-java-samples
String MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
String MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
// Create necessary API instances
EditApi editApi = new EditApi(configuration);
FileApi fileApi = new FileApi(configuration);
// The document already uploaded into the storage.
// Load it into editable state
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("Spreadsheet/four-sheets.xlsx");
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setFileInfo(fileInfo);
loadOptions.setOutputPath("output");
LoadResult loadResult = editApi.load(new LoadRequest(loadOptions));
// Download html document
File file = fileApi.downloadFile(new DownloadFileRequest(loadResult.getHtmlPath(), null, null));
// Edit something...
List<String> lines = Files.readAllLines(file.toPath());
List<String> newLines = new ArrayList<String>();
for (String line : lines) {
newLines.add(line.replaceAll("This is sample sheet", "This is sample sheep"));
}
Files.write(file.toPath(), newLines);
// Upload html back to storage
fileApi.uploadFile(new UploadFileRequest(loadResult.getHtmlPath(), file, Common.MYStorage));
// Save html back to xlsx
SpreadsheetSaveOptions saveOptions = new SpreadsheetSaveOptions();
saveOptions.setFileInfo(fileInfo);
saveOptions.setOutputPath("output/edited.xlsx");
saveOptions.setHtmlPath(loadResult.getHtmlPath());
saveOptions.setResourcesPath(loadResult.getResourcesPath());
DocumentResult saveResult = editApi.save(new SaveRequest(saveOptions));
System.out.println("Document edited: " + saveResult.getPath());
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-java-samples
String MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
String MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
// Create necessary API instances
EditApi editApi = new EditApi(configuration);
FileApi fileApi = new FileApi(configuration);
// The document already uploaded into the storage.
// Load it into editable state
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("Text/document.txt");
TextLoadOptions loadOptions = new TextLoadOptions();
loadOptions.setFileInfo(fileInfo);
loadOptions.setOutputPath("output");
LoadResult loadResult = editApi.load(new LoadRequest(loadOptions));
// Download html document
File file = fileApi.downloadFile(new DownloadFileRequest(loadResult.getHtmlPath(), null, null));
// Edit something...
List<String> lines = Files.readAllLines(file.toPath());
List<String> newLines = new ArrayList<String>();
for (String line : lines) {
newLines.add(line.replaceAll("Page Text", "New Text"));
}
Files.write(file.toPath(), newLines);
// Upload html back to storage
fileApi.uploadFile(new UploadFileRequest(loadResult.getHtmlPath(), file, Common.MYStorage));
// Save html back to txt
TextSaveOptions saveOptions = new TextSaveOptions();
saveOptions.setFileInfo(fileInfo);
saveOptions.setOutputPath("output/edited.txt");
saveOptions.setHtmlPath(loadResult.getHtmlPath());
saveOptions.setResourcesPath(loadResult.getResourcesPath());
DocumentResult saveResult = editApi.save(new SaveRequest(saveOptions));
System.out.println("Document edited: " + saveResult.getPath());
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-java-samples
String MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
String MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
// Create necessary API instances
EditApi editApi = new EditApi(configuration);
FileApi fileApi = new FileApi(configuration);
// The document already uploaded into the storage.
// Load it into editable state
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("WordProcessing/password-protected.docx");
fileInfo.setPassword("password");
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
loadOptions.setFileInfo(fileInfo);
loadOptions.setOutputPath("output");
LoadResult loadResult = editApi.load(new LoadRequest(loadOptions));
// Download html document
File file = fileApi.downloadFile(new DownloadFileRequest(loadResult.getHtmlPath(), null, null));
// Edit something...
List<String> lines = Files.readAllLines(file.toPath());
List<String> newLines = new ArrayList<String>();
for (String line : lines) {
newLines.add(line.replaceAll("Sample test text", "Hello world"));
}
Files.write(file.toPath(), newLines);
// Upload html back to storage
fileApi.uploadFile(new UploadFileRequest(loadResult.getHtmlPath(), file, Common.MYStorage));
// Save html back to docx
WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions();
saveOptions.setFileInfo(fileInfo);
saveOptions.setOutputPath("output/edited.docx");
saveOptions.setHtmlPath(loadResult.getHtmlPath());
saveOptions.setResourcesPath(loadResult.getResourcesPath());
DocumentResult saveResult = editApi.save(new SaveRequest(saveOptions));
System.out.println("Document edited: " + saveResult.getPath());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment