Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ XLS, XLSX, PPTX, DOC, DOCX, MobiXML, JPEG, EMF, PNG, BMP, GIF, TIFF, Text
## Read PDF Formats
MHT, PCL, PS, XSLFO, MD

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

## Bugs fixed in Version 25.7
- PostDeleteStamps removing stamps from PDF page is incorrect.

## Installation

### NPM
Expand Down
158 changes: 158 additions & 0 deletions UsesCases/ChangeLayout/changeLayoutHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import credentials from "../../../Credentials/credentials.json" with { type: "json" }; // json-file in this format: { "id": "*****", "key": "*******" }
import fs from 'node:fs/promises';
import path from 'node:path';
import { PdfApi } from "../../src/api/api.js";
import { Rotation } from "../../src/models/rotation.js";
import { DocumentConfig } from "../../src/models/documentConfig.js"
import { DocumentProperties } from "../../src/models/documentProperties.js"
import { DocumentProperty } from "../../src/models/documentProperty.js"
import { DisplayProperties } from "../../src/models/displayProperties.js"
import { DefaultPageConfig } from "../../src/models/defaultPageConfig.js"
import { ImageStamp } from "../../src/models/imageStamp.js"
import { HorizontalAlignment } from "../../src/models/horizontalAlignment.js"
import { VerticalAlignment } from "../../src/models/verticalAlignment.js"
import { HtmlDocumentType } from "../../src/models/htmlDocumentType.js";
import { OutputFormat } from "../../src/models/outputFormat.js"

export { configParams, pdfApi, PdfChangeLayoutHelper };

const configParams = {
LOCAL_FOLDER: "C:\\Samples\\",
PDF_DOCUMENT_NAME: "sample.pdf",
TEMP_FOLDER: 'TempPdfCloud',

ROTATE_ANGLE: Rotation.on90,
ROTATE_PAGES: "1-3",

CROP_PAGE_TEMP_FILE: "sammple_temp_file.png",
CROP_LOCAL_RESULT_DOCUMENT_NAME: "output_sample.pdf",
CROP_PAGE_NUMBER: 3,
CROP_PAGE_WIDTH: 0,
CROP_PAGE_HEIGHT: 0,
CROP_HEIGHT: 400,
CROP_WIDTH: 300,
CROP_LLX: 100,
CROP_LLY: 200,

RESIZE_PDF_HTML_FILE: "sammple_temp_file.html",
RESIZE_RESULT_DOCUMENT_NAME:"output_sample.pdf",
RESIZE_PAGE_NUMBER: 2,
RESIZE_NEW_PAGE_WIDTH: 1000,
RESIZE_NEW_PAGE_HEIGHT: 3000,

};

const pdfApi = new PdfApi(credentials.id, credentials.key);

