From c61ec6abaa57c7eae62073af0edb95d971b79b6f Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Tue, 14 Jan 2025 13:36:38 +0100 Subject: [PATCH] Aspose.PDF for Node.js via C++: AsposePdfReplaceTextPages --- english/nodejs-cpp/_index.md | 1 + english/nodejs-cpp/organize/_index.md | 1 + .../asposepdfreplacetextpages/_index.md | 82 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 english/nodejs-cpp/organize/asposepdfreplacetextpages/_index.md diff --git a/english/nodejs-cpp/_index.md b/english/nodejs-cpp/_index.md index 08c1d5541..f0e29ac93 100644 --- a/english/nodejs-cpp/_index.md +++ b/english/nodejs-cpp/_index.md @@ -76,6 +76,7 @@ is_root: true | [AsposePdfAddAttachment](./organize/asposepdfaddattachment/) | Add attachment to a PDF-file. | | [AsposePdfGetAttachment](./organize/asposepdfgetattachment/) | Get attachment from a PDF-file. | | [AsposePdfReplaceText](./organize/asposepdfreplacetext/) | Replace text in a PDF-file. | +| [AsposePdfReplaceTextPages](./organize/asposepdfreplacetextpages/) | Replace text on pages in a PDF-file. | | [AsposePdfFindText](./organize/asposepdffindtext/) | Find text in a PDF-file. | | [AsposePdfReplaceFont](./organize/asposepdfreplacefont/) | Replace font in a PDF-file. | | [AsposePdfValidatePDFA](./organize/asposepdfvalidatepdfa/) | Validate PDF/A compatibility a PDF-file. | diff --git a/english/nodejs-cpp/organize/_index.md b/english/nodejs-cpp/organize/_index.md index cfd89e231..f0076c967 100644 --- a/english/nodejs-cpp/organize/_index.md +++ b/english/nodejs-cpp/organize/_index.md @@ -31,6 +31,7 @@ url: /nodejs-cpp/organize/ | [AsposePdfAddAttachment](./asposepdfaddattachment/) | Add attachment to a PDF-file. | | [AsposePdfGetAttachment](./asposepdfgetattachment/) | Get attachment from a PDF-file. | | [AsposePdfReplaceText](./asposepdfreplacetext/) | Replace text in a PDF-file. | +| [AsposePdfReplaceTextPages](./asposepdfreplacetextpages/) | Replace text on pages in a PDF-file. | | [AsposePdfFindText](./asposepdffindtext/) | Find text in a PDF-file. | | [AsposePdfReplaceFont](./asposepdfreplacefont/) | Replace font in a PDF-file. | | [AsposePdfValidatePDFA](./asposepdfvalidatepdfa/) | Validate PDF/A compatibility a PDF-file. | diff --git a/english/nodejs-cpp/organize/asposepdfreplacetextpages/_index.md b/english/nodejs-cpp/organize/asposepdfreplacetextpages/_index.md new file mode 100644 index 000000000..34d94955a --- /dev/null +++ b/english/nodejs-cpp/organize/asposepdfreplacetextpages/_index.md @@ -0,0 +1,82 @@ +--- +title: "AsposePdfReplaceTextPages" +second_title: Aspose.PDF for Node.js via C++ +description: "Replace text on pages in a PDF-file." +type: docs +url: /nodejs-cpp/organize/asposepdfreplacetextpages/ +--- + +_Replace text on pages in a PDF-file._ + +```js +function AsposePdfReplaceTextPages( + fileName, + findText, + replaceText, + numPages, + fileNameResult +) +``` + +**Parameters**: + +* **fileName** file name +* **findText** text fragment to search +* **replaceText** text fragment to replace +* **numPages** page numbers: + * string, include page numbers with intervals as "7, 20, 22, 30-32, 33, 36-40, 46" + * array, array of page numbers, such as [1,3] + * number, page number as 2 +* **fileNameResult** result file name + +**Return**: + +JSON object + +* **errorCode** - code error (0 no error) +* **errorText** - text error ("" no error) +* **fileNameResult** - result file name + + +**CommonJS**: + +```js +const AsposePdf = require('asposepdfnodejs'); +const pdf_file = 'Aspose.pdf'; +AsposePdf().then(AsposePdfModule => { + const findText = 'Aspose'; + const replaceText = 'ASPOSE'; + + /*string, include number pages with interval: "7, 20, 22, 30-32, 33, 36-40, 46"*/ + /*const numPages = "1-3";*/ + /*array, array of number pages*/ + /*const numPages = [1,3];*/ + /*number, number page*/ + const numPages = 1; + + /*Replace text on first page in a PDF-file and save the "ResultPdfReplaceTextPages.pdf"*/ + const json = AsposePdfModule.AsposePdfReplaceTextPages(pdf_file, findText, replaceText, numPages, "ResultPdfReplaceTextPages.pdf"); + console.log("AsposePdfReplaceTextPages => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); +}); +``` + +**ECMAScript/ES6**: + +```js +import AsposePdf from 'asposepdfnodejs'; +const AsposePdfModule = await AsposePdf(); +const pdf_file = 'Aspose.pdf'; +const findText = 'Aspose'; +const replaceText = 'ASPOSE'; + +/*string, include number pages with interval: "7, 20, 22, 30-32, 33, 36-40, 46"*/ +/*const numPages = "1-3";*/ +/*array, array of number pages*/ +/*const numPages = [1,3];*/ +/*number, number page*/ +const numPages = 1; + +/*Replace text on first page in a PDF-file and save the "ResultPdfReplaceTextPages.pdf"*/ +const json = AsposePdfModule.AsposePdfReplaceTextPages(pdf_file, findText, replaceText, numPages, "ResultPdfReplaceTextPages.pdf"); +console.log("AsposePdfReplaceTextPages => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText); +``` \ No newline at end of file