Skip to content

Commit 77c5de5

Browse files
authored
Merge pull request #134 from aspose-pdf-cloud/develop
update to 25.7
2 parents b69764d + f888b3e commit 77c5de5

15 files changed

+398
-7
lines changed

README.md

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

33-
## Enhancements in Version 25.6
34-
- Develop Rotate Document Pages method.
33+
## Enhancements in Version 25.7
34+
- Add possibility to hide subject field in signature appearance.
3535
- A new version of Aspose.PDF Cloud was prepared using the latest version of Aspose.PDF for .NET.
3636

37+
## Bugs fixed in Version 25.7
38+
- PostDeleteStamps removing stamps from PDF page is incorrect.
39+
3740
## Installation
3841

3942
### NPM
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import credentials from "../../../Credentials/credentials.json" with { type: "json" }; // json-file in this format: { "id": "*****", "key": "*******" }
2+
import fs from 'node:fs/promises';
3+
import path from 'node:path';
4+
import { PdfApi } from "../../src/api/api.js";
5+
import { Rotation } from "../../src/models/rotation.js";
6+
import { DocumentConfig } from "../../src/models/documentConfig.js"
7+
import { DocumentProperties } from "../../src/models/documentProperties.js"
8+
import { DocumentProperty } from "../../src/models/documentProperty.js"
9+
import { DisplayProperties } from "../../src/models/displayProperties.js"
10+
import { DefaultPageConfig } from "../../src/models/defaultPageConfig.js"
11+
import { ImageStamp } from "../../src/models/imageStamp.js"
12+
import { HorizontalAlignment } from "../../src/models/horizontalAlignment.js"
13+
import { VerticalAlignment } from "../../src/models/verticalAlignment.js"
14+
import { HtmlDocumentType } from "../../src/models/htmlDocumentType.js";
15+
import { OutputFormat } from "../../src/models/outputFormat.js"
16+
17+
export { configParams, pdfApi, PdfChangeLayoutHelper };
18+
19+
const configParams = {
20+
LOCAL_FOLDER: "C:\\Samples\\",
21+
PDF_DOCUMENT_NAME: "sample.pdf",
22+
TEMP_FOLDER: 'TempPdfCloud',
23+
24+
ROTATE_ANGLE: Rotation.on90,
25+
ROTATE_PAGES: "1-3",
26+
27+
CROP_PAGE_TEMP_FILE: "sammple_temp_file.png",
28+
CROP_LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
29+
CROP_PAGE_NUMBER: 3,
30+
CROP_PAGE_WIDTH: 0,
31+
CROP_PAGE_HEIGHT: 0,
32+
CROP_HEIGHT: 400,
33+
CROP_WIDTH: 300,
34+
CROP_LLX: 100,
35+
CROP_LLY: 200,
36+
37+
RESIZE_PDF_HTML_FILE: "sammple_temp_file.html",
38+
RESIZE_RESULT_DOCUMENT_NAME:"output_sample.pdf",
39+
RESIZE_PAGE_NUMBER: 2,
40+
RESIZE_NEW_PAGE_WIDTH: 1000,
41+
RESIZE_NEW_PAGE_HEIGHT: 3000,
42+
43+
};
44+
45+
const pdfApi = new PdfApi(credentials.id, credentials.key);
46+
47+
const PdfChangeLayoutHelper = {
48+
async uploadFile (fileName, localFolder, tempFolder) {
49+
const fileNamePath = path.join(localFolder, fileName);
50+
const fileData = await fs.readFile(fileNamePath);
51+
const storagePath = path.join(tempFolder, fileName);
52+
await pdfApi.uploadFile(storagePath, fileData)
53+
.then(() => console.log("File: '" + fileName +"' successfully uploaded."));
54+
},
55+
56+
async uploadDocument(document, localFolder, tempFolder) {
57+
await this.uploadFile(document, localFolder, tempFolder)
58+
},
59+
60+
async downloadResult(document, localFolder, tempFolder, prefix) {
61+
const fileName = path.join(tempFolder, document);
62+
const changedPdfData = await pdfApi.downloadFile(fileName);
63+
const filePath = path.join(localFolder, prefix + document);
64+
await fs.writeFile(filePath, changedPdfData.body);
65+
console.log("Downloaded: " + filePath);
66+
},
67+
68+
async getPageInfo (document, pageNumber, tempFolder) {
69+
const resultPages = await pdfApi.getPage( document, pageNumber, { folder: tempFolder } );
70+
71+
if (resultPages.body.code == 200 && resultPages.body.page) {
72+
this.showPages( [ resultPages.body.page ], "page");
73+
configParams.PAGE_HEIGHT = resultPages.body.page.rectangle.uRY - resultPages.body.page.rectangle.lLY;
74+
configParams.PAGE_WIDTH = resultPages.body.page.rectangle.uRX - resultPages.body.page.rectangle.lLX;
75+
return {
76+
"width": configParams.PAGE_WIDTH,
77+
"height": configParams.PAGE_HEIGHT
78+
}
79+
}
80+
else {
81+
console.error("Unexpected error : can't get pages!!!");
82+
return null;
83+
}
84+
},
85+
86+
showPages (pages, prefix) {
87+
if (Array.isArray(pages) && pages.length > 0)
88+
{
89+
pages.forEach(function(page) {
90+
console.log(prefix +" => id: '" + page.id + "', lLx: '" + page.rectangle.lLX + "', lLY: '" + page.rectangle.lLY + "', uRX: '" + page.rectangle.uRX + "', uRY: '" + page.rectangle.uRY + "'");
91+
});
92+
}
93+
else
94+
console.error("showPages() error: array of pages is empty!")
95+
},
96+
97+
async extractPdfPage(document, pageNumber, width, height, localFolder, tempFolder) {
98+
const response = await pdfApi.getPageConvertToPng(document, pageNumber, Math.trunc(width), Math.trunc(height), tempFolder);
99+
if (response.response.status != 200)
100+
{
101+
console.error("extractPdfPage(): Faild to convert page to image!");
102+
return null;
103+
}
104+
const filePath = path.join(localFolder, document + ".png");
105+
await fs.writeFile(filePath, response.body);
106+
107+
const imageFile = document + ".png";
108+
const imagePath = localFolder;
109+
110+
await this.uploadFile(imageFile, localFolder, tempFolder);
111+
112+
console.log("Page #" + pageNumber + " extracted as image.");
113+
return imageFile;
114+
},
115+
116+
async createPdfDocument(document, width, height, tempFolder) {
117+
const pdfConfig = new DocumentConfig();
118+
pdfConfig.pagesCount = 1;
119+
120+
pdfConfig.displayProperties = new DisplayProperties();
121+
pdfConfig.displayProperties.centerWindow = true;
122+
pdfConfig.displayProperties.hideMenuBar = true;
123+
124+
pdfConfig.documentProperties = new DocumentProperties();
125+
const docProperty = new DocumentProperty();
126+
docProperty.builtIn = false;
127+
docProperty.name = "prop1";
128+
docProperty.value = "Val1";
129+
130+
pdfConfig.documentProperties.list = [ docProperty ];
131+
132+
pdfConfig.defaultPageConfig = new DefaultPageConfig();
133+
pdfConfig.defaultPageConfig.height = height;
134+
pdfConfig.defaultPageConfig.width = width;
135+
136+
const response = await pdfApi.postCreateDocument(document, pdfConfig, null, tempFolder);
137+
console.log("Document #" + document + " created.")
138+
return response;
139+
},
140+
141+
async insertPageAsImage(document, imageFileValue, llx, lly, tempFolder) {
142+
const stamp = new ImageStamp();
143+
stamp.background = true;
144+
stamp.horizontalAlignment = HorizontalAlignment.None;
145+
stamp.verticalAlignment = VerticalAlignment.None;
146+
stamp.opacity = 1;
147+
stamp.rotate = Rotation.None;
148+
stamp.rotateAngle = 0;
149+
stamp.xIndent = -llx;
150+
stamp.yIndent = -lly;
151+
stamp.zoom = 1;
152+
stamp.fileName = configParams.TEMP_FOLDER + '/' + imageFileValue;
153+
154+
const response = await pdfApi.postPageImageStamps(document, 1, [stamp], null, tempFolder);
155+
console.log("Image iserted into '" + document + "document on page #1");
156+
return response;
157+
},
158+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { configParams } from "./changeLayoutHelper.js";
2+
import { PdfRotatePages } from "./rotatePageStdAngle.js"
3+
import { PdfCropPage } from "./cropPage.js";
4+
import { PdfResizePages } from "./resizeDocumentAllPages.js";
5+
6+
async function main() {
7+
try {
8+
9+
await PdfRotatePages.rotate(configParams.PDF_DOCUMENT_NAME,
10+
configParams.ROTATE_ANGLE, configParams.ROTATE_PAGES,
11+
configParams.LOCAL_FOLDER, configParams.TEMP_FOLDER);
12+
13+
await PdfCropPage.cropPage(configParams.PDF_DOCUMENT_NAME,
14+
configParams.CROP_PAGE_NUMBER, configParams.CROP_LLX, configParams.CROP_LLY, configParams.CROP_WIDTH, configParams.CROP_HEIGHT, configParams.CROP_LOCAL_RESULT_DOCUMENT_NAME,
15+
configParams.LOCAL_FOLDER, configParams.TEMP_FOLDER);
16+
17+
await PdfResizePages.resizeAllPages(configParams.PDF_DOCUMENT_NAME,
18+
configParams.RESIZE_PDF_HTML_FILE, configParams.RESIZE_NEW_PAGE_WIDTH, configParams.RESIZE_NEW_PAGE_HEIGHT, configParams.RESIZE_RESULT_DOCUMENT_NAME,
19+
configParams.LOCAL_FOLDER, configParams.TEMP_FOLDER);
20+
21+
} catch (error) {
22+
console.error("Error:", error.message);
23+
}
24+
}
25+
26+
await main();

UsesCases/ChangeLayout/cropPage.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";
2+
3+
export { PdfCropPage };
4+
5+
const PdfCropPage = {
6+
async cropPage(document, pageNumber, llx, lly, width, height, outputDocument, localFolder, tempFolder) {
7+
if ( pdfApi ) {
8+
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder);
9+
10+
var pageSie = await PdfChangeLayoutHelper.getPageInfo(document, pageNumber, tempFolder);
11+
12+
const imageFile = await PdfChangeLayoutHelper.extractPdfPage(document, pageNumber, pageSie.width, pageSie.height, localFolder, tempFolder);
13+
const newPdf = await PdfChangeLayoutHelper.createPdfDocument(outputDocument, width, height, tempFolder);
14+
if (newPdf.body.code != 200) {
15+
console.error("cropPage(): Failed to create new PDF document!");
16+
return;
17+
}
18+
19+
const response = await PdfChangeLayoutHelper.insertPageAsImage(outputDocument, imageFile, llx, lly, tempFolder);
20+
21+
if (response.body.code == 200) {
22+
console.log("cropPage(): Page successfully cropped.");
23+
await PdfChangeLayoutHelper.downloadResult(outputDocument, localFolder, tempFolder, "cropped_")
24+
}
25+
else
26+
console.error("cropPage(): Can't crop pdf document page!")
27+
}
28+
29+
},
30+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";
2+
import path from 'node:path';
3+
import { HtmlDocumentType } from "../../src/models/htmlDocumentType.js";
4+
import { OutputFormat } from "../../src/models/outputFormat.js"
5+
6+
export { PdfResizePages }
7+
8+
const PdfResizePages = {
9+
async resizeAllPages(document, htmlTempDoc, width, height, outputDocument, localFolder, tempFolder) {
10+
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder)
11+
12+
const htmlTempPath = path.join(tempFolder, htmlTempDoc);
13+
14+
const html_response = await pdfApi.putPdfInStorageToHtml(
15+
document,
16+
htmlTempPath,
17+
null, null, null, null,
18+
HtmlDocumentType.Xhtml,
19+
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
20+
tempFolder,
21+
null, null,
22+
OutputFormat.Folder);
23+
24+
if (html_response.body.code != 200) {
25+
console.error("resizePages(): Can't convert pdf to html!");
26+
return;
27+
}
28+
else
29+
console.log("resizePages(): temporary file '" + htmlTempDoc + "' succesfully creaated.")
30+
31+
const response = await pdfApi.putHtmlInStorageToPdf(
32+
outputDocument,
33+
htmlTempPath,
34+
htmlTempDoc,
35+
height,
36+
width,
37+
null, null, null, null, null,
38+
tempFolder,
39+
null);
40+
41+
if (response.body.code == 200) {
42+
console.log("resizePages(): Pages successfully resized.");
43+
await PdfChangeLayoutHelper.downloadResult(outputDocument, localFolder, tempFolder, "resized_doc_");
44+
}
45+
else
46+
console.log("resizePages(): Can't convert html to pdf!")
47+
48+
},
49+
50+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";
2+
3+
export { PdfRotatePages };
4+
5+
const PdfRotatePages = {
6+
async rotate(document, angle, pages, localFolder, tempFolder) {
7+
if ( pdfApi) {
8+
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder);
9+
10+
const response = await pdfApi.postDocumentPagesRotate(
11+
document, angle, pages, null, tempFolder);
12+
13+
if (response.body.code == 200) {
14+
console.log("rotatePages(): Page successfully rotated.");
15+
await PdfChangeLayoutHelper.downloadResult(document, localFolder, tempFolder, "rotated_output_");
16+
}
17+
else
18+
console.error("rotatePages(): Can't rotate pdf document pages!")
19+
}
20+
21+
},
22+
};

docs/SignatureCustomAppearance.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ An abstract class which represents signature custom appearance object.
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**fontFamilyName** | **string** | Gets/sets font family name. It should be existed in the document. Default value: Arial. | [optional]
8-
**fontSize** | **number** | Gets/sets font size. Default value: 10. |
8+
**fontSize** | **number** | Gets/sets font size. Default value: 10. | [optional]
9+
**rotation** | [**Rotation**](Rotation.md) | Gets or sets signature rotation. |
910
**showContactInfo** | **boolean** | Gets/sets contact info visibility. Default value: true. |
1011
**showReason** | **boolean** | Gets/sets reason visibility. Default value: true. |
1112
**showLocation** | **boolean** | Gets/sets location visibility. Default value: true. |
@@ -16,6 +17,10 @@ Name | Type | Description | Notes
1617
**dateSignedAtLabel** | **string** | Gets/sets date signed label. Default value: "Date". | [optional]
1718
**dateTimeLocalFormat** | **string** | Gets/sets datetime local format. Default value: "yyyy.MM.dd HH:mm:ss zzz". | [optional]
1819
**dateTimeFormat** | **string** | Gets/sets datetime format. Default value: "yyyy.MM.dd HH:mm:ss". | [optional]
20+
**backgroundColor** | [**Color**](Color.md) | Gets/sets background color. | [optional]
21+
**foregroundColor** | [**Color**](Color.md) | Gets/sets foreground color. | [optional]
22+
**useDigitalSubjectFormat** | **boolean** | Gets/sets subject format usage. |
23+
**digitalSubjectFormat** | [**Array<SignatureSubjectNameElements>**](SignatureSubjectNameElements.md) | Gets/sets subject format. | [optional]
1924

