Skip to content

Commit 677afcd

Browse files
authored
Merge pull request #137 from aspose-pdf-cloud/develop
update to 25.9
2 parents e6b23f6 + 919f730 commit 677afcd

40 files changed

+1386
-9
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ XLS, XLSX, PPTX, DOC, DOCX, MobiXML, JPEG, EMF, PNG, BMP, GIF, TIFF, Text
2929
## Read PDF Formats
3030
MHT, PCL, PS, XSLFO, MD
3131

32-
## Enhancements in Version 25.8
33-
- Implement document page resize functionality using the Pdf.Cloud API library.
32+
## Enhancements in Version 25.9
33+
- Implement PDF document page crop functionality using the Pdf.Cloud API library.
3434
- A new version of Aspose.PDF Cloud was prepared using the latest version of Aspose.PDF for .NET.
3535

36-
## Bugs fixed in Version 25.8
37-
- Implement delete watermark from PDF document using the Pdf.Cloud API library.
38-
3936
## Unit Tests
4037
Aspose PDF SDK includes a suite of unit tests. These Unit Tests also serves as examples of how to use the Aspose PDF SDK.
4138

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
using EncryptDecrypt;
3+
4+
namespace EnryptDecrypt
5+
{
6+
public class DecryptPdf
7+
{
8+
public static async Task Decrypt(EncryptDecryptHelper helper, string documentName, string outputName, string remoteFolder)
9+
{
10+
await helper.UploadFile(documentName);
11+
12+
string ownerPassword = "Owner-Password";
13+
14+
AsposeResponse response = await helper.pdfApi.PostDecryptDocumentInStorageAsync(
15+
documentName,
16+
helper.ToBase64(ownerPassword),
17+
folder: remoteFolder);
18+
19+
if (response == null)
20+
Console.WriteLine("DecryptPdf(): Unexpected error!");
21+
else if (response.Code < 200 || response.Code > 299)
22+
Console.WriteLine("DecryptPdf(): Failed to decrypt document.");
23+
else
24+
{
25+
Console.WriteLine("DecryptPdf(): document '{0} successfully decrypted.", documentName);
26+
await helper.DownloadFile(documentName, outputName, "decrypt_");
27+
}
28+
}
29+
}
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\src\Aspose.Pdf.Cloud.Sdk\Aspose.Pdf.Cloud.Sdk.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using Aspose.Pdf.Cloud.Sdk.Api;
2+
using Aspose.Pdf.Cloud.Sdk.Model;
3+
using Newtonsoft.Json;
4+
using System.Text;
5+
6+
namespace EncryptDecrypt
7+
{
8+
public class ConfigParams
9+
{
10+
public string CrdentialPath { get; } = "..\\credentials.json";
11+
public string LOCAL_FOLDER { get; } = "C:\\Samples";
12+
public string REMOTE_TEMP_FOLDER { get; } = "TempPdfCloud";
13+
public string PDF_DOCUMENT { get; } = "sample.pdf";
14+
public string PDF_DOCUMENT_ENCRYPTED { get; } = "sample_encrypted.pdf";
15+
16+
public string PDF_OUTPUT { get; } = "output_sample.pdf";
17+
}
18+
19+
public class Credentials
20+
{
21+
public string Id { get; set; }
22+
public string Key { get; set; }
23+
}
24+
25+
public class EncryptDecryptHelper
26+
{
27+
public PdfApi pdfApi { get; private set; }
28+
public ConfigParams config { get; private set; }
29+
30+
public EncryptDecryptHelper()
31+
{
32+
config = new ConfigParams();
33+
string jsCredText = File.ReadAllText(config.CrdentialPath);
34+
Credentials cred = JsonConvert.DeserializeObject<Credentials>(jsCredText);
35+
pdfApi = new PdfApi(cred.Key, cred.Id);
36+
}
37+
38+
public async Task UploadFile(string fileName)
39+
{
40+
using (var file = File.OpenRead(Path.Combine(config.LOCAL_FOLDER, fileName)))
41+
{
42+
FilesUploadResult response = await pdfApi.UploadFileAsync(Path.Combine(config.REMOTE_TEMP_FOLDER, fileName), file);
43+
if (response == null)
44+
Console.WriteLine("UploadFile(): Unexpected error - no response!");
45+
else if (response.Errors != null && response.Errors.Count > 0)
46+
foreach (var error in response.Errors)
47+
Console.WriteLine("UploadFile(): {0} -> {1}", [error.Code, error.Message]);
48+
else
49+
Console.WriteLine("UploadFile(): File '{0}' successfully uploaded.", fileName);
50+
}
51+
}
52+
53+
public async Task DownloadFile(string fileName, string outputName, string outputPrefix)
54+
{
55+
Stream stream = pdfApi.DownloadFile(Path.Combine(config.REMOTE_TEMP_FOLDER, fileName));
56+
using var fileStream = File.Create(Path.Combine(config.LOCAL_FOLDER, outputPrefix + outputName));
57+
stream.Position = 0;
58+
await stream.CopyToAsync(fileStream);
59+
Console.WriteLine("DownloadFile(): File '{0}' successfully downloaded.", outputPrefix + outputName);
60+
}
61+
62+
public string ToBase64(string str)
63+
{
64+
var bytes = Encoding.UTF8.GetBytes(str);
65+
return Convert.ToBase64String(bytes);
66+
}
67+
}
68+
69+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
3+
namespace EncryptDecrypt
4+
{
5+
public class EncryptPdf
6+
{
7+
public static async Task Encrypt(EncryptDecryptHelper helper, string documentName, string outputName, string remoteFolder)
8+
{
9+
await helper.UploadFile(documentName);
10+
11+
string userPassword = "User-Password";
12+
string ownerPassword = "Owner-Password";
13+
14+
AsposeResponse response = await helper.pdfApi.PostEncryptDocumentInStorageAsync(
15+
documentName,
16+
helper.ToBase64(userPassword),
17+
helper.ToBase64(ownerPassword),
18+
CryptoAlgorithm.AESx256.ToString(),
19+
folder: remoteFolder);
20+
21+
if (response == null)
22+
Console.WriteLine("EncryptPdf(): Unexpected error!");
23+
else if (response.Code < 200 || response.Code > 299)
24+
Console.WriteLine("EncryptPdf(): Failed to encrypt document.");
25+
else
26+
{
27+
Console.WriteLine("EncryptPdf(): document '{0} successfully encrypted.", documentName);
28+
await helper.DownloadFile(documentName, outputName, "encrypt_");
29+
}
30+
}
31+
}
32+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
using EncryptDecrypt;
3+
4+
namespace EnryptDecrypt
5+
{
6+
public class PasswordModify
7+
{
8+
public static async Task Change(EncryptDecryptHelper helper, string documentName, string outputName, string remoteFolder)
9+
{
10+
await helper.UploadFile(documentName);
11+
12+
string ownerPassword = "Owner-Password";
13+
14+
string newOwnerPassword = "NEW-Owner-Password";
15+
string newUserPassword = "NEW-User-Password";
16+
17+
AsposeResponse response = await helper.pdfApi.PostChangePasswordDocumentInStorageAsync(
18+
documentName,
19+
helper.ToBase64(ownerPassword),
20+
helper.ToBase64(newUserPassword),
21+
helper.ToBase64(newOwnerPassword),
22+
folder: remoteFolder);
23+
24+
if (response == null)
25+
Console.WriteLine("PasswordModify(): Unexpected error!");
26+
else if (response.Code < 200 || response.Code > 299)
27+
Console.WriteLine("PasswordModify(): Failed to change password in document.");
28+
else
29+
{
30+
Console.WriteLine("PasswordModify(): password in document '{0} successfully changed.", documentName);
31+
await helper.DownloadFile(documentName, outputName, "password_modify_");
32+
}
33+
}
34+
}
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using EncryptDecrypt;
2+
using EnryptDecrypt;
3+
4+
EncryptDecryptHelper helper = new EncryptDecryptHelper();
5+
ConfigParams config = helper.config;
6+
7+
await EncryptPdf.Encrypt(helper, config.PDF_DOCUMENT, config.PDF_OUTPUT, config.REMOTE_TEMP_FOLDER);
8+
9+
await DecryptPdf.Decrypt(helper, config.PDF_DOCUMENT_ENCRYPTED, config.PDF_OUTPUT, config.REMOTE_TEMP_FOLDER);
10+
11+
await PasswordModify.Change(helper, config.PDF_DOCUMENT_ENCRYPTED, config.PDF_OUTPUT, config.REMOTE_TEMP_FOLDER);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
3+
namespace Parser
4+
{
5+
public class ExportFormToFdf
6+
{
7+
public static async Task Extract(ParserHelper helper, string documentName, string outputFdfName, string remoteFolder)
8+
{
9+
await helper.UploadFile(documentName);
10+
11+
string fdfPath = Path.Combine(remoteFolder, outputFdfName);
12+
13+
AsposeResponse response = await helper.pdfApi.PutExportFieldsFromPdfToFdfInStorageAsync(documentName, fdfPath, folder: remoteFolder);
14+
15+
if (response == null)
16+
Console.WriteLine("ExportFormToFdf(): Unexpected error!");
17+
else if (response.Code < 200 || response.Code > 299)
18+
Console.WriteLine("ExportFormToFdf(): Failed to export Pdf document form fields.");
19+
else
20+
{
21+
Console.WriteLine("ExportFormToFdf(): Pdf document '{0}' form fields successfully exported to '{1} file.", documentName, outputFdfName);
22+
await helper.DownloadFile(outputFdfName, outputFdfName, string.Empty);
23+
}
24+
}
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
namespace Parser
3+
{
4+
public class ExportFormToXML
5+
{
6+
public static async Task Extract(ParserHelper helper, string documentName, string outputXMLName, string remoteFolder)
7+
{
8+
await helper.UploadFile(documentName);
9+
10+
string xmlPath = Path.Combine(remoteFolder, outputXMLName);
11+
12+
AsposeResponse response = await helper.pdfApi.PutExportFieldsFromPdfToXmlInStorageAsync(documentName, xmlPath, folder: remoteFolder);
13+
14+
if (response == null)
15+
Console.WriteLine("ExportFormToXML(): Unexpected error!");
16+
else if (response.Code < 200 || response.Code > 299)
17+
Console.WriteLine("ExportFormToXML(): Failed to export Pdf document form fields.");
18+
else
19+
{
20+
Console.WriteLine("ExportFormToXML(): Pdf document '{0}' form fields successfully exported to '{1} file.", documentName, outputXMLName);
21+
await helper.DownloadFile(outputXMLName, outputXMLName, string.Empty);
22+
}
23+
}
24+
}
25+
}

Uses-Cases/Parser/GetImages.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
using Newtonsoft.Json;
3+
4+
namespace Parser
5+
{
6+
public class GetImages
7+
{
8+
public static async Task Extract(ParserHelper helper, string documentName, int pageNumber, string localFolder, string remoteFolder)
9+
{
10+
await helper.UploadFile(documentName);
11+
12+
ImagesResponse response = await helper.pdfApi.GetImagesAsync(documentName, pageNumber, folder: remoteFolder);
13+
14+
if (response == null)
15+
Console.WriteLine("GetImages(): Unexpected error!");
16+
else if (response.Code < 200 || response.Code > 299)
17+
Console.WriteLine("GetImages(): Failed to receive Images from '{0}' page of the document.", pageNumber);
18+
else if (response.Images == null || response.Images.List == null || response.Images.List.Count == 0)
19+
Console.WriteLine("GetImages(): Images not found in the document '{0]'.", documentName);
20+
else
21+
{
22+
Console.WriteLine("GetImages(): Images successfully received from the document '{0}.", documentName);
23+
foreach (var image in response.Images.List)
24+
{
25+
using (var respImage = await helper.pdfApi.GetImageExtractAsPngAsync(documentName, image.Id, folder: remoteFolder))
26+
{
27+
Console.WriteLine(image.ToString());
28+
29+
string fileName = Path.Combine(localFolder, image.Id + ".png");
30+
using (var file = File.Create(fileName)) {
31+
respImage.Seek(0, SeekOrigin.Begin);
32+
await respImage.CopyToAsync(file);
33+
Console.WriteLine("GetImages(): File '{0}' successfully downloaded.", fileName);
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)