Skip to content

Commit 430ca20

Browse files
authored
Merge pull request #125 from aspose-pdf-cloud/develop
update to 25.7
2 parents 512975e + 31487c0 commit 430ca20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1672
-20
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ 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.6
33-
- Develop Rotate Document Pages method.
32+
## Enhancements in Version 25.7
33+
- Add possibility to hide subject field in signature appearance.
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.7
37+
- PostDeleteStamps removing stamps from PDF page is incorrect.
38+
3639
## Unit Tests
3740
Aspose PDF SDK includes a suite of unit tests. These Unit Tests also serves as examples of how to use the Aspose PDF SDK.
3841

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: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
using Aspose.Pdf.Cloud.Sdk.Api;
2+
using Aspose.Pdf.Cloud.Sdk.Model;
3+
using Newtonsoft.Json;
4+
5+
namespace ChangeLayout
6+
{
7+
public class ConfigParams
8+
{
9+
public string CrdentialPath { get; } = "..\\credentials.json ";
10+
public string LOCAL_FOLDER { get; } = "C:\\Samples";
11+
public string REMOTE_TEMP_FOLDER { get; } = "TempPdfCloud";
12+
public string PDF_DOCUMENT { get; } = "sample.pdf";
13+
public string PDF_OUTPUT { get; } = "output_sample.pdf";
14+
15+
public Rotation ROTATE_PAGES_ANGLE = Rotation.On90;
16+
public string ROTATE_PAGES { get; } = "1-3";
17+
18+
19+
public string CROP_PAGE_TEMP_FILE { get; } = "sample_temp_file.png";
20+
public string CROP_LOCAL_RESULT_DOCUMENT_NAME { get; } = "output_sample.pdf";
21+
public int CROP_PAGE_NUMBER { get; } = 3;
22+
public int CROP_HEIGHT { get; } = 400;
23+
public int CROP_WIDTH { get; } = 300;
24+
public int CROP_LLX { get; } = 100;
25+
public int CROP_LLY { get; } = 200;
26+
27+
public string RESIZE_PDF_HTML_FILE { get; } = "sample_temp_file.html";
28+
public string RESIZE_RESULT_DOCUMENT_NAME { get; } = "output_sample.pdf";
29+
public int RESIZE_PAGE_NUMBER { get; } = 2;
30+
public int RESIZE_NEW_PAGE_WIDTH { get; } = 1000;
31+
public int RESIZE_NEW_PAGE_HEIGHT { get; } = 500;
32+
33+
public int CROP_PAGE_WIDTH { get; set; } = 0;
34+
public int CROP_PAGE_HEIGHT { get; set; } = 0;
35+
}
36+
37+
public class Credentials
38+
{
39+
public string Id { get; set; }
40+
public string Key { get; set; }
41+
}
42+
43+
public class ChangeLayoutHelper
44+
{
45+
public PdfApi pdfApi { get; private set; }
46+
public ConfigParams config { get; private set; }
47+
48+
public ChangeLayoutHelper()
49+
{
50+
config = new ConfigParams();
51+
string jsCredText = File.ReadAllText(config.CrdentialPath);
52+
Credentials cred = JsonConvert.DeserializeObject<Credentials>(jsCredText);
53+
pdfApi = new PdfApi(cred.Key, cred.Id);
54+
}
55+
56+
public async Task UploadFile(string fileName)
57+
{
58+
using (var file = File.OpenRead(Path.Combine(config.LOCAL_FOLDER, fileName)))
59+
{
60+
FilesUploadResult response = await pdfApi.UploadFileAsync(Path.Combine(config.REMOTE_TEMP_FOLDER, fileName), file);
61+
if (response == null)
62+
Console.WriteLine("UploadFile(): Unexpected error - no response!");
63+
else if (response.Errors != null && response.Errors.Count > 0)
64+
foreach (var error in response.Errors)
65+
Console.WriteLine("UploadFile(): {0} -> {1}", [ error.Code, error.Message]);
66+
else
67+
Console.WriteLine("UploadFile(): File '{0}' successfully uploaded.", fileName);
68+
}
69+
}
70+
71+
public async Task DownloadFile(string fileName, string outputPrefix)
72+
{
73+
Stream stream = pdfApi.DownloadFile(Path.Combine(config.REMOTE_TEMP_FOLDER, fileName));
74+
using var fileStream = File.Create(Path.Combine(config.LOCAL_FOLDER, outputPrefix + fileName));
75+
stream.Position = 0;
76+
await stream.CopyToAsync(fileStream);
77+
Console.WriteLine("DownloadFile(): File '{0}' successfully downloaded.", outputPrefix + fileName);
78+
}
79+
80+
public async Task GetPageInfo(string document, int pageNumber)
81+
{
82+
DocumentPageResponse response = await pdfApi.GetPageAsync(document, pageNumber, folder: config.REMOTE_TEMP_FOLDER);
83+
if (response == null)
84+
Console.WriteLine("GetPageInfo(): Unexpected error - no response!");
85+
else if (response.Code != 200)
86+
Console.WriteLine("GetPageInfo(): Code {0} -> Status '{1}'", [response.Code, response.Status]);
87+
else
88+
{
89+
Page page = response.Page;
90+
Rectangle rectangle = page.Rectangle;
91+
Console.WriteLine("GetPageInfo(): page {0} => id: '{1}', lLx: '{2}', lLY: '{3}', uRX: '{4}', uRY: '{5}'",
92+
[pageNumber, page.Id, rectangle.LLX, rectangle.LLY, rectangle.URX, rectangle.URY]);
93+
config.CROP_PAGE_HEIGHT = (int)(Math.Round(rectangle.URY ?? 0) - Math.Round(rectangle.LLY ?? 0));
94+
config.CROP_PAGE_WIDTH = (int)(Math.Round(rectangle.URX ?? 0) - Math.Round(rectangle.LLX ?? 0));
95+
}
96+
}
97+
98+
public async Task<string> ExtractPdfPage(string document, int pageNumber, int width, int height)
99+
{
100+
string imageFile = document + ".png";
101+
Stream stream = await pdfApi.GetPageConvertToPngAsync(document, pageNumber, width, height, config.REMOTE_TEMP_FOLDER);
102+
using var fileStream = File.Create(Path.Combine(config.LOCAL_FOLDER, imageFile));
103+
stream.Position = 0;
104+
await stream.CopyToAsync(fileStream);
105+
106+
UploadFile(imageFile);
107+
Console.WriteLine("ExtractPdfPage(): Page #{0} extracted as image {1}.", [pageNumber, imageFile]);
108+
109+
return imageFile;
110+
}
111+
112+
public async Task<DocumentResponse?> CreatePdfDocument(string newDocument, int width, int height)
113+
{
114+
DocumentProperties docProps = new DocumentProperties(
115+
List: new List<DocumentProperty>() {
116+
new DocumentProperty(Name: "prop1", Value: "Value1", BuiltIn: false)
117+
}
118+
);
119+
120+
DisplayProperties dispProps = new DisplayProperties()
121+
{
122+
CenterWindow = true,
123+
HideMenuBar = true,
124+
Direction = Direction.L2R,
125+
DisplayDocTitle = true,
126+
HideToolBar = true,
127+
HideWindowUI = true,
128+
NonFullScreenPageMode = PageMode.UseThumbs,
129+
PageLayout = PageLayout.TwoPageLeft,
130+
PageMode = PageMode.UseThumbs
131+
};
132+
133+
DefaultPageConfig pageConfig = new DefaultPageConfig(height, width);
134+
135+
DocumentConfig document_config = new DocumentConfig(
136+
DocumentProperties: docProps,
137+
DisplayProperties: dispProps,
138+
DefaultPageConfig: pageConfig,
139+
PagesCount: 1
140+
);
141+
142+
DocumentResponse response = await pdfApi.PostCreateDocumentAsync(newDocument, document_config, folder: config.REMOTE_TEMP_FOLDER);
143+
144+
if (response != null && response.Code == 200)
145+
{
146+
Console.WriteLine("CreatePdfDocument(): Document '{0}' created.", newDocument);
147+
return response;
148+
}
149+
else
150+
{
151+
Console.WriteLine("CreatePdfDocument(): Unexpected error!!!");
152+
return null;
153+
}
154+
}
155+
156+
public async Task<AsposeResponse?> InsertPageAsImage(string document, string imageFileValue, int llx, int lly)
157+
{
158+
ImageStamp imageStamp = new ImageStamp(
159+
Background: true,
160+
HorizontalAlignment: HorizontalAlignment.None,
161+
VerticalAlignment: VerticalAlignment.None,
162+
Rotate: Rotation.None,
163+
RotateAngle: 0,
164+
Opacity: 1,
165+
XIndent: -llx,
166+
YIndent: -lly,
167+
Zoom: 1,
168+
FileName: Path.Combine(config.REMOTE_TEMP_FOLDER, imageFileValue)
169+
);
170+
171+
AsposeResponse response = await pdfApi.PostPageImageStampsAsync(document, 1, new List<ImageStamp>() { imageStamp}, folder: config.REMOTE_TEMP_FOLDER );
172+
if (response != null && response.Code == 200)
173+
{
174+
Console.WriteLine("InsertPageAsImage(): Document '{0}' with stamp '{1}' created.", [document, imageFileValue]);
175+
return response;
176+
}
177+
else
178+
{
179+
Console.WriteLine("CreatePdfDocument(): Unexpected error!!!");
180+
return null;
181+
}
182+
}
183+
}
184+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
3+
namespace ChangeLayout
4+
{
5+
public class CropDocumentPage
6+
{
7+
private ChangeLayoutHelper _helper;
8+
9+
public CropDocumentPage(ChangeLayoutHelper helper)
10+
{
11+
_helper = helper;
12+
}
13+
14+
public async Task MakeCropDocumentPage(string document, string outputDocument, int pageNumber, int llx, int lly, int width, int height)
15+
{
16+
await _helper.UploadFile(document);
17+
await _helper.GetPageInfo(document, pageNumber);
18+
string imageFile = await _helper.ExtractPdfPage(document, pageNumber, _helper.config.CROP_PAGE_WIDTH, _helper.config.CROP_PAGE_HEIGHT);
19+
DocumentResponse? newPdf = await _helper.CreatePdfDocument(outputDocument, width, height);
20+
if (newPdf == null)
21+
Console.WriteLine("MakeCropDocumentPage(): Unexpected error - new document is NULL");
22+
else if (newPdf.Code != 200)
23+
Console.WriteLine("MakeCropDocumentPage(): Failed to create new PDF document!");
24+
else
25+
{
26+
AsposeResponse? response = await _helper.InsertPageAsImage(outputDocument, imageFile, llx, lly);
27+
if (response == null)
28+
Console.WriteLine("MakeCropDocumentPage(): Unexpected error - insert image return NULL");
29+
else if (newPdf.Code != 200)
30+
Console.WriteLine("MakeCropDocumentPage(): Failed to insert image to the new PDF document!");
31+
else
32+
{
33+
Console.WriteLine("cropPage(): Page successfully cropped.");
34+
await _helper.DownloadFile(outputDocument, "cropped_");
35+
}
36+
}
37+
}
38+
}
39+
}

Uses-Cases/ChangeLayout/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using ChangeLayout;
2+
3+
4+
ChangeLayoutHelper helper = new ChangeLayoutHelper();
5+
6+
RotateDocumentsPages rotate = new RotateDocumentsPages(helper);
7+
await rotate.MakeRotateDocumentsPages(helper.config.PDF_DOCUMENT, helper.config.ROTATE_PAGES_ANGLE.ToString(), helper.config.ROTATE_PAGES);
8+
9+
ResizeDocumentAllPages resize = new ResizeDocumentAllPages(helper);
10+
await resize.MakeResizeDocumentAllPages(helper.config.PDF_DOCUMENT, helper.config.RESIZE_PDF_HTML_FILE, helper.config.RESIZE_NEW_PAGE_WIDTH, helper.config.RESIZE_NEW_PAGE_HEIGHT);
11+
12+
CropDocumentPage crop = new CropDocumentPage(helper);
13+
await crop.MakeCropDocumentPage(helper.config.PDF_DOCUMENT, helper.config.CROP_LOCAL_RESULT_DOCUMENT_NAME, helper.config.CROP_PAGE_NUMBER, helper.config.CROP_LLX, helper.config.CROP_LLY, helper.config.CROP_WIDTH, helper.config.CROP_HEIGHT);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Aspose.Pdf.Cloud.Sdk.Model;
2+
3+
4+
namespace ChangeLayout
5+
{
6+
public class ResizeDocumentAllPages
7+
{
8+
private ChangeLayoutHelper _helper;
9+
10+
public ResizeDocumentAllPages(ChangeLayoutHelper helper)
11+
{
12+
_helper = helper;
13+
}
14+
15+
public async Task MakeResizeDocumentAllPages(string document, string htmlTempDoc, int pageWidth, int pageHeight)
16+
{
17+
await _helper.UploadFile(document);
18+
string htmlTempPath = Path.Combine(_helper.config.REMOTE_TEMP_FOLDER, htmlTempDoc);
19+
AsposeResponse response = await _helper.pdfApi.PutPdfInStorageToHtmlAsync(
20+
document, htmlTempPath,
21+
documentType: HtmlDocumentType.Xhtml.ToString(),
22+
outputFormat: OutputFormat.Folder.ToString(),
23+
folder: _helper.config.REMOTE_TEMP_FOLDER
24+
);
25+
if (response == null)
26+
Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in Pdf to Html convert!");
27+
else if (response.Code != 200)
28+
Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
29+
else
30+
{
31+
Console.WriteLine("MakeResizeDocumentAllPages(): temporary file '{0}' successfully created.", htmlTempDoc);
32+
string outputDocument = "resized_" + document;
33+
await _helper.pdfApi.PutHtmlInStorageToPdfAsync(
34+
outputDocument, htmlTempPath,
35+
dstFolder: _helper.config.REMOTE_TEMP_FOLDER,
36+
htmlFileName: htmlTempDoc,
37+
height: pageHeight,
38+
width: pageWidth
39+
);
40+
41+
if (response == null)
42+
Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in html to Pdf convert!");
43+
else if (response.Code != 200)
44+
Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
45+
else
46+
{
47+
Console.WriteLine("resizePages(): Pages successfully resized.");
48+
await _helper.DownloadFile(outputDocument, "resized_doc_");
49+
}
50+
}
51+
52+
}
53+
}
54+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Aspose.Pdf.Cloud.Sdk.Api;
2+
using Aspose.Pdf.Cloud.Sdk.Model;
3+
4+
namespace ChangeLayout
5+
{
6+
public class RotateDocumentsPages
7+
{
8+
private ChangeLayoutHelper _helper;
9+
10+
public RotateDocumentsPages(ChangeLayoutHelper helper)
11+
{
12+
_helper = helper;
13+
}
14+
15+
public async Task MakeRotateDocumentsPages(string document, string rotateAngle, string pages)
16+
{
17+
await _helper.UploadFile(document);
18+
AsposeResponse response = await _helper.pdfApi.PostDocumentPagesRotateAsync(document, rotateAngle, pages, folder: _helper.config.REMOTE_TEMP_FOLDER);
19+
if (response.Code != 200)
20+
Console.WriteLine("MakeRotateDocumentsPages(): Unexpected error!");
21+
else {
22+
Console.WriteLine("MakeRotateDocumentsPages(): Pages '{0}' successfully rotated!");
23+
24+
await _helper.DownloadFile(document, "rotated_");
25+
}
26+
}
27+
}
28+
}
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>

0 commit comments

Comments
 (0)