diff --git a/README.md b/README.md index 231d8de6..6b72b3f1 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,11 @@ XLS, XLSX, PPTX, DOC, DOCX, MobiXML, JPEG, EMF, PNG, BMP, GIF, TIFF, Text ## Read PDF Formats MHT, PCL, PS, XSLFO, MD -## Enhancements in Version 24.7 +## Enhancements in Version 24.8 +- Adding Text stamps to multiple pages. +- Adding Image stamps to multiple pages. - A new version of Aspose.PDF Cloud was prepared using the latest version of Aspose.PDF for .NET. -## Bugs fixed in Version 24.7 -- PutPsInStorageToPdf throws: Cannot find resource ???Aspose.PDF.dependencies.ZapfDingbats.ttf. -- Ocr method is not working. - ## Installation ### NPM diff --git a/docs/OptimizeOptions.md b/docs/OptimizeOptions.md index 22206f9e..d941594d 100644 --- a/docs/OptimizeOptions.md +++ b/docs/OptimizeOptions.md @@ -5,16 +5,16 @@ Represents Pdf optimize options. Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **password** | **string** | Specifies document password (if any) encoded with base-64. | [optional] -**allowReusePageContent** | **boolean** | If true page contents will be reused when document is optimized for equal pages. | [optional] +**allowReusePageContent** | **boolean** | If true page contents will be reused when document is optimized for equal pages. LinkDuplcateStreams option must be set to true. | [optional] **compressImages** | **boolean** | If this flag is set to true images will be compressed in the document. Compression level is specified with ImageQuality property. | [optional] **imageQuality** | **number** | Specifies level of image compression when CompressImages flag is used. | [optional] **linkDuplcateStreams** | **boolean** | If this flag is set to true, Resource streams will be analyzed. If duplicate streams are found (i.e. if stream contents is equal), then thees streams will be stored as one object. This allows to decrease document size in some cases (for example, when same document was concatenated multiple times). | [optional] **removeUnusedObjects** | **boolean** | If this flag is set to true, all document objects will be checked and unused objects (i.e. objects which does not have any reference) are removed from document. | [optional] **removeUnusedStreams** | **boolean** | If this flag set to true, every resource is checked on it's usage. If resource is never used, then resources is removed. This may decrease document size for example when pages were extracted from document. | [optional] -**unembedFonts** | **boolean** | Make fonts not embedded if set to true. | [optional] +**unembedFonts** | **boolean** | Make fonts not embedded if set to true. Unembedding a font means removing the embedded byte stream data of the font included in a PDF document. | [optional] **resizeImages** | **boolean** | If this flag set to true and CompressImages is true images will be resized if image resolution is greater then specified MaxResolution parameter. | [optional] **maxResolution** | **number** | Specifies maximum resolution of images. If image has higher resolution it will be scaled. | [optional] -**subsetFonts** | **boolean** | Fonts will be converted into subsets if set to true. | [optional] +**subsetFonts** | **boolean** | Fonts will be converted into subsets if set to true. Only those characters that are actually used in the layout are stored in the PDF. | [optional] **removePrivateInfo** | **boolean** | Remove private information (page piece info). | [optional] **imageEncoding** | [**ImageEncoding**](ImageEncoding.md) | Image encode which will be used. | [optional] **imageCompressionVersion** | [**ImageCompressionVersion**](ImageCompressionVersion.md) | Version of compression algorithm. Possible values are: "Standard" - standard compression, "Fast" - fast (improved compression which is faster then standard but may be applicable not for all images), "Mixed" - mixed (standard compression is applied to images which can not be compressed by faster algorithm, this may give best compression but more slow then "Fast" algorithm. Version "Fast" is not applicable for resizing images (standard method will be used). Default is "Standard". | [optional] diff --git a/docs/PdfApi.md b/docs/PdfApi.md index 1b2ee98b..e7071e9d 100644 --- a/docs/PdfApi.md +++ b/docs/PdfApi.md @@ -203,10 +203,12 @@ Method | HTTP request | Description *PdfApi* | [**postDecryptDocumentInStorage**](PdfApi.md#postDecryptDocumentInStorage) | **POST** /pdf/\{name}/decrypt | Decrypt document in storage. *PdfApi* | [**postDocumentImageFooter**](PdfApi.md#postDocumentImageFooter) | **POST** /pdf/\{name}/footer/image | Add document image footer. *PdfApi* | [**postDocumentImageHeader**](PdfApi.md#postDocumentImageHeader) | **POST** /pdf/\{name}/header/image | Add document image header. +*PdfApi* | [**postDocumentImageStamps**](PdfApi.md#postDocumentImageStamps) | **POST** /pdf/\{name}/stamps/image | Add document pages image stamps. *PdfApi* | [**postDocumentPageNumberStamps**](PdfApi.md#postDocumentPageNumberStamps) | **POST** /pdf/\{name}/stamps/pagenumber | Add document page number stamps. *PdfApi* | [**postDocumentTextFooter**](PdfApi.md#postDocumentTextFooter) | **POST** /pdf/\{name}/footer/text | Add document text footer. *PdfApi* | [**postDocumentTextHeader**](PdfApi.md#postDocumentTextHeader) | **POST** /pdf/\{name}/header/text | Add document text header. *PdfApi* | [**postDocumentTextReplace**](PdfApi.md#postDocumentTextReplace) | **POST** /pdf/\{name}/text/replace | Document's replace text method. +*PdfApi* | [**postDocumentTextStamps**](PdfApi.md#postDocumentTextStamps) | **POST** /pdf/\{name}/stamps/text | Add document pages text stamps. *PdfApi* | [**postEncryptDocumentInStorage**](PdfApi.md#postEncryptDocumentInStorage) | **POST** /pdf/\{name}/encrypt | Encrypt document in storage. *PdfApi* | [**postFlattenDocument**](PdfApi.md#postFlattenDocument) | **POST** /pdf/\{name}/flatten | Flatten the document. *PdfApi* | [**postHtmlToPdf**](PdfApi.md#postHtmlToPdf) | **POST** /pdf/create/html | Convert HTML file (zip archive in request content) to PDF format and return resulting file in response. @@ -5004,6 +5006,30 @@ Name | Type | Description | Notes [**AsposeResponse**](AsposeResponse.md) +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + + +## **postDocumentImageStamps** +> postDocumentImageStamps(name, stamps, storage, folder, password) + +Add document pages image stamps. + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**name** | **string** | The document name. | +**stamps** | [**Array<ImageStamp>**](ImageStamp.md) | The array of stamp. | +**storage** | **string** | The document storage. | [optional] +**folder** | **string** | The document folder. | [optional] +**password** | **string** | Base64 encoded password. | [optional] + +### Return type + +[**AsposeResponse**](AsposeResponse.md) + ### HTTP request headers - **Content-Type**: application/json @@ -5103,6 +5129,30 @@ Name | Type | Description | Notes [**TextReplaceResponse**](TextReplaceResponse.md) +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + + +## **postDocumentTextStamps** +> postDocumentTextStamps(name, stamps, storage, folder, password) + +Add document pages text stamps. + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**name** | **string** | The document name. | +**stamps** | [**Array<TextStamp>**](TextStamp.md) | The array of stamp. | +**storage** | **string** | The document storage. | [optional] +**folder** | **string** | The document folder. | [optional] +**password** | **string** | Base64 encoded password. | [optional] + +### Return type + +[**AsposeResponse**](AsposeResponse.md) + ### HTTP request headers - **Content-Type**: application/json diff --git a/package-lock.json b/package-lock.json index 8ce66829..7fe2e5fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "asposepdfcloud", - "version": "24.7.0", + "version": "24.8.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "asposepdfcloud", - "version": "24.7.0", + "version": "24.8.0", "license": "MIT", "dependencies": { "@types/bluebird": "*", diff --git a/package.json b/package.json index e02f1f8a..0240222d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asposepdfcloud", - "version": "24.7.0", + "version": "24.8.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": { diff --git a/src/api/api.ts b/src/api/api.ts index f3818bd0..78e10fef 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -12384,6 +12384,70 @@ export class PdfApi { } + /** + * + * @summary Add document pages image stamps. + * @param name The document name. + * @param stamps The array of stamp. + * @param storage The document storage. + * @param folder The document folder. + * @param password Base64 encoded password. + */ + public async postDocumentImageStamps (name: string, stamps: Array, storage?: string, folder?: string, password?: string) : Promise<{ response: http.IncomingMessage; body: AsposeResponse; }> { + const localVarPath = this.basePath + '/pdf/{name}/stamps/image' + .replace('{' + 'name' + '}', encodeURIComponent(String(name)).replace('%2F', '/')); + let localVarQueryParameters: any = {}; + let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); + let localVarFormParams: any = {}; + + // verify required parameter 'name' is not null or undefined + if (name === null || name === undefined) { + throw new Error('Required parameter name was null or undefined when calling postDocumentImageStamps.'); + } + + // verify required parameter 'stamps' is not null or undefined + if (stamps === null || stamps === undefined) { + throw new Error('Required parameter stamps was null or undefined when calling postDocumentImageStamps.'); + } + + if (storage !== undefined && null !== storage) { + localVarQueryParameters['storage'] = ObjectSerializer.serialize(storage, "string"); + } + + if (folder !== undefined && null !== folder) { + localVarQueryParameters['folder'] = ObjectSerializer.serialize(folder, "string"); + } + + if (password !== undefined && null !== password) { + localVarQueryParameters['password'] = ObjectSerializer.serialize(password, "string"); + } + + + let localVarUseFormData = false; + let fileData = null; + let localVarRequestOptions: localVarRequest.Options = { + method: 'POST', + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + body: ObjectSerializer.serialize(stamps, "Array") + }; + + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; + } else { + localVarRequestOptions.form = localVarFormParams; + } + } + const response = await invokeApiMethod(localVarRequestOptions, this.configuration, false, fileData); + const result = ObjectSerializer.deserialize(response.body, "AsposeResponse"); + return Promise.resolve({body: result, response}); + } + + /** * * @summary Add document page number stamps. @@ -12655,6 +12719,70 @@ export class PdfApi { } + /** + * + * @summary Add document pages text stamps. + * @param name The document name. + * @param stamps The array of stamp. + * @param storage The document storage. + * @param folder The document folder. + * @param password Base64 encoded password. + */ + public async postDocumentTextStamps (name: string, stamps: Array, storage?: string, folder?: string, password?: string) : Promise<{ response: http.IncomingMessage; body: AsposeResponse; }> { + const localVarPath = this.basePath + '/pdf/{name}/stamps/text' + .replace('{' + 'name' + '}', encodeURIComponent(String(name)).replace('%2F', '/')); + let localVarQueryParameters: any = {}; + let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); + let localVarFormParams: any = {}; + + // verify required parameter 'name' is not null or undefined + if (name === null || name === undefined) { + throw new Error('Required parameter name was null or undefined when calling postDocumentTextStamps.'); + } + + // verify required parameter 'stamps' is not null or undefined + if (stamps === null || stamps === undefined) { + throw new Error('Required parameter stamps was null or undefined when calling postDocumentTextStamps.'); + } + + if (storage !== undefined && null !== storage) { + localVarQueryParameters['storage'] = ObjectSerializer.serialize(storage, "string"); + } + + if (folder !== undefined && null !== folder) { + localVarQueryParameters['folder'] = ObjectSerializer.serialize(folder, "string"); + } + + if (password !== undefined && null !== password) { + localVarQueryParameters['password'] = ObjectSerializer.serialize(password, "string"); + } + + + let localVarUseFormData = false; + let fileData = null; + let localVarRequestOptions: localVarRequest.Options = { + method: 'POST', + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + body: ObjectSerializer.serialize(stamps, "Array") + }; + + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; + } else { + localVarRequestOptions.form = localVarFormParams; + } + } + const response = await invokeApiMethod(localVarRequestOptions, this.configuration, false, fileData); + const result = ObjectSerializer.deserialize(response.body, "AsposeResponse"); + return Promise.resolve({body: result, response}); + } + + /** * * @summary Encrypt document in storage. diff --git a/src/auth.ts b/src/auth.ts index ef90456a..e18f3aae 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -82,8 +82,30 @@ export class OAuth implements IAuthentication { }, }; - const response = await invokeApiMethod(requestOptions, configuration, true); - this.accessToken = response.body.access_token; + try { + const response = await invokeApiMethod(requestOptions, configuration, true); + if (!response.body.access_token || response.body.access_token.trim() == "") { + this._handleResponseError(response) + } + + this.accessToken = response.body.access_token; + } + catch(err) { + if (err.response) { + this._handleResponseError(err.response) + } else { + throw err + } + } + return Promise.resolve(); } + + private _handleResponseError(response: request.RequestResponse) { + if (typeof response.body == 'string' && response.body.trim() != '') { + throw new Error(response.body) + } else { + throw new Error(`empty token (${JSON.stringify(response.body)})`) + } + } } diff --git a/src/models/optimizeOptions.ts b/src/models/optimizeOptions.ts index 3765dfb7..b088ff52 100644 --- a/src/models/optimizeOptions.ts +++ b/src/models/optimizeOptions.ts @@ -31,7 +31,7 @@ export class OptimizeOptions { */ 'password': string; /** - * If true page contents will be reused when document is optimized for equal pages. + * If true page contents will be reused when document is optimized for equal pages. LinkDuplcateStreams option must be set to true. */ 'allowReusePageContent': boolean; /** @@ -55,7 +55,7 @@ export class OptimizeOptions { */ 'removeUnusedStreams': boolean; /** - * Make fonts not embedded if set to true. + * Make fonts not embedded if set to true. Unembedding a font means removing the embedded byte stream data of the font included in a PDF document. */ 'unembedFonts': boolean; /** @@ -67,7 +67,7 @@ export class OptimizeOptions { */ 'maxResolution': number; /** - * Fonts will be converted into subsets if set to true. + * Fonts will be converted into subsets if set to true. Only those characters that are actually used in the layout are stored in the PDF. */ 'subsetFonts': boolean; /** diff --git a/src/requestHelper.ts b/src/requestHelper.ts index 4c423d8c..04603ebc 100644 --- a/src/requestHelper.ts +++ b/src/requestHelper.ts @@ -95,7 +95,7 @@ async function invokeApiMethodInternal(requestOptions: request.Options, confgura //headers sa.set("User-Agent", "pdf nodejs sdk"); sa.set("x-aspose-client", "nodejs sdk"); - sa.set("x-aspose-client-version", "24.7.0"); + sa.set("x-aspose-client-version", "24.8.0"); if (!requestOptions.headers) { requestOptions.headers = {}; diff --git a/test/testStamps.ts b/test/testStamps.ts index 71ea5171..d7285717 100644 --- a/test/testStamps.ts +++ b/test/testStamps.ts @@ -121,6 +121,39 @@ describe("Stamps Tests", () => { }); }); + describe("Post Document Text Stamps Test", () => { + + it("should return response with code 200", async () => { + + const textState = new TextState(); + textState.fontSize = 14; + textState.font = 'Arial'; + + const stamp = new TextStamp(); + stamp.background = true; + stamp.leftMargin = 1; + stamp.rightMargin = 2; + stamp.topMargin = 3; + stamp.bottomMargin = 4; + stamp.horizontalAlignment = HorizontalAlignment.Center; + stamp.verticalAlignment = VerticalAlignment.Center; + stamp.opacity = 1; + stamp.rotate = Rotation.None; + stamp.rotateAngle = 0; + stamp.xIndent = 0; + stamp.yIndent = 0; + stamp.zoom = 1; + stamp.textAlignment = HorizontalAlignment.Center; + stamp.value = "Text Stamp"; + stamp.textState = textState; + + return BaseTest.getPdfApi().postDocumentTextStamps(name, [stamp], null, BaseTest.remoteTempFolder) + .then((result) => { + assert.equal(result.response.statusCode, 200); + }); + }); + }); + describe("Post Page Image Stamps Test", () => { it("should return response with code 200", async () => { @@ -151,6 +184,35 @@ describe("Stamps Tests", () => { }); }); + describe("Post Document Image Stamps Test", () => { + + it("should return response with code 200", async () => { + + await BaseTest.uploadFile(imageFile); + + const stamp = new ImageStamp(); + stamp.background = true; + stamp.leftMargin = 1; + stamp.rightMargin = 2; + stamp.topMargin = 3; + stamp.bottomMargin = 4; + stamp.horizontalAlignment = HorizontalAlignment.Center; + stamp.verticalAlignment = VerticalAlignment.Center; + stamp.opacity = 1; + stamp.rotate = Rotation.None; + stamp.rotateAngle = 0; + stamp.xIndent = 0; + stamp.yIndent = 0; + stamp.zoom = 1; + stamp.fileName = BaseTest.remoteTempFolder + '/' + imageFile; + + return BaseTest.getPdfApi().postDocumentImageStamps(name, [stamp], null, BaseTest.remoteTempFolder) + .then((result) => { + assert.equal(result.response.statusCode, 200); + }); + }); + }); + describe("Post Page PdfPage Stamps Test", () => { it("should return response with code 200", async () => {