Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Watermark-Java
// For complete examples and data files, please go to https://github.com/groupdocs-watermark-cloud/groupdocs-watermark-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);
WatermarkApi apiInstance = new WatermarkApi(configuration);
WatermarkOptions options = new WatermarkOptions();
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/sample.docx");
options.setFileInfo(fileInfo);
WatermarkDetails watermarkDetails = new WatermarkDetails();
ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
FileInfo image = new FileInfo();
image.setFilePath("watermark_images/sample_watermark.png");
imageWatermarkOptions.setImage(image);
watermarkDetails.setImageWatermarkOptions(imageWatermarkOptions);
List<WatermarkDetails> watermarkDetailsList = new ArrayList<WatermarkDetails>();
watermarkDetailsList.add(watermarkDetails);
options.setWatermarkDetails(watermarkDetailsList);
AddRequest request = new AddRequest(options);
WatermarkResult response = apiInstance.add(request);
// For complete examples and data files, please go to https://github.com/groupdocs-parser-cloud/groupdocs-parser-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);
WatermarkApi apiInstance = new WatermarkApi(configuration);
WatermarkOptions options = new WatermarkOptions();
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/sample.docx");
options.setFileInfo(fileInfo);
WatermarkDetails watermarkDetails = new WatermarkDetails();
TextWatermarkOptions textWatermarkOptions = new TextWatermarkOptions();
textWatermarkOptions.setText("New watermark text");
textWatermarkOptions.setFontFamilyName("Arial");
textWatermarkOptions.setFontSize(12d);
watermarkDetails.setTextWatermarkOptions(textWatermarkOptions);
List<WatermarkDetails> watermarkDetailsList = new ArrayList<WatermarkDetails>();
watermarkDetailsList.add(watermarkDetails);
options.setWatermarkDetails(watermarkDetailsList);
AddRequest request = new AddRequest(options);
WatermarkResult response = apiInstance.add(request);
package examples.Working_With_Files;
import com.groupdocs.cloud.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_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: 'Watermarws/one-page1.docx' file copied as 'Watermarws/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.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Copy_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
CopyFolderRequest request = new CopyFolderRequest("Watermarws", "Watermarws1", Utils.MYStorage,
Utils.MYStorage);
apiInstance.copyFolder(request);
System.out.println("Expected response type is Void: 'Watermarws' folder copied as 'Watermarws1'.");
} catch (ApiException e) {
System.err.println("Exception while calling FolderApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Folder;
import com.groupdocs.cloud.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Create_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
CreateFolderRequest request = new CreateFolderRequest("Watermarws", Utils.MYStorage);
apiInstance.createFolder(request);
System.out.println("Expected response type is Void: 'Watermarws' folder created.");
} catch (ApiException e) {
System.err.println("Exception while calling FolderApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Files;
import com.groupdocs.cloud.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Delete_File {
public static void main(String[] args) {
FileApi apiInstance = new FileApi(Utils.AppSID, Utils.AppKey);
try {
DeleteFileRequest request = new DeleteFileRequest("Watermarws1\\one-page1.docx", Utils.MYStorage, null);
apiInstance.deleteFile(request);
System.out.println("Expected response type is Void: 'Watermarws1/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.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Delete_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
DeleteFolderRequest request = new DeleteFolderRequest("Watermarws\\Watermarws1", Utils.MYStorage, true);
apiInstance.deleteFolder(request);
System.out
.println("Expected response type is Void: 'Watermarws/Watermarws1' 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.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_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();
}
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-watermark-cloud/groupdocs-watermark-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();
package examples.Working_With_Storage;
import com.groupdocs.cloud.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.*;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_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-watermark-cloud/groupdocs-watermark-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("documents/password-protected.docx");
fileInfo.setPassword("password");
InfoOptions options = new InfoOptions();
options.setFileInfo(fileInfo);
GetInfoRequest request = new GetInfoRequest(options);
InfoResult response = apiInstance.getInfo(request);
package examples.Working_With_Storage;
import com.groupdocs.cloud.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.*;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Get_File_Versions {
public static void main(String[] args) {
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey);
try {
GetFileVersionsRequest request = new GetFileVersionsRequest("Watermarws\\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.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.FilesList;
import com.groupdocs.cloud.Watermarw.model.*;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Get_Files_List {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
GetFilesListRequest request = new GetFilesListRequest("Watermarws", 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.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_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.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Move_Folder {
public static void main(String[] args) {
FolderApi apiInstance = new FolderApi(Utils.AppSID, Utils.AppKey);
try {
MoveFolderRequest request = new MoveFolderRequest("Watermarws1", "Watermarws\\Watermarws1",
Utils.MYStorage, Utils.MYStorage);
apiInstance.moveFolder(request);
System.out.println(
"Expected response type is Void: 'Watermarws1' folder moved to 'Watermarws/Watermarws1'.");
} catch (ApiException e) {
System.err.println("Exception while calling FolderApi:");
e.printStackTrace();
}
}
}
package examples.Working_With_Storage;
import com.groupdocs.cloud.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.*;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_Java_Object_Exists {
public static void main(String[] args) {
StorageApi apiInstance = new StorageApi(Utils.AppSID, Utils.AppKey);
try {
ObjectExistsRequest request = new ObjectExistsRequest("Watermarws\\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();
}
}
}
// For complete examples and data files, please go to https://github.com/groupdocs-watermark-cloud/groupdocs-watermark-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);
WatermarkApi apiInstance = new WatermarkApi(configuration);
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("with_watermarks/sample.pdf");
RemoveOptions options = new RemoveOptions();
options.setFileInfo(fileInfo);
ImageSearchCriteria imageSearchCriteria = new ImageSearchCriteria();
FileInfo imageFileInfo = new FileInfo();
imageFileInfo.setFilePath("watermark_images/sample_watermark.png");
imageSearchCriteria.setImageFileInfo(imageFileInfo);
options.setImageSearchCriteria(imageSearchCriteria);
TextSearchCriteria textSearchCriteria = new TextSearchCriteria();
textSearchCriteria.setSearchText("Watermark text");
options.setTextSearchCriteria(textSearchCriteria);
options.setOutputFolder("removed_watermarks");
RemoveRequest request = new RemoveRequest(options);
RemoveResult response = apiInstance.remove(request);
// For complete examples and data files, please go to https://github.com/groupdocs-watermark-cloud/groupdocs-watermark-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);
WatermarkApi apiInstance = new WatermarkApi(configuration);
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("with_watermarks/sample.pdf");
ReplaceOptions options = new ReplaceOptions();
options.setFileInfo(fileInfo);
ImageSearchCriteria imageSearchCriteria = new ImageSearchCriteria();
FileInfo imageFileInfo = new FileInfo();
imageFileInfo.setFilePath("watermark_images/sample_watermark.png");
imageSearchCriteria.setImageFileInfo(imageFileInfo);
options.setImageSearchCriteria(imageSearchCriteria);
TextSearchCriteria textSearchCriteria = new TextSearchCriteria();
textSearchCriteria.setSearchText("Watermark text");
options.setTextSearchCriteria(textSearchCriteria);
ReplaceTextOptions replaceTextOptions = new ReplaceTextOptions();
replaceTextOptions.setText("New watermark text");
options.setReplaceTextOptions(replaceTextOptions);
ReplaceImageOptions replaceImageOptions = new ReplaceImageOptions();
FileInfo replaceImageFileInfo = new FileInfo();
replaceImageFileInfo.setFilePath("images/sample.jpg");
replaceImageOptions.setImage(replaceImageFileInfo);
options.setReplaceImageOptions(replaceImageOptions);
options.setOutputFolder("found_image_watermarks");
ReplaceRequest request = new ReplaceRequest(options);
ReplaceResult response = apiInstance.replace(request);
// For complete examples and data files, please go to https://github.com/groupdocs-watermark-cloud/groupdocs-watermark-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);
WatermarkApi apiInstance = new WatermarkApi(configuration);
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("with_watermarks/sample.pdf");
SearchOptions options = new SearchOptions();
options.setFileInfo(fileInfo);
ImageSearchCriteria imageSearchCriteria = new ImageSearchCriteria();
FileInfo imageFileInfo = new FileInfo();
imageFileInfo.setFilePath("watermark_images/sample_watermark.png");
imageSearchCriteria.setImageFileInfo(imageFileInfo);
options.setImageSearchCriteria(imageSearchCriteria);
TextSearchCriteria textSearchCriteria = new TextSearchCriteria();
textSearchCriteria.setSearchText("Watermark text");
options.setTextSearchCriteria(textSearchCriteria);
options.setOutputFolder("found_image_watermarks");
SearchRequest request = new SearchRequest(options);
SearchResult response = apiInstance.search(request);
package examples.Working_With_Storage;
import com.groupdocs.cloud.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.*;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_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.Watermarw.api.*;
import com.groupdocs.cloud.Watermarw.client.ApiException;
import com.groupdocs.cloud.Watermarw.model.*;
import com.groupdocs.cloud.Watermarw.model.requests.*;
import examples.Utils;
public class Watermarw_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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.