const PdfChangeLayoutHelper = {
async uploadFile (fileName, localFolder, tempFolder) {
const fileNamePath = path.join(localFolder, fileName);
const fileData = await fs.readFile(fileNamePath);
const storagePath = path.join(tempFolder, fileName);
await pdfApi.uploadFile(storagePath, fileData)
.then(() => console.log("File: '" + fileName +"' successfully uploaded."));
},

async uploadDocument(document, localFolder, tempFolder) {
await this.uploadFile(document, localFolder, tempFolder)
},

async downloadResult(document, localFolder, tempFolder, prefix) {
const fileName = path.join(tempFolder, document);
const changedPdfData = await pdfApi.downloadFile(fileName);
const filePath = path.join(localFolder, prefix + document);
await fs.writeFile(filePath, changedPdfData.body);
console.log("Downloaded: " + filePath);
},

async getPageInfo (document, pageNumber, tempFolder) {
const resultPages = await pdfApi.getPage( document, pageNumber, { folder: tempFolder } );

if (resultPages.body.code == 200 && resultPages.body.page) {
this.showPages( [ resultPages.body.page ], "page");
configParams.PAGE_HEIGHT = resultPages.body.page.rectangle.uRY - resultPages.body.page.rectangle.lLY;
configParams.PAGE_WIDTH = resultPages.body.page.rectangle.uRX - resultPages.body.page.rectangle.lLX;
return {
"width": configParams.PAGE_WIDTH,
"height": configParams.PAGE_HEIGHT
}
}
else {
console.error("Unexpected error : can't get pages!!!");
return null;
}
},

showPages (pages, prefix) {
if (Array.isArray(pages) && pages.length > 0)
{
pages.forEach(function(page) {
console.log(prefix +" => id: '" + page.id + "', lLx: '" + page.rectangle.lLX + "', lLY: '" + page.rectangle.lLY + "', uRX: '" + page.rectangle.uRX + "', uRY: '" + page.rectangle.uRY + "'");
});
}
else
console.error("showPages() error: array of pages is empty!")
},

async extractPdfPage(document, pageNumber, width, height, localFolder, tempFolder) {
const response = await pdfApi.getPageConvertToPng(document, pageNumber, Math.trunc(width), Math.trunc(height), tempFolder);
if (response.response.status != 200)
{
console.error("extractPdfPage(): Faild to convert page to image!");
return null;
}
const filePath = path.join(localFolder, document + ".png");
await fs.writeFile(filePath, response.body);

const imageFile = document + ".png";
const imagePath = localFolder;

await this.uploadFile(imageFile, localFolder, tempFolder);

console.log("Page #" + pageNumber + " extracted as image.");
return imageFile;
},

async createPdfDocument(document, width, height, tempFolder) {
const pdfConfig = new DocumentConfig();
pdfConfig.pagesCount = 1;

pdfConfig.displayProperties = new DisplayProperties();
pdfConfig.displayProperties.centerWindow = true;
pdfConfig.displayProperties.hideMenuBar = true;

pdfConfig.documentProperties = new DocumentProperties();
const docProperty = new DocumentProperty();
docProperty.builtIn = false;
docProperty.name = "prop1";
docProperty.value = "Val1";

pdfConfig.documentProperties.list = [ docProperty ];

pdfConfig.defaultPageConfig = new DefaultPageConfig();
pdfConfig.defaultPageConfig.height = height;
pdfConfig.defaultPageConfig.width = width;

const response = await pdfApi.postCreateDocument(document, pdfConfig, null, tempFolder);
console.log("Document #" + document + " created.")
return response;
},

async insertPageAsImage(document, imageFileValue, llx, lly, tempFolder) {
const stamp = new ImageStamp();
stamp.background = true;
stamp.horizontalAlignment = HorizontalAlignment.None;
stamp.verticalAlignment = VerticalAlignment.None;
stamp.opacity = 1;
stamp.rotate = Rotation.None;
stamp.rotateAngle = 0;
stamp.xIndent = -llx;
stamp.yIndent = -lly;
stamp.zoom = 1;
stamp.fileName = configParams.TEMP_FOLDER + '/' + imageFileValue;

const response = await pdfApi.postPageImageStamps(document, 1, [stamp], null, tempFolder);
console.log("Image iserted into '" + document + "document on page #1");
return response;
},
};
26 changes: 26 additions & 0 deletions UsesCases/ChangeLayout/changeLayoutLaunch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { configParams } from "./changeLayoutHelper.js";
import { PdfRotatePages } from "./rotatePageStdAngle.js"
import { PdfCropPage } from "./cropPage.js";
import { PdfResizePages } from "./resizeDocumentAllPages.js";

async function main() {
try {

await PdfRotatePages.rotate(configParams.PDF_DOCUMENT_NAME,
configParams.ROTATE_ANGLE, configParams.ROTATE_PAGES,
configParams.LOCAL_FOLDER, configParams.TEMP_FOLDER);

await PdfCropPage.cropPage(configParams.PDF_DOCUMENT_NAME,
configParams.CROP_PAGE_NUMBER, configParams.CROP_LLX, configParams.CROP_LLY, configParams.CROP_WIDTH, configParams.CROP_HEIGHT, configParams.CROP_LOCAL_RESULT_DOCUMENT_NAME,
configParams.LOCAL_FOLDER, configParams.TEMP_FOLDER);

await PdfResizePages.resizeAllPages(configParams.PDF_DOCUMENT_NAME,
configParams.RESIZE_PDF_HTML_FILE, configParams.RESIZE_NEW_PAGE_WIDTH, configParams.RESIZE_NEW_PAGE_HEIGHT, configParams.RESIZE_RESULT_DOCUMENT_NAME,
configParams.LOCAL_FOLDER, configParams.TEMP_FOLDER);

} catch (error) {
console.error("Error:", error.message);
}
}

await main();
30 changes: 30 additions & 0 deletions UsesCases/ChangeLayout/cropPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";

export { PdfCropPage };

const PdfCropPage = {
async cropPage(document, pageNumber, llx, lly, width, height, outputDocument, localFolder, tempFolder) {
if ( pdfApi ) {
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder);

var pageSie = await PdfChangeLayoutHelper.getPageInfo(document, pageNumber, tempFolder);

const imageFile = await PdfChangeLayoutHelper.extractPdfPage(document, pageNumber, pageSie.width, pageSie.height, localFolder, tempFolder);
const newPdf = await PdfChangeLayoutHelper.createPdfDocument(outputDocument, width, height, tempFolder);
if (newPdf.body.code != 200) {
console.error("cropPage(): Failed to create new PDF document!");
return;
}

const response = await PdfChangeLayoutHelper.insertPageAsImage(outputDocument, imageFile, llx, lly, tempFolder);

if (response.body.code == 200) {
console.log("cropPage(): Page successfully cropped.");
await PdfChangeLayoutHelper.downloadResult(outputDocument, localFolder, tempFolder, "cropped_")
}
else
console.error("cropPage(): Can't crop pdf document page!")
}

},
};
50 changes: 50 additions & 0 deletions UsesCases/ChangeLayout/resizeDocumentAllPages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";
import path from 'node:path';
import { HtmlDocumentType } from "../../src/models/htmlDocumentType.js";
import { OutputFormat } from "../../src/models/outputFormat.js"

export { PdfResizePages }

const PdfResizePages = {
async resizeAllPages(document, htmlTempDoc, width, height, outputDocument, localFolder, tempFolder) {
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder)

const htmlTempPath = path.join(tempFolder, htmlTempDoc);

const html_response = await pdfApi.putPdfInStorageToHtml(
document,
htmlTempPath,
null, null, null, null,
HtmlDocumentType.Xhtml,
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
tempFolder,
null, null,
OutputFormat.Folder);

if (html_response.body.code != 200) {
console.error("resizePages(): Can't convert pdf to html!");
return;
}
else
console.log("resizePages(): temporary file '" + htmlTempDoc + "' succesfully creaated.")

const response = await pdfApi.putHtmlInStorageToPdf(
outputDocument,
htmlTempPath,
htmlTempDoc,
height,
width,
null, null, null, null, null,
tempFolder,
null);

if (response.body.code == 200) {
console.log("resizePages(): Pages successfully resized.");
await PdfChangeLayoutHelper.downloadResult(outputDocument, localFolder, tempFolder, "resized_doc_");
}
else
console.log("resizePages(): Can't convert html to pdf!")

},

};
22 changes: 22 additions & 0 deletions UsesCases/ChangeLayout/rotatePageStdAngle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";

export { PdfRotatePages };

const PdfRotatePages = {
async rotate(document, angle, pages, localFolder, tempFolder) {
if ( pdfApi) {
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder);

const response = await pdfApi.postDocumentPagesRotate(
document, angle, pages, null, tempFolder);

if (response.body.code == 200) {
console.log("rotatePages(): Page successfully rotated.");
await PdfChangeLayoutHelper.downloadResult(document, localFolder, tempFolder, "rotated_output_");
}
else
console.error("rotatePages(): Can't rotate pdf document pages!")
}

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

[[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)

16 changes: 16 additions & 0 deletions docs/SignatureSubjectNameElements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SignatureSubjectNameElements
Represents an enumeration of available SubjectNameElements.

## Enum
Name | Type | Value | Description
------------ | ------------- | ------------- | -------------
**C** | **string** | 'C' | Common Name.
**CN** | **string** | 'CN' | Common Name.
**E** | **string** | 'E' | Email.
**L** | **string** | 'L' | Locality.
**O** | **string** | 'O' | Organization.
**OU** | **string** | 'OU' | Organizational Unit.
**S** | **string** | 'S' | State or Province Name.

[[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)

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asposepdfcloud",
"version": "25.6.0",
"version": "25.7.0",
"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.",
"homepage": "https://products.aspose.cloud/pdf/cloud",
"author": {
Expand Down
1 change: 1 addition & 0 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import { Segment } from "../models/segment";
import { ShapeType } from "../models/shapeType";
import { Signature } from "../models/signature";
import { SignatureCustomAppearance } from "../models/signatureCustomAppearance";
import { SignatureSubjectNameElements } from "../models/signatureSubjectNameElements";
import { SignatureType } from "../models/signatureType";
import { SoundEncoding } from "../models/soundEncoding";
import { SoundIcon } from "../models/soundIcon";
Expand Down
Loading