2025
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[View Source]](../src/models/signatureCustomAppearance.ts)
2126

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SignatureSubjectNameElements
2+
Represents an enumeration of available SubjectNameElements.
3+
4+
## Enum
5+
Name | Type | Value | Description
6+
------------ | ------------- | ------------- | -------------
7+
**C** | **string** | 'C' | Common Name.
8+
**CN** | **string** | 'CN' | Common Name.
9+
**E** | **string** | 'E' | Email.
10+
**L** | **string** | 'L' | Locality.
11+
**O** | **string** | 'O' | Organization.
12+
**OU** | **string** | 'OU' | Organizational Unit.
13+
**S** | **string** | 'S' | State or Province Name.
14+
15+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) [[View Source]](../src/models/signatureSubjectNameElements.ts)
16+

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "asposepdfcloud",
3-
"version": "25.6.0",
3+
"version": "25.7.0",
44
"description": "Aspose.PDF Cloud is a REST API for creating and editing PDF files. Most popular features proposed by Aspose.PDF Cloud: PDF to Word, Convert PDF to Image, Merge PDF, Split PDF, Add Images to PDF, Rotate PDF. It can also be used to convert PDF files to different formats like DOC, HTML, XPS, TIFF and many more. Aspose.PDF Cloud gives you control: create PDFs from scratch or from HTML, XML, template, database, XPS or an image. Render PDFs to image formats such as JPEG, PNG, GIF, BMP, TIFF and many others. Aspose.PDF Cloud helps you manipulate elements of a PDF file like text, annotations, watermarks, signatures, bookmarks, stamps and so on. Its REST API also allows you to manage PDF pages by using features like merging, splitting, and inserting. Add images to a PDF file or convert PDF pages to images.",
55
"homepage": "https://products.aspose.cloud/pdf/cloud",
66
"author": {

0 commit comments

Comments
 (0)