diff --git a/Examples/deleteImage.js b/Examples/deleteImage.js new file mode 100644 index 00000000..affdfeb7 --- /dev/null +++ b/Examples/deleteImage.js @@ -0,0 +1,27 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "testOutput"; + +async function main() +{ + // Read document images. + const result = await api.getImages(fileName, 1, null, null); + const imageId = result.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/DeleteImage + // Delete image from document page. + const response = await api.deleteImage(fileName, imageId, storage, folder); + console.log(response.body.status); +} + +main(); diff --git a/Examples/getImage.js b/Examples/getImage.js new file mode 100644 index 00000000..5bb48f35 --- /dev/null +++ b/Examples/getImage.js @@ -0,0 +1,28 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "testOutput"; + +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, null, null); + const imageId = imagesResult.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/DeleteImage + // Delete image from document page. + const result = await api.getImage(fileName, imageId, storage, folder); + // todo: parse response + console.log(result.body.status); +} + +main(); diff --git a/Examples/getImageExtractAsGif.js b/Examples/getImageExtractAsGif.js new file mode 100644 index 00000000..3ddfc6ab --- /dev/null +++ b/Examples/getImageExtractAsGif.js @@ -0,0 +1,36 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "testOutput"; + +async function main() +{ + // Read document images. + const result = await api.getImages(fileName, 1, null, null); + const imageId = result.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/GetImageExtractAsJpeg + // Extract document image in PNG format. + const response = await api.getImageExtractAsGif(fileName, imageId, width, heigth, storage, folder); + if (response.response.statusCode == 200) + { + console.log("OK"); + // Write extracted image on disk. + fs.writeFileSync(destFolder + "/" + fileName + ".gif", response.body); + } +} + +main(); diff --git a/Examples/getImageExtractAsJpeg.js b/Examples/getImageExtractAsJpeg.js index 169a17b8..9217bd85 100644 --- a/Examples/getImageExtractAsJpeg.js +++ b/Examples/getImageExtractAsJpeg.js @@ -1,16 +1,36 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/fieldType"); +const fs = require("fs"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "testOutput"; -pdfApi = new PdfApi("XXXX", "XXXXXXX") +async function main() +{ + // Read document images. + const result = await api.getImages(fileName, 1, null, null); + const imageId = result.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/GetImageExtractAsJpeg + // Extract document image in PNG format. + const response = await api.getImageExtractAsJpeg(fileName, imageId, width, heigth, storage, folder); + if (response.response.statusCode == 200) + { + console.log("OK"); + // Write extracted image on disk. + fs.writeFileSync(destFolder + "/" + fileName + ".jpeg", response.body); + } +} -console.log('running example'); - -const result = await pdfApi.getImages("PdfWithImages2.pdf", 1, null, null); -imageId = result.body.images.list[0].id; - -pdfApi.putImageExtractAsJpeg("PdfWithImages2.pdf", imageId, null, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/getImageExtractAsPng.js b/Examples/getImageExtractAsPng.js new file mode 100644 index 00000000..ef991f82 --- /dev/null +++ b/Examples/getImageExtractAsPng.js @@ -0,0 +1,36 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "testOutput"; + +async function main() +{ + // Read document images. + const result = await api.getImages(fileName, 1, null, null); + const imageId = result.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/GetImageExtractAsPng + // Extract document image in PNG format. + const response = await api.getImageExtractAsPng(fileName, imageId, width, heigth, storage, folder); + if (response.response.statusCode == 200) + { + console.log("OK"); + // Write extracted image on disk. + fs.writeFileSync(destFolder + "/" + fileName + ".png", response.body); + } +} + +main(); \ No newline at end of file diff --git a/Examples/getImageExtractAsTiff.js b/Examples/getImageExtractAsTiff.js new file mode 100644 index 00000000..5c4a94db --- /dev/null +++ b/Examples/getImageExtractAsTiff.js @@ -0,0 +1,36 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "testOutput"; + +async function main() +{ + // Read document images. + const result = await api.getImages(fileName, 1, null, null); + const imageId = result.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/GetImageExtractAsJpeg + // Extract document image in PNG format. + const response = await api.getImageExtractAsTiff(fileName, imageId, width, heigth, storage, folder); + if (response.response.statusCode == 200) + { + console.log("OK"); + // Write extracted image on disk. + fs.writeFileSync(destFolder + "/" + fileName + ".tiff", response.body); + } +} + +main(); diff --git a/Examples/getImages.js b/Examples/getImages.js index b6cb843b..90f12147 100644 --- a/Examples/getImages.js +++ b/Examples/getImages.js @@ -1,16 +1,21 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/freeTextAnnotation"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; -pdfApi = new PdfApi("XXXX", "XXXXXXX") +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/GetImages + // Read document images. + const result = await api.getImages(fileName, 1, storage, folder); + console.log(result.body.status); +} -console.log('running example'); - -pdfApi.getImages("PdfWithImages2.pdf", 1, null, null); -const imageId = result.body.images.list[0].id; - -pdfApi.getImage("PdfWithImages2.pdf", imageId, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/getPageConvertToPng.js b/Examples/getPageConvertToPng.js index 00e0a2e3..5cdae37a 100644 --- a/Examples/getPageConvertToPng.js +++ b/Examples/getPageConvertToPng.js @@ -1,15 +1,37 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/movieAnnotation"); +const fs = require("fs"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); +// Set the document name. +const fileName = "4pages.pdf"; +// Set the page number. +const pageNumber = 1; +// Set the width of coverted image. +const width = (595 / 2) | 0; +// Set the heigth of coverted image. +const heigth = (842 / 2) | 0; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set no password. +const password = null; +// Set an extracted image folder. +const destFolder = "testOutput"; -pdfApi = new PdfApi("XXXX", "XXXXXXX") +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Pages/GetPageConvertToPng + // Convert document page to Png image and return resulting file in response.. + const response = await api.getPageConvertToPng(fileName, pageNumber, width, heigth, folder, storage, password); + if (response.response.statusCode == 200) + { + console.log("OK"); + // Write extracted image on disk. + fs.writeFileSync(destFolder + "/" + fileName + ".png", response.body); + } +} -console.log('running example'); - - - -pdfApi.getPageConvertToPng("4pages.pdf", 1, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/getPageText.js b/Examples/getPageText.js index 592ff66d..a8e9596a 100644 --- a/Examples/getPageText.js +++ b/Examples/getPageText.js @@ -1,19 +1,50 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/stamp"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi("XXXX", "XXXXXXX") - -console.log('running example'); -const name = "4pages.pdf"; -const x = 0; -const y = 0; -const width = 0; -const height = 0; +// Set the document name. +const fileName = "4pages.pdf"; +// Set the page number. const pageNumber = 1; +// Set the X-coordinate of lower-left corner. +const llx = 0; +// Set an Y-coordinate of lower-left corner. +const lly = 0; +// Set the X-coordinate of upper-right corner. +const urx = 0; +// Set an Y-coordinate of upper-right corner. +const ury = 0; +// Set list of formats for search. const format = ["First Page", "Second Page"]; +// Set formats are specified as a regular expression. +const regex = null; +// Set split result fragments (default is true). +const splitRects = true; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Text/GetPageText + // Read page text items. + const result = await api.getPageText( + fileName, + pageNumber, + llx, + lly, + urx, + ury, + format, + regex, + splitRects, + folder, + storage); + + // todo: parse response + console.log(result.body.status); +} -pdfApi.getPageText(name, pageNumber, x, y, width, height, format, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/getPdfInStorageToDoc.js b/Examples/getPdfInStorageToDoc.js index c1f9410e..532a582c 100644 --- a/Examples/getPdfInStorageToDoc.js +++ b/Examples/getPdfInStorageToDoc.js @@ -1,12 +1,59 @@ const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); -pdfApi = new PdfApi( - "78946fb4-3bd4-4d3e-b309-f9e2ff9ac6f9", "b125f13bf6b76ed81ee990142d841195") +const fileName = "28968-1.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -console.log('running example'); +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/docsaveoptions/ +// Use paragraph instead of line breaks. +const addReturnToLineEndings = true; +// Convert to doc format (default value). +const format = "doc"; +// Converted images X resolution default value is 300. +const imageResolutionX = 300; +// Converted images Y resolution default value is 300. +const imageResolutionY = 300; +// Specified in hundreds of percent of the text lines height. +const maxDistanceBetweenLines = 10; +// This mode is fast and good for maximally preserving original look of the PDF file. +const mode = "Textbox"; +// Recognition of bullets. +const recognizeBullets = true; +// It's normed to font size - 1.0 means 100% of supposed word's font size +const relativeHorizontalProximity = 1.0; +// Set root folder. +const folder = null; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; -pdfApi.getPdfInStorageToDoc(simplePdf, null, null, null, null, null, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/GetPdfInStorageToDoc + // Converts PDF document (located on storage) to DOC format and returns resulting file in response content. + const result = await api.getPdfInStorageToDoc(fileName, + addReturnToLineEndings, + format, + imageResolutionX, + imageResolutionY, + maxDistanceBetweenLines, + mode, + recognizeBullets, + relativeHorizontalProximity, + folder, + storage, + password); + + if (result.response.statusCode == 200) + { + console.log("OK"); + // Write extracted image on disk. + fs.writeFileSync("testOutput/" + fileName + "." + format, result.body); + } +} + +main(); \ No newline at end of file diff --git a/Examples/getPdfInStorageToPptx.js b/Examples/getPdfInStorageToPptx.js new file mode 100644 index 00000000..3e36038e --- /dev/null +++ b/Examples/getPdfInStorageToPptx.js @@ -0,0 +1,40 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "4pages.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/pptxsaveoptions/ + +// If set to true then images are separated from all other graphics +const separateImages = true; +// If set to true then all the content is recognized as images (one per page). +const slidesAsImages = false; +// Set root folder. +const folder = null; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/GetPdfInStorageToPptx + // Converts PDF document (located on storage) to PPTX format and returns resulting file in response content + const result = await api.getPdfInStorageToPptx(fileName, + separateImages, + slidesAsImages, + folder, + storage, + password); + + if (result.response.statusCode == 200) + { + fs.writeFileSync("testOutput/" + fileName + ".pptx", result.body) + console.log("OK"); + } +} + +main(); \ No newline at end of file diff --git a/Examples/getPdfInStorageToXls.js b/Examples/getPdfInStorageToXls.js new file mode 100644 index 00000000..1c433b01 --- /dev/null +++ b/Examples/getPdfInStorageToXls.js @@ -0,0 +1,46 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "4pages.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/excelsaveoptions/ + +// Insert blank column at first. +const insertBlankColumnAtFirst = true; +// Save of each PDF page as separated worksheet. +const minimizeTheNumberOfWorksheets = false; +// Obsolete. +const scaleFactor = null; +// Columns division will independent for each page. +const uniformWorksheets = true; +// Set root folder. +const folder = null; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/GetPdfInStorageToXls + // Converts PDF document (located on storage) to XLS format and returns resulting file in response content + const result = await api.getPdfInStorageToXls(fileName, + insertBlankColumnAtFirst, + minimizeTheNumberOfWorksheets, + scaleFactor, + uniformWorksheets, + folder, + storage, + password); + + if (result.response.statusCode == 200) + { + fs.writeFileSync("testOutput/" + fileName + ".xls", result.body) + console.log("OK"); + } +} + +main(); \ No newline at end of file diff --git a/Examples/getPdfInStorageToXlsx.js b/Examples/getPdfInStorageToXlsx.js new file mode 100644 index 00000000..8333c80d --- /dev/null +++ b/Examples/getPdfInStorageToXlsx.js @@ -0,0 +1,46 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "PdfWithImages2.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/excelsaveoptions/ + +// Insert blank column at first. +const insertBlankColumnAtFirst = true; +// Save of each PDF page as separated worksheet. +const minimizeTheNumberOfWorksheets = false; +// Obsolete. +const scaleFactor = null; +// Columns division will independent for each page. +const uniformWorksheets = true; +// Set root folder. +const folder = null; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/GetPdfInStorageToXlsx + // Converts PDF document (located on storage) to XLSX format and returns resulting file in response content + const result = await api.getPdfInStorageToXlsx(fileName, + insertBlankColumnAtFirst, + minimizeTheNumberOfWorksheets, + scaleFactor, + uniformWorksheets, + folder, + storage, + password); + + if (result.response.statusCode == 200) + { + fs.writeFileSync("testOutput/" + fileName + ".xlsx", result.body) + console.log("OK"); + } +} + +main(); \ No newline at end of file diff --git a/Examples/getText.js b/Examples/getText.js index 773e237d..fdeecd70 100644 --- a/Examples/getText.js +++ b/Examples/getText.js @@ -1,20 +1,47 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/stamp"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); +// The document name. +const fileName = "4pages.pdf"; +// X-coordinate of lower-left corner. +const llx = 0; +// Y-coordinate of lower-left corner. +const lly = 0; +// X-coordinate of upper-right corner. +const urx = 0; +// Y-coordinate of upper-right corner. +const ury = 0; +// List of formats for search. +const format = []; +// Formats are specified as a regular expression. +const regex = null; +// Split result fragments (default is true). +const splitRects = true; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Text/GetText + // Read document text. + const result = await api.getText( + fileName, + llx, + lly, + urx, + ury, + format, + regex, + splitRects, + folder, + storage); -pdfApi = new PdfApi("XXXX", "XXXXXXX") + // todo: parse response + console.log(result.body.status); +} -console.log('running example'); - -const name = "4pages.pdf"; -const x = 0; -const y = 0; -const width = 0; -const height = 0; - -pdfApi.getText(name, x, y, width, height, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/getXmpMetadataJson.js b/Examples/getXmpMetadataJson.js new file mode 100644 index 00000000..5eb7be51 --- /dev/null +++ b/Examples/getXmpMetadataJson.js @@ -0,0 +1,30 @@ +// Import the necessary class from the Aspose PDF Cloud SDK +const { PdfApi } = require("asposepdfcloud"); + +// Create an instance of the PdfApi with the base URL +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Set the document name (the PDF file you want to retrieve metadata from) +const fileName = "example.pdf"; // Replace with your PDF file name +// Set the folder where the document is stored (if applicable) +const folder = "Documents"; // Replace with your folder name if applicable +// Optional parameters +const storage = null; // Specify storage name if using a specific storage +const password = null; // Specify the password if the document is password-protected + +// Main function to execute the API call +async function main() { + try { + // Call the getXmpMetadataJson method to retrieve the XMP metadata + const result = await api.getXmpMetadataJson(fileName, folder, storage, password); + + // Log the retrieved XMP metadata + console.log("XMP Metadata:", result.body); + } catch (error) { + // Handle any errors that occur during the API call + console.error("Error retrieving XMP metadata:", error); + } +} + +// Execute the main function +main(); diff --git a/Examples/getXmpMetadataXml.js b/Examples/getXmpMetadataXml.js new file mode 100644 index 00000000..34a51fd3 --- /dev/null +++ b/Examples/getXmpMetadataXml.js @@ -0,0 +1,30 @@ +// Import the necessary class from the Aspose PDF Cloud SDK +const { PdfApi } = require("asposepdfcloud"); + +// Create an instance of the PdfApi with the base URL +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Set the document name (the PDF file you want to retrieve metadata from) +const fileName = "example.pdf"; // Replace with your PDF file name +// Set the folder where the document is stored (if applicable) +const folder = "Documents"; // Replace with your folder name if applicable +// Optional parameters +const storage = null; // Specify storage name if using a specific storage +const password = null; // Specify the password if the document is password-protected + +// Main function to execute the API call +async function main() { + try { + // Call the getXmpMetadataJson method to retrieve the XMP metadata + const result = await api.getXmpMetadataXml(fileName, folder, storage, password); + + // Log the retrieved XMP metadata + console.log("XMP Metadata:", result.body); + } catch (error) { + // Handle any errors that occur during the API call + console.error("Error retrieving XMP metadata:", error); + } +} + +// Execute the main function +main(); diff --git a/Examples/postDocumentTextReplace.js b/Examples/postDocumentTextReplace.js index 9f11cbf5..c2070c7a 100644 --- a/Examples/postDocumentTextReplace.js +++ b/Examples/postDocumentTextReplace.js @@ -1,20 +1,110 @@ const { PdfApi } = require("asposepdfcloud"); -const { TextReplaceListRequest } = require("asposepdfcloud/src/models/textReplace"); +const { TextState } = require("asposepdfcloud/src/models/textState"); +const { FontStyles } = require("asposepdfcloud/src/models/fontStyles"); +const { Color } = require("asposepdfcloud/src/models/color"); +const { TextReplace } = require("asposepdfcloud/src/models/textReplace"); +const { Rectangle } = require("asposepdfcloud/src/models/rectangle"); +const { TextReplaceListRequest } = require("asposepdfcloud/src/models/textReplaceListRequest"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi("XXXX", "XXXXXXX") +// Set the document name. +const fileName = "4pages.pdf"; +// Represents color DTO. +const color = new Color +{ + // Set an alpha component. + a = 0, + // Set the red component. + r = 255, + // Set the green component. + g = 255, + // Set the blue component. + b = 255 +}; +// Represents a text state of a text +const textState = new TextState +{ + // Set font size of the text. + fontSize = 14; + // Set font name of the text. + font = "Arial"; + // Set foreground color of the text. + foregroundColor = color; + // Set background color of the text. + backgroundColor = color; + // Set font style of the text. + fontStyle = FontStyles.Regular; + // Set path of font file in storage. + fontFile = ""; + // Set underline of the text. + underline = true; + // Set strikeout of the text. + strikeOut = false; + // Set superscript mode of the text. + superscript = false; + // Set subscript mode of the text. + subscript = false; +}; +// Represents rectangle DTO. +const rect = new Rectangle +{ + // Set the X-coordinate of lower-left corner. + lLX = 0; + // Set the Y-coordinate of lower-left corner. + lLY = 0; + // Set the X-coordinate of upper-right corner. + uRX = 400; + // Set the Y-coordinate of upper-right corner. + uRY = 400; +}; +// Single text replacement setting. +const textReplace = new TextReplace +{ + // Set an original text. + oldValue = "Page", + // Set the new text. + newValue = "Replacement", + // Set a value indicating whether search text is regular expression. + regex = false, + // Set the text properties of a new text. + textState = textState, + // Set the rectangle area where searched original text. + rect = rect, + // Set the text after replacement is centered horizontally relative to the text being replaced. + centerTextHorizontally = true +}; +// Multiple text replacements request. +const textReplaceList = new TextReplaceListRequest +{ + // Set the list of text replacement settings. + textReplaces = [ textReplace ], + // Set the name of font to use if requested font is not embedded into document. + defaultFont = "Arial"; + // Set the index of first match to be replaced. + startIndex = 0; + // Set the number of matches to be replaced. + countReplace = 5; -console.log('running example'); +}; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/TextReplace/PostDocumentTextReplace + // Document's replace text method. + const result = await api.postDocumentTextReplace( + fileName, + textReplaceList, + storage, + folder); -const name = "4pages.pdf"; -const trr = new TextReplaceListRequest(); -trr.textReplaces = [textReplace]; -trr.startIndex = 0; -trr.countReplace = 0; + // todo: parse response + console.log(result.body.status); +} - -pdfApi.postDocumentTextReplace(name, trr, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/postInsertImage.js b/Examples/postInsertImage.js index 2e52fb42..0213c794 100644 --- a/Examples/postInsertImage.js +++ b/Examples/postInsertImage.js @@ -1,17 +1,46 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/freeTextAnnotation"); - - -pdfApi = new PdfApi("XXXX", "XXXXXXX") - -console.log('running example'); - - -const imageName = "Koala.jpg"; - - -pdfApi.postInsertImage("4pages.pdf", 2, 10, 10, 100, 100, imageName, null, null) - .then((result) => { - console.log(result.response); -}); \ No newline at end of file +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "4pages.pdf"; +// Path to image file in storage. Image content is used otherwise. +const imageFilePath = "Koala.jpg"; +// Set page number to insert an image to. +const pageNumber = 1; +// Set left bottom x coordinate of an image. +const llx = 10; +// Set left bottom y coordinate of an image. +const lly = 10; +// Set right upper x coordinate of an image. +const urx = 100; +// Set right upper y coordinate of an image. +const ury = 100; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set image buffer. +const imageContent = null + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PostInsertImage + // Insert image to document page. + const result = await api.postInsertImage( + fileName, + pageNumber, + llx, + lly, + urx, + ury, + imageFilePath, + storage, + folder, + null); + // todo: parse response + console.log(result.body.status); +} + +main(); diff --git a/Examples/postPageTextReplace.js b/Examples/postPageTextReplace.js new file mode 100644 index 00000000..45fe68fa --- /dev/null +++ b/Examples/postPageTextReplace.js @@ -0,0 +1,110 @@ +const { PdfApi } = require("asposepdfcloud"); +const { TextState } = require("asposepdfcloud/src/models/textState"); +const { FontStyles } = require("asposepdfcloud/src/models/fontStyles"); +const { Color } = require("asposepdfcloud/src/models/color"); +const { TextReplace } = require("asposepdfcloud/src/models/textReplace"); +const { Rectangle } = require("asposepdfcloud/src/models/rectangle"); +const { TextReplaceListRequest } = require("asposepdfcloud/src/models/textReplaceListRequest"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Set the document name. +const fileName = "4pages.pdf"; +// Represents color DTO. +const color = new Color +{ + // Set an alpha component. + A = 0, + // Set the red component. + R = 255, + // Set the green component. + G = 255, + // Set the blue component. + B = 255 +}; +// Represents a text state of a text +const textState = new TextState +{ + // Set font size of the text. + fontSize = 14; + // Set font name of the text. + font = "Arial"; + // Set foreground color of the text. + foregroundColor = color; + // Set background color of the text. + backgroundColor = color; + // Set font style of the text. + fontStyle = FontStyles.Regular; + // Set path of font file in storage. + fontFile = null; + // Set underline of the text. + underline = true; + // Set strikeout of the text. + strikeOut = false; + // Set superscript mode of the text. + superscript = false; + // Set subscript mode of the text. + subscript = false; +}; +// Represents rectangle DTO. +const rect = new Rectangle +{ + // Set the X-coordinate of lower-left corner. + lLX = 0; + // Set the Y-coordinate of lower-left corner. + lLY = 0; + // Set the X-coordinate of upper-right corner. + uRX = 400; + // Set the Y-coordinate of upper-right corner. + uRY = 400; +}; +// Single text replacement setting. +const textReplace = new TextReplace +{ + // Set an original text. + oldValue = "Page", + // Set the new text. + newValue = "Replacement", + // Set a value indicating whether search text is regular expression. + regex = false, + // Set the text properties of a new text. + textState = textState, + // Set the rectangle area where searched original text. + rect = rect, + // Set the text after replacement is centered horizontally relative to the text being replaced. + centerTextHorizontally = true +}; +// Multiple text replacements request. +const textReplaceList = new TextReplaceListRequest +{ + // Set the list of text replacement settings. + textReplaces = [ textReplace ], + // Set the name of font to use if requested font is not embedded into document. + defaultFont = "Arial"; + // Set the index of first match to be replaced. + startIndex = 0; + // Set the number of matches to be replaced. + countReplace = 5; + +}; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/TextReplace/PostPageTextReplace + // Page's replace text method. + const result = await api.postPageTextReplace( + fileName, + textReplaceList, + storage, + folder); + + // todo: parse response + console.log(result.body.status); +} + +main(); diff --git a/Examples/postPdfToXlsx.js b/Examples/postPdfToXlsx.js new file mode 100644 index 00000000..acd845ad --- /dev/null +++ b/Examples/postPdfToXlsx.js @@ -0,0 +1,38 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "PdfWithImages2.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/excelsaveoptions/ + +// Insert blank column at first. +const insertBlankColumnAtFirst = true; +// Save of each PDF page as separated worksheet. +const minimizeTheNumberOfWorksheets = false; +// Columns division will independent for each page. +const uniformWorksheets = true; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PostPdfToXlsx + // Converts PDF document (in request content) to XLSX format and uploads and returns resulting file in response content. + const result = await api.postPdfToXlsx( + insertBlankColumnAtFirst, + minimizeTheNumberOfWorksheets, + uniformWorksheets, + password, + fs.readFileSync("testData/" + fileName)); + + if (result.response.statusCode == 200) + { + fs.writeFileSync("testOutput/" + fileName + ".xlsx", result.body) + console.log("OK"); + } +} + +main(); \ No newline at end of file diff --git a/Examples/postSplitRangePdfDocument.js b/Examples/postSplitRangePdfDocument.js new file mode 100644 index 00000000..c70dc0b9 --- /dev/null +++ b/Examples/postSplitRangePdfDocument.js @@ -0,0 +1,24 @@ +const { PdfApi } = require("asposepdfcloud"); +const { SplitRangePdfOptions } = require("asposepdfcloud/src/models/splitRangePdfOptions"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Set the document name. +const fileName = "4pages.pdf"; +// +const options = new SplitRangePdfOptions(); +options. +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set no password. +const password = null; + +async function main() +{ + const result = await api.postSplitRangePdfDocument(fileName, null, storage, folder, password); + console.log(result.body.status); +} + +main(); \ No newline at end of file diff --git a/Examples/postXmpMetadata.js b/Examples/postXmpMetadata.js new file mode 100644 index 00000000..ca1a6bc2 --- /dev/null +++ b/Examples/postXmpMetadata.js @@ -0,0 +1,101 @@ +// Import the necessary class from the Aspose PDF Cloud SDK +const { PdfApi } = require("asposepdfcloud"); +const { XmpMetadata } = require("asposepdfcloud/src/models/xmpMetadata"); +const { XmpMetadataProperty } = require("asposepdfcloud/src/models/xmpMetadataProperty"); + +// Create an instance of the PdfApi with the base URL +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Set the document name (the PDF file you want to retrieve metadata from) +const fileName = "example.pdf"; // Replace with your PDF file name +// Set the folder where the document is stored (if applicable) +const folder = "Documents"; // Replace with your folder name if applicable +// Optional parameters +const storage = null; // Specify storage name if using a specific storage +const password = null; // Specify the password if the document is password-protected + +// Initialize properties using empty constructors + +// Property for ModifyDate +const modifyDateProperty = new XmpMetadataProperty(); +// Set the key +modifyDateProperty.Key = "ModifyDate"; +// Set the value to the predefined date +modifyDateProperty.Value = date; + +// Property for xmp:CreateDate +const createDateProperty = new XmpMetadataProperty(); +// Set the key +createDateProperty.Key = "xmp:CreateDate"; +// Set the value to the predefined date +createDateProperty.Value = date; + +// Property for CreatorTool (to be removed) +const creatorToolProperty = new XmpMetadataProperty(); +// Set the key +creatorToolProperty.Key = "CreatorTool"; +// Value is null (indicating removal) +creatorToolProperty.Value = null; + +// Property for BaseURL +const baseUrlProperty = new XmpMetadataProperty(); +// Set the key +baseUrlProperty.Key = "BaseURL"; +// Set the value to a URL +baseUrlProperty.Value = "http://www.somename.com/path"; + +// Property for dc:title (to be removed) +const dcTitleProperty = new XmpMetadataProperty(); +// Set the key +dcTitleProperty.Key = "dc:title"; +// Value is null (indicating removal) +dcTitleProperty.Value = null; + +// Property for pdf:Producer +const pdfProducerProperty = new XmpMetadataProperty(); +// Set the key +pdfProducerProperty.Key = "pdf:Producer"; +// Set the value +pdfProducerProperty.Value = "Aspose.PDF Cloud"; +// Set the namespace URI +pdfProducerProperty.NamespaceUri = "http://ns.adobe.com/pdf/1.3/"; + +// Property for pdf:Prop +const pdfPropProperty = new XmpMetadataProperty(); +// Set the key +pdfPropProperty.Key = "pdf:Prop"; +// Set the value +pdfPropProperty.Value = "PropValue"; +// Set the namespace URI +pdfPropProperty.NamespaceUri = "http://ns.adobe.com/pdf/1.3/"; + +// Create an instance of XmpMetadata +const xmpMetadata = new XmpMetadata() +{ + properties = [ + modifyDateProperty, + createDateProperty, + creatorToolProperty, + baseUrlProperty, + dcTitleProperty, + pdfProducerProperty, + pdfPropProperty + ] +}; + +// Main function to execute the API call +async function main() { + try { + // Call the getXmpMetadataJson method to retrieve the XMP metadata + const result = await api.postXmpMetadata(fileName, xmpMetadata, folder, storage, password); + + // Log the retrieved XMP metadata + console.log(result.body.status); + } catch (error) { + // Handle any errors that occur during the API call + console.error("Error retrieving XMP metadata:", error); + } +} + +// Execute the main function +main(); diff --git a/Examples/putAddText.js b/Examples/putAddText.js index 9334d221..ff52f2d0 100644 --- a/Examples/putAddText.js +++ b/Examples/putAddText.js @@ -1,48 +1,130 @@ +// Import necessary classes from the Aspose PDF Cloud library const { PdfApi } = require("asposepdfcloud"); +const { Color } = require("asposepdfcloud/src/models/color"); +const { FontStyles } = require("asposepdfcloud/src/models/fontStyles"); +const { LineSpacing } = require("asposepdfcloud/src/models/lineSpacing"); const { Paragraph } = require("asposepdfcloud/src/models/paragraph"); +const { TextHorizontalAlignment } = require("asposepdfcloud/src/models/textHorizontalAlignment"); +const { VerticalAlignment } = require("asposepdfcloud/src/models/verticalAlignment"); +const { WrapMode } = require("asposepdfcloud/src/models/wrapMode"); +// Create an instance of the PdfApi with the base URL +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi("XXXX", "XXXXXXX") - -console.log('running example'); - - -const paragraph = new Paragraph(); -paragraph.rectangle = { lLX: 100, lLY: 100, uRX: 200, uRY: 200 }; -paragraph.leftMargin = 10; -paragraph.rightMargin = 10; -paragraph.topMargin = 20; -paragraph.bottomMargin = 20; -paragraph.horizontalAlignment = TextHorizontalAlignment.FullJustify; -paragraph.lineSpacing = LineSpacing.FontSize; -paragraph.rotation = 10; -paragraph.subsequentLinesIndent = 20; -paragraph.verticalAlignment = VerticalAlignment.Center; -paragraph.wrapMode = WrapMode.ByWords; - -paragraph.lines = [ +// Set the document name +const fileName = "4pages.pdf"; +// Set the page number where the text will be added +const pageNumber = 3; +// Represents color DTO. +const color = new Color +{ + // Set an alpha component. + a = 0, + // Set the red component. + r = 255, + // Set the green component. + g = 255, + // Set the blue component. + b = 255 +}; +// Create a new paragraph object to represent text paragraphs +const paragraph = new Paragraph() +{ + // Set the line spacing mode to FullSize + lineSpacing = LineSpacing.FullSize, + // Set the word wrap mode to wrap by words + wrapMode = WrapMode.ByWords, + // Set the horizontal alignment for the text inside the paragraph + horizontalAlignment = TextHorizontalAlignment.FullJustify, + // Set the left margin for the paragraph + leftMargin = 10, + // Set the right margin for the paragraph + rightMargin = 10, + // Set the top margin for the paragraph + topMargin = 20, + // Set the bottom margin for the paragraph + bottomMargin = 20, + // Define the rectangle area for the paragraph + rectangle = { - horizontalAlignment: TextHorizontalAlignment.Right, - segments: [ - { - value: "segment 1", - textState: { - font: "Arial", - fontSize: 10, - foregroundColor: { a: 0x00, r: 0x00, g: 0xFF, b: 0x00 }, - backgroundColor: { a: 0x00, r: 0xFF, g: 0x00, b: 0x00 }, - fontStyle: FontStyles.Bold + // Lower left x coordinate + lLX: 100, + // Lower left y coordinate + lLY: 100, + // Upper right x coordinate + uRX: 200, + // Upper right y coordinate + uRY: 200 + }, + // Set the rotation angle of the text in degrees + rotation = 10, + // Set the indent for subsequent lines + subsequentLinesIndent = 20, + // Set the vertical alignment for the text inside the paragraph + verticalAlignment = VerticalAlignment.Center, + // Define an array of text lines for the paragraph + lines = + [ + { + // Set the line's horizontal alignment to Right + horizontalAlignment: TextHorizontalAlignment.Right, + // Define the segments that form the line + segments: + [ + { + // Text value for the segment + value: "segment 1", + // Define the text state for formatting + textState: + { + // Set font size of the text + fontSize: 14, + // Set font name of the text + font: "Arial", + // Set foreground color of the text + foregroundColor: color, + // Set background color of the text + backgroundColor: color, + // Set font style of the text + fontStyle: FontStyles.Regular, + // Font file path in storage (null means default font) + fontFile: null, + // Set underline for the text + underline: true, + // Set strikeout for the text + strikeOut: false, + // Set superscript mode for the text + superscript: false, + // Set subscript mode for the text + subscript: false + } } - } - ] - } -]; + ] + } + ] +} -const pageNumber = 3; -const name = "4pages.pdf"; +// Use default storage (null indicates default storage) +const storage = null; +// Set the folder where the document is stored +const folder = "Documents"; + +// Main function to execute the API call +async function main() +{ + // Reference to the Swagger method for adding text + // Available at: https://reference.aspose.cloud/pdf/#/Text/PutAddText + // Call the API to add text to the specified PDF document page + const result = await api.putAddText( + fileName, + pageNumber, + paragraph, + folder, + storage); -pdfApi.putAddText(name, pageNumber, paragraph, null) - .then((result) => { - console.log(result.response); + // TODO: Parse the response to handle the result + console.log(result.body.status); // Log the status of the operation +} - }); \ No newline at end of file +// Execute the main function +main(); diff --git a/Examples/putImageExtractAsGif.js b/Examples/putImageExtractAsGif.js new file mode 100644 index 00000000..4a88b0c1 --- /dev/null +++ b/Examples/putImageExtractAsGif.js @@ -0,0 +1,38 @@ +const { PdfApi } = require("asposepdfcloud"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "Images"; + +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, storage, folder); + const imageId = imagesResult.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImageExtractAsGif + // Extract document image in GIF format to folder. + const result = await api.putImageExtractAsGif( + fileName, + imageId, + width, + heigth, + storage, + folder, + destFolder); + + console.log(result.body.status) +} + +main(); diff --git a/Examples/putImageExtractAsJpeg.js b/Examples/putImageExtractAsJpeg.js index 46b734a8..ebf9cc56 100644 --- a/Examples/putImageExtractAsJpeg.js +++ b/Examples/putImageExtractAsJpeg.js @@ -1,16 +1,38 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/fieldType"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi("XXXX", "XXXXXXX") +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "Images"; -console.log('running example'); +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, storage, folder); + const imageId = imagesResult.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImageExtractAsJpeg + // Extract document image in JPEG format to folder. + const result = await api.putImageExtractAsJpeg( + fileName, + imageId, + width, + heigth, + storage, + folder, + destFolder); + console.log(result.body.status) +} -const result = await BaseTest.getPdfApi().getImages("PdfWithImages2.pdf", 1, null, null); -imageId = result.body.images.list[0].id; - -pdfApi.putImageExtractAsJpeg("PdfWithImages2.pdf", imageId, null, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/putImageExtractAsPng.js b/Examples/putImageExtractAsPng.js new file mode 100644 index 00000000..3b921e95 --- /dev/null +++ b/Examples/putImageExtractAsPng.js @@ -0,0 +1,38 @@ +const { PdfApi } = require("asposepdfcloud"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "Images"; + +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, storage, folder); + const imageId = imagesResult.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImageExtractAsPng + // Extract document image in PNG format to folder. + const result = await api.putImageExtractAsPng( + fileName, + imageId, + width, + heigth, + storage, + folder, + destFolder); + + console.log(result.body.status) +} + +main(); diff --git a/Examples/putImageExtractAsTiff.js b/Examples/putImageExtractAsTiff.js new file mode 100644 index 00000000..dd196958 --- /dev/null +++ b/Examples/putImageExtractAsTiff.js @@ -0,0 +1,38 @@ +const { PdfApi } = require("asposepdfcloud"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Width of coverted image. +const width = 100; +// Heigth of coverted image. +const heigth = 100; +// Set document folder. +const folder = "Documents"; +// Set extracted image folder. +const destFolder = "Images"; + +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, storage, folder); + const imageId = imagesResult.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImageExtractAsTiff + // Extract document image in TIFF format to folder. + const result = await api.putImageExtractAsTiff( + fileName, + imageId, + width, + heigth, + storage, + folder, + destFolder); + + console.log(result.body.status) +} + +main(); diff --git a/Examples/putImageInStorageToPdf.js b/Examples/putImageInStorageToPdf.js new file mode 100644 index 00000000..5dd1bbce --- /dev/null +++ b/Examples/putImageInStorageToPdf.js @@ -0,0 +1,56 @@ +const { PdfApi } = require("asposepdfcloud"); +const { ImageSrcType } = require("asposepdfcloud/src/models/imageSrcType"); +const { ImageTemplate } = require("asposepdfcloud/src/models/imageTemplate"); +const { ImageTemplatesRequest } = require("asposepdfcloud/src/models/imageTemplatesRequest"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Use default storage. +const storage = null; +// Set extracted image folder. +const destFolder = "Images"; +// Initialize image template. +const imageTemplate1 = new ImageTemplate +{ + // Set path to image. + imagePath = "testData/33539.jpg", + // Set image src type. + imageSrcType = ImageSrcType.Common +}; +const imageTemplate2 = new ImageTemplate +{ + // Set path to image. + imagePath = "testData/44781.jpg", + // Set image src type. + imageSrcType = ImageSrcType.Common +}; +// Initialize image template request. +const imageTemplatesRequest = new ImageTemplatesRequest +{ + // Use ocr. + isOCR = true, + // Set language for ocr procedure. + oCRLangs = "eng", + // Image templates. + imagesList = [ imageTemplate1, imageTemplate2 ] +}; + +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, storage, folder); + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutImageInStorageToPdf + // Convert image file (located on storage) to PDF format and upload resulting file to storage. + const result = await api.putImageInStorageToPdf( + fileName, + imageTemplatesRequest, + destFolder, + storage); + + console.log(result.body.status) +} + +main(); diff --git a/Examples/putImagesExtractAsGif.js b/Examples/putImagesExtractAsGif.js index 2d87e105..6dcc009c 100644 --- a/Examples/putImagesExtractAsGif.js +++ b/Examples/putImagesExtractAsGif.js @@ -1,14 +1,37 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/fieldType"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi( - "78946fb4-3bd4-4d3e-b309-f9e2ff9ac6f9", "b125f13bf6b76ed81ee990142d841195") +// Set the document name. +const fileName = "PdfWithImages2.pdf"; +// Set the page number. +const pageNumber = 1; +// Use default storage. +const storage = null; +// Set the width of coverted image. +const width = 100; +// Set the heigth of coverted image. +const heigth = 100; +// Set the document folder. +const folder = "Documents"; +// Set an extracted image folder. +const destFolder = "Images"; -console.log('running example'); +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImagesExtractAsGif + // Extract document images in GIF format to folder. + const response = await api.putImagesExtractAsGif( + fileName, + pageNumber, + width, + heigth, + storage, + folder, + destFolder); + console.log(response.body.status) +} -pdfApi.putImagesExtractAsGif("PdfWithImages2.pdf", 1, null, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/putImagesExtractAsJpeg.js b/Examples/putImagesExtractAsJpeg.js index 4d8f9a0e..27288d5b 100644 --- a/Examples/putImagesExtractAsJpeg.js +++ b/Examples/putImagesExtractAsJpeg.js @@ -1,13 +1,37 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/freeTextAnnotation"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi( - "78946fb4-3bd4-4d3e-b309-f9e2ff9ac6f9", "b125f13bf6b76ed81ee990142d841195") +// Set the document name. +const fileName = "PdfWithImages2.pdf"; +// Set the page number. +const pageNumber = 1; +// Use default storage. +const storage = null; +// Set the width of coverted image. +const width = 100; +// Set the heigth of coverted image. +const heigth = 100; +// Set the document folder. +const folder = "Documents"; +// Set an extracted image folder. +const destFolder = "Images"; -console.log('running example'); +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImagesExtractAsJpeg + // Extract document images in JPEG format to folder. + const response = await api.putImagesExtractAsJpeg( + fileName, + pageNumber, + width, + heigth, + storage, + folder, + destFolder); -pdfApi.putImagesExtractAsJpeg("PdfWithImages2.pdf", 1, null, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file + console.log(response.body.status) +} + +main(); diff --git a/Examples/putImagesExtractAsPng.js b/Examples/putImagesExtractAsPng.js index 893fadbd..47733087 100644 --- a/Examples/putImagesExtractAsPng.js +++ b/Examples/putImagesExtractAsPng.js @@ -1,14 +1,37 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/fieldType"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi( - "78946fb4-3bd4-4d3e-b309-f9e2ff9ac6f9", "b125f13bf6b76ed81ee990142d841195") +// Set the document name. +const fileName = "PdfWithImages2.pdf"; +// Set the page number. +const pageNumber = 1; +// Use default storage. +const storage = null; +// Set the width of coverted image. +const width = 100; +// Set the heigth of coverted image. +const heigth = 100; +// Set the document folder. +const folder = "Documents"; +// Set an extracted image folder. +const destFolder = "Images"; -console.log('running example'); +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImagesExtractAsPng + // Extract document images in PNG format to folder. + const response = await api.putImagesExtractAsPng( + fileName, + pageNumber, + width, + heigth, + storage, + folder, + destFolder); + console.log(response.body.status) +} -pdfApi.putImagesExtractAsPng("PdfWithImages2.pdf", 1, null, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/putImagesExtractAsTiff.js b/Examples/putImagesExtractAsTiff.js index 5c2e2e5e..fbe3958e 100644 --- a/Examples/putImagesExtractAsTiff.js +++ b/Examples/putImagesExtractAsTiff.js @@ -1,12 +1,37 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/fieldType"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi("XXXX", "XXXXXXX") +// Set the document name. +const fileName = "PdfWithImages2.pdf"; +// Set the page number. +const pageNumber = 1; +// Use default storage. +const storage = null; +// Set the width of coverted image. +const width = 100; +// Set the heigth of coverted image. +const heigth = 100; +// Set the document folder. +const folder = "Documents"; +// Set an extracted image folder. +const destFolder = "Images"; -console.log('running example'); +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutImagesExtractAsTiff + // Extract document images in TIFF format to folder. + const response = await api.putImagesExtractAsTiff( + fileName, + pageNumber, + width, + heigth, + storage, + folder, + destFolder); -pdfApi.putImagesExtractAsTiff("PdfWithImages2.pdf", 1, null, null, null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file + console.log(response.body.status) +} + +main(); diff --git a/Examples/putMergeDocuments.js b/Examples/putMergeDocuments.js index 4a975256..4935d019 100644 --- a/Examples/putMergeDocuments.js +++ b/Examples/putMergeDocuments.js @@ -1,23 +1,25 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/mergeDocuments"); +const { MergeDocuments } = require("asposepdfcloud/src/models/mergeDocuments"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); - -pdfApi = new PdfApi("XXXX", "XXXXXXX") - -console.log('running example'); - - -const names = ["4pages.pdf", "PdfWithImages2.pdf", "marketing.pdf"]; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set result file name. const resultName = "MergingResult.pdf"; +// Create merge request. const mergeDocuments = new MergeDocuments(); -mergeDocuments.list = []; -names.forEach((file) => { - mergeDocuments.list.push(file); -}); - - -pdfApi.putMergeDocuments(resultName, mergeDocuments, null, null) - .then((result) => { - console.log(result.response); - }); +mergeDocuments.list = [folder + "/4pages.pdf", folder + "/PdfWithImages2.pdf", folder + "/marketing.pdf"]; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Merge/PutMergeDocuments + // Merge a list of documents. + const result = await api.putMergeDocuments(resultName, mergeDocuments, storage, folder); + console.log(result.body.status); +} + +main(); diff --git a/Examples/putPageConvertToPng.js b/Examples/putPageConvertToPng.js index e436e1d5..d7502337 100644 --- a/Examples/putPageConvertToPng.js +++ b/Examples/putPageConvertToPng.js @@ -1,12 +1,31 @@ const { PdfApi } = require("asposepdfcloud"); -const { PdfAType } = require("asposepdfcloud/src/models/movieAnnotation"); +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); -pdfApi = new PdfApi("XXXX", "XXXXXXX") -console.log('running example'); +// Set the document name. +const fileName = "4pages.pdf"; +// Set the page number. +const pageNumber = 1; +// Set an extracted image path. +const outPath = "Images/" + fileName + "_" + pageNumber + ".png"; +// Set the width of coverted image. +const width = (595 / 2) | 0; +// Set the heigth of coverted image. +const heigth = (842 / 2) | 0; +// Set document folder. +const folder = "Documents"; +// Use default storage. +const storage = null; +// Set no password. +const password = null; +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Pages/PutPageConvertToPng + // Convert document page to png image and upload resulting file to storage. + const response = await api.putPageConvertToPng(fileName, pageNumber, outPath, width, heigth, folder, storage, password); + console.log(response.body.status) +} -pdfApi.putPageConvertToPng("4pages.pdf", 1, "page.png", null, null, null) - .then((result) => { - console.log(result.response); - }); \ No newline at end of file +main(); diff --git a/Examples/putPdfInRequestToDoc.js b/Examples/putPdfInRequestToDoc.js new file mode 100644 index 00000000..37532577 --- /dev/null +++ b/Examples/putPdfInRequestToDoc.js @@ -0,0 +1,55 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "28968-1.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/docsaveoptions/ + +// Use paragraph instead of line breaks. +const addReturnToLineEndings = true; +// Convert to doc format (default value). +const format = "doc"; +// Converted images X resolution default value is 300. +const imageResolutionX = 300; +// Converted images Y resolution default value is 300. +const imageResolutionY = 300; +// Specified in hundreds of percent of the text lines height. +const maxDistanceBetweenLines = 10; +// This mode is fast and good for maximally preserving original look of the PDF file. +const mode = "Textbox"; +// Recognition of bullets. +const recognizeBullets = true; +// It's normed to font size - 1.0 means 100% of supposed word's font size +const relativeHorizontalProximity = 1.0; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; +// Set an extracted image path. +const outPath = "Doc/" + fileName + "." + format; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInRequestToDoc + // Converts PDF document (in request content) to DOC format and uploads resulting file to storage. + const result = await api.putPdfInRequestToDoc( + outPath, + addReturnToLineEndings, + format, + imageResolutionX, + imageResolutionY, + maxDistanceBetweenLines, + mode, + recognizeBullets, + relativeHorizontalProximity, + storage, + fs.readFileSync("testData/" + fileName), + password); + + console.log(result.body.status); +} + +main(); diff --git a/Examples/putPdfInRequestToPptx.js b/Examples/putPdfInRequestToPptx.js new file mode 100644 index 00000000..2cf990ed --- /dev/null +++ b/Examples/putPdfInRequestToPptx.js @@ -0,0 +1,37 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "4pages.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/pptxsaveoptions/ + +// Set an extracted image path. +const outPath = "Pptx/" + fileName + ".pptx"; +// If set to true then images are separated from all other graphics +const separateImages = true; +// If set to true then all the content is recognized as images (one per page). +const slidesAsImages = false; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInRequestToPptx + // Converts PDF document (in request content) to PPTX format and uploads resulting file to storage. + const response = await api.putPdfInRequestToPptx( + outPath, + separateImages, + slidesAsImages, + storage, + password, + fs.readFileSync("testData/" + fileName)); + + console.log(response.body.status); +} + +main(); \ No newline at end of file diff --git a/Examples/putPdfInRequestToXls.js b/Examples/putPdfInRequestToXls.js new file mode 100644 index 00000000..b5277140 --- /dev/null +++ b/Examples/putPdfInRequestToXls.js @@ -0,0 +1,43 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "4pages.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/excelsaveoptions/ + +// Set an extracted image path. +const outPath = "Xls/" + fileName + ".xls"; +// Insert blank column at first. +const insertBlankColumnAtFirst = true; +// Save of each PDF page as separated worksheet. +const minimizeTheNumberOfWorksheets = false; +// Obsolete. +const scaleFactor = null; +// Columns division will independent for each page. +const uniformWorksheets = true; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInRequestToXls + // Converts PDF document (in request content) to XLS format and uploads resulting file to storage. + const response = await api.putPdfInRequestToXls( + outPath, + insertBlankColumnAtFirst, + minimizeTheNumberOfWorksheets, + scaleFactor, + uniformWorksheets, + storage, + password, + fs.readFileSync("testData/" + fileName)); + + console.log(response.body.status); +} + +main(); \ No newline at end of file diff --git a/Examples/putPdfInRequestToXlsx.js b/Examples/putPdfInRequestToXlsx.js new file mode 100644 index 00000000..6224df13 --- /dev/null +++ b/Examples/putPdfInRequestToXlsx.js @@ -0,0 +1,43 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "4pages.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/excelsaveoptions/ + +// Set an extracted image path. +const outPath = "Xls/" + fileName + ".xlsx"; +// Insert blank column at first. +const insertBlankColumnAtFirst = true; +// Save of each PDF page as separated worksheet. +const minimizeTheNumberOfWorksheets = false; +// Obsolete. +const scaleFactor = null; +// Columns division will independent for each page. +const uniformWorksheets = true; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInRequestToXlsx + // Converts PDF document (in request content) to XLSX format and uploads resulting file to storage. + const response = await api.putPdfInRequestToXlsx( + outPath, + insertBlankColumnAtFirst, + minimizeTheNumberOfWorksheets, + scaleFactor, + uniformWorksheets, + storage, + password, + fs.readFileSync("testData/" + fileName)); + + console.log(response.body.status); +} + +main(); \ No newline at end of file diff --git a/Examples/putPdfInStorageToDoc.js b/Examples/putPdfInStorageToDoc.js new file mode 100644 index 00000000..4abe8190 --- /dev/null +++ b/Examples/putPdfInStorageToDoc.js @@ -0,0 +1,57 @@ +const { PdfApi } = require("asposepdfcloud"); + +const fileName = "28968-1.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/docsaveoptions/ + +// Use paragraph instead of line breaks. +const addReturnToLineEndings = true; +// Convert to doc format (default value). +const format = "doc"; +// Converted images X resolution default value is 300. +const imageResolutionX = 300; +// Converted images Y resolution default value is 300. +const imageResolutionY = 300; +// Specified in hundreds of percent of the text lines height. +const maxDistanceBetweenLines = 10; +// This mode is fast and good for maximally preserving original look of the PDF file. +const mode = "Textbox"; +// Recognition of bullets. +const recognizeBullets = true; +// It's normed to font size - 1.0 means 100% of supposed word's font size +const relativeHorizontalProximity = 1.0; +// Set root folder. +const folder = "Documents"; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; +// Set an extracted image path. +const outPath = "Doc/" + fileName + "." + format; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInStorageToDoc + // Converts PDF document (located on storage) to DOC format and uploads resulting file to storage. + const result = await api.putPdfInStorageToDoc( + fileName, + fileName + "." + format, + addReturnToLineEndings, + format, + imageResolutionX, + imageResolutionY, + maxDistanceBetweenLines, + mode, + recognizeBullets, + relativeHorizontalProximity, + folder, + storage, + password); + + console.log(result.body.status); +} + +main(); diff --git a/Examples/putPdfInStorageToPptx.js b/Examples/putPdfInStorageToPptx.js new file mode 100644 index 00000000..af519421 --- /dev/null +++ b/Examples/putPdfInStorageToPptx.js @@ -0,0 +1,38 @@ +const { PdfApi } = require("asposepdfcloud"); + +const fileName = "4pages.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/pptxsaveoptions/ + +// Set an extracted image path. +const outPath = "Pptx/" + fileName + ".pptx"; +// If set to true then images are separated from all other graphics +const separateImages = true; +// If set to true then all the content is recognized as images (one per page). +const slidesAsImages = false; +// Set root folder. +const folder = "Documents"; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInStorageToPptx + // Converts PDF document (located on storage) to PPTX format and uploads resulting file to storage + const response = await api.putPdfInStorageToPptx(fileName, + outPath, + separateImages, + slidesAsImages, + folder, + storage, + password); + + console.log(response.response.statusCode); +} + +main(); \ No newline at end of file diff --git a/Examples/putPdfInStorageToXls.js b/Examples/putPdfInStorageToXls.js new file mode 100644 index 00000000..a3b949b6 --- /dev/null +++ b/Examples/putPdfInStorageToXls.js @@ -0,0 +1,44 @@ +const { PdfApi } = require("asposepdfcloud"); + +const fileName = "28968-1.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/excelsaveoptions/ + +// Set an extracted image path. +const outPath = "Xls/" + fileName + ".xls"; +// Insert blank column at first. +const insertBlankColumnAtFirst = true; +// Save of each PDF page as separated worksheet. +const minimizeTheNumberOfWorksheets = false; +// Obsolete. +const scaleFactor = null; +// Columns division will independent for each page. +const uniformWorksheets = true; +// Set root folder. +const folder = "Documents"; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null; + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInStorageToXls + // Converts PDF document (located on storage) to XLS format and uploads resulting file to storage + const result = await api.putPdfInStorageToXls(fileName, + outPath, + insertBlankColumnAtFirst, + minimizeTheNumberOfWorksheets, + scaleFactor, + uniformWorksheets, + folder, + storage, + password); + + console.log(result.body.status); +} + +main(); \ No newline at end of file diff --git a/Examples/putPdfInStorageToXlsx.js b/Examples/putPdfInStorageToXlsx.js new file mode 100644 index 00000000..b7c62b2b --- /dev/null +++ b/Examples/putPdfInStorageToXlsx.js @@ -0,0 +1,44 @@ +const { PdfApi } = require("asposepdfcloud"); + +const fileName = "4pages.pdf"; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// Detailed description of available parameters at +// https://reference.aspose.com/pdf/net/aspose.pdf/excelsaveoptions/ + +// Set an extracted image path. +const outPath = "Xls/" + fileName + ".xlsx"; +// Insert blank column at first. +const insertBlankColumnAtFirst = true; +// Save of each PDF page as separated worksheet. +const minimizeTheNumberOfWorksheets = false; +// Obsolete. +const scaleFactor = null; +// Columns division will independent for each page. +const uniformWorksheets = true; +// Set root folder. +const folder = "Documents"; +// Set default storage. +const storage = null; +// Set pdf document password. +const password = null + +async function main() +{ + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Convert/PutPdfInStorageToXlsx + // Converts PDF document (located on storage) to XLSX format and uploads resulting file to storage + const response = await api.putPdfInStorageToXlsx(fileName, + outPath, + insertBlankColumnAtFirst, + minimizeTheNumberOfWorksheets, + scaleFactor, + uniformWorksheets, + folder, + storage, + password); + + console.log(response.response.statusCode); +} + +main(); \ No newline at end of file diff --git a/Examples/putReplaceImage.js b/Examples/putReplaceImage.js new file mode 100644 index 00000000..fe90f704 --- /dev/null +++ b/Examples/putReplaceImage.js @@ -0,0 +1,35 @@ +const { PdfApi } = require("asposepdfcloud"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Path to image file in storage. Image content is used otherwise. +const imageFilePath = ""; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set image buffer. +const imageContent = null + +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, storage, folder); + const imageId = imagesResult.body.images.list[0].id; + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutReplaceImage + // Replace document image. + const result = await api.putReplaceImage( + fileName, + imageId, + imageFilePath, + storage, + folder, + imageContent); + + console.log(result.body.status); +} + +main(); diff --git a/Examples/putReplaceMultipleImage.js b/Examples/putReplaceMultipleImage.js new file mode 100644 index 00000000..6939fd5f --- /dev/null +++ b/Examples/putReplaceMultipleImage.js @@ -0,0 +1,34 @@ +const { PdfApi } = require("asposepdfcloud"); + +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +// The document name. +const fileName = "PdfWithImages2.pdf"; +// Path to image file in storage. Image content is used otherwise. +const imageFilePath = ""; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; +// Set image buffer. +const imageContent = null + +async function main() +{ + // Read document images. + const imagesResult = await api.getImages(fileName, 1, storage, folder); + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Images/PutReplaceMultipleImage + // Replace document image. + const result = await api.putReplaceMultipleImage( + fileName, + imagesResult.body.images.list, + imageFilePath, + storage, + folder, + imageContent); + + console.log(result.body.status); +} + +main(); diff --git a/Examples/uploadFile.js b/Examples/uploadFile.js new file mode 100644 index 00000000..c2b1c6e1 --- /dev/null +++ b/Examples/uploadFile.js @@ -0,0 +1,15 @@ +const { PdfApi } = require("asposepdfcloud"); +const fs = require("fs"); + +const fileName = "PdfWithImages2.pdf"; +const folder = "Documents"; +const storage = null; +const api = new PdfApi("http://172.17.0.1:5000/v3.0"); + +async function main() +{ + const response = await api.uploadFile(folder + "/" +fileName, fs.readFileSync("testData/" + fileName), storage) + console.log(response.body.uploaded[0]) +} + +main(); diff --git a/README.md b/README.md index 83aedaf9..61825991 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ 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.10 +## Enhancements in Version 24.11 - Develop DeleteDocumentLayer Method. - Develop GetDocumentLayers Method. - How to extract PDF layer elements and create a new PDF diff --git a/docs/DocRecognitionMode.md b/docs/DocRecognitionMode.md index edd5a46d..a865994c 100644 --- a/docs/DocRecognitionMode.md +++ b/docs/DocRecognitionMode.md @@ -4,6 +4,7 @@ Allows to control how a PDF document is converted into a word processing documen ## Enum Name | Type | Value | Description ------------ | ------------- | ------------- | ------------- +**EnhancedFlow** | **string** | 'EnhancedFlow' | An alternative Flow mode that supports the recognition of tables. **Flow** | **string** | 'Flow' | Full recognition mode, the engine performs grouping and multi-level analysis to restore the original document author's intent and produce a maximally editable document. The downside is that the output document might look different from the original PDF file. **Textbox** | **string** | 'Textbox' | This mode is fast and good for maximally preserving original look of the PDF file, but editability of the resulting document could be limited.Every visually grouped block of text int the original PDF file is converted into a textbox in the resulting document. This achieves maximal resemblance of the output document to the original PDF file. The output document will look good, but it will consist entirely of textboxes and it could makes further editing of the document in Microsoft Word quite hard.This is the default mode. diff --git a/docs/PdfApi.md b/docs/PdfApi.md index 3535ab34..63bc9069 100644 --- a/docs/PdfApi.md +++ b/docs/PdfApi.md @@ -95,6 +95,7 @@ Method | HTTP request | Description *PdfApi* | [**getImageExtractAsPng**](PdfApi.md#getImageExtractAsPng) | **GET** /pdf/\{name}/images/\{imageId}/extract/png | Extract document image in PNG format *PdfApi* | [**getImageExtractAsTiff**](PdfApi.md#getImageExtractAsTiff) | **GET** /pdf/\{name}/images/\{imageId}/extract/tiff | Extract document image in TIFF format *PdfApi* | [**getImages**](PdfApi.md#getImages) | **GET** /pdf/\{name}/pages/\{pageNumber}/images | Read document images. +*PdfApi* | [**getImagesExtractSvg**](PdfApi.md#getImagesExtractSvg) | **GET** /pdf/\{name}/pages/\{pageNumber}/images/extract/svg | Extract SVG images from document page. *PdfApi* | [**getImportFieldsFromFdfInStorage**](PdfApi.md#getImportFieldsFromFdfInStorage) | **GET** /pdf/\{name}/import/fdf | Update fields from FDF file in storage. *PdfApi* | [**getImportFieldsFromXfdfInStorage**](PdfApi.md#getImportFieldsFromXfdfInStorage) | **GET** /pdf/\{name}/import/xfdf | Update fields from XFDF file in storage. *PdfApi* | [**getImportFieldsFromXmlInStorage**](PdfApi.md#getImportFieldsFromXmlInStorage) | **GET** /pdf/\{name}/import/xml | Import from XML file (located on storage) to PDF format and return resulting file in response. @@ -2437,6 +2438,30 @@ Name | Type | Description | Notes [**ImagesResponse**](ImagesResponse.md) +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + + +## **getImagesExtractSvg** +> getImagesExtractSvg(name, pageNumber, storage, folder, passBase64) + +Extract SVG images from document page. + +### Parameters +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**name** | **string** | The document name. | +**pageNumber** | **number** | The page number. | +**storage** | **string** | The document storage. | [optional] +**folder** | **string** | The document folder. | [optional] +**passBase64** | **string** | The password (Base64). | [optional] + +### Return type + +[**SvgImages**](SvgImages.md) + ### HTTP request headers - **Content-Type**: application/json diff --git a/docs/SvgImages.md b/docs/SvgImages.md new file mode 100644 index 00000000..1651b235 --- /dev/null +++ b/docs/SvgImages.md @@ -0,0 +1,13 @@ +# SvgImages +SvgImages class + +*Inherited from [AsposeResponse](AsposeResponse.md)* +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**list** | **Array<string>** | List of SVG images | [optional] +**code** | **number** | Response status code.
*Inherited from [AsposeResponse](AsposeResponse.md)* | +**status** | **string** | Response status.
*Inherited from [AsposeResponse](AsposeResponse.md)* | [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/svgImages.ts) + diff --git a/src/api/api.ts b/src/api/api.ts index 032d32db..813bac43 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -250,6 +250,7 @@ import { StampsInfoResponse } from "../models/stampsInfoResponse"; import { StrikeOutAnnotationResponse } from "../models/strikeOutAnnotationResponse"; import { StrikeOutAnnotations } from "../models/strikeOutAnnotations"; import { StrikeOutAnnotationsResponse } from "../models/strikeOutAnnotationsResponse"; +import { SvgImages } from "../models/svgImages"; import { Table } from "../models/table"; import { TableRecognized } from "../models/tableRecognized"; import { TableRecognizedResponse } from "../models/tableRecognizedResponse"; @@ -5503,6 +5504,70 @@ export class PdfApi { } + /** + * + * @summary Extract SVG images from document page. + * @param name The document name. + * @param pageNumber The page number. + * @param storage The document storage. + * @param folder The document folder. + * @param passBase64 The password (Base64). + */ + public async getImagesExtractSvg (name: string, pageNumber: number, storage?: string, folder?: string, passBase64?: string) : Promise<{ response: http.IncomingMessage; body: SvgImages; }> { + const localVarPath = this.basePath + '/pdf/{name}/pages/{pageNumber}/images/extract/svg' + .replace('{' + 'name' + '}', encodeURIComponent(String(name)).replace('%2F', '/')) + .replace('{' + 'pageNumber' + '}', encodeURIComponent(String(pageNumber)).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 getImagesExtractSvg.'); + } + + // verify required parameter 'pageNumber' is not null or undefined + if (pageNumber === null || pageNumber === undefined) { + throw new Error('Required parameter pageNumber was null or undefined when calling getImagesExtractSvg.'); + } + + if (storage !== undefined && null !== storage) { + localVarQueryParameters['storage'] = ObjectSerializer.serialize(storage, "string"); + } + + if (folder !== undefined && null !== folder) { + localVarQueryParameters['folder'] = ObjectSerializer.serialize(folder, "string"); + } + + if (passBase64 !== undefined && null !== passBase64) { + localVarQueryParameters['passBase64'] = ObjectSerializer.serialize(passBase64, "string"); + } + + + let localVarUseFormData = false; + let fileData = null; + let localVarRequestOptions: localVarRequest.Options = { + method: 'GET', + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + }; + + 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, "SvgImages"); + return Promise.resolve({body: result, response}); + } + + /** * * @summary Update fields from FDF file in storage. diff --git a/src/models/docRecognitionMode.ts b/src/models/docRecognitionMode.ts index 0ea8fb9a..d3771348 100644 --- a/src/models/docRecognitionMode.ts +++ b/src/models/docRecognitionMode.ts @@ -22,4 +22,5 @@ export enum DocRecognitionMode { Textbox = 'Textbox', Flow = 'Flow', + EnhancedFlow = 'EnhancedFlow', } diff --git a/src/models/svgImages.ts b/src/models/svgImages.ts new file mode 100644 index 00000000..94b5720f --- /dev/null +++ b/src/models/svgImages.ts @@ -0,0 +1,47 @@ + /** + * + * Copyright (c) 2024 Aspose.PDF Cloud + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +import { AsposeResponse } from "./asposeResponse"; + +/** +* SvgImages class +*/ +export class SvgImages extends AsposeResponse { + /** + * List of SVG images + */ + 'list': Array; + + static discriminator = undefined; + + static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "list", + "baseName": "List", + "type": "Array" + } ]; + + static getAttributeTypeMap() { + return super.getAttributeTypeMap().concat(SvgImages.attributeTypeMap); + } +} + + diff --git a/src/objectSerializer.ts b/src/objectSerializer.ts index f0c3c708..56226f3b 100644 --- a/src/objectSerializer.ts +++ b/src/objectSerializer.ts @@ -250,6 +250,7 @@ import { StampsInfoResponse } from "./models/stampsInfoResponse"; import { StrikeOutAnnotationResponse } from "./models/strikeOutAnnotationResponse"; import { StrikeOutAnnotations } from "./models/strikeOutAnnotations"; import { StrikeOutAnnotationsResponse } from "./models/strikeOutAnnotationsResponse"; +import { SvgImages } from "./models/svgImages"; import { Table } from "./models/table"; import { TableRecognized } from "./models/tableRecognized"; import { TableRecognizedResponse } from "./models/tableRecognizedResponse"; @@ -544,6 +545,7 @@ let typeMap: {[index: string]: any} = { "StrikeOutAnnotationResponse": StrikeOutAnnotationResponse, "StrikeOutAnnotations": StrikeOutAnnotations, "StrikeOutAnnotationsResponse": StrikeOutAnnotationsResponse, + "SvgImages": SvgImages, "Table": Table, "TableRecognized": TableRecognized, "TableRecognizedResponse": TableRecognizedResponse, diff --git a/src/requestHelper.ts b/src/requestHelper.ts index b3137e59..638944a0 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.10.0"); + sa.set("x-aspose-client-version", "24.11.0"); if (!requestOptions.headers) { requestOptions.headers = {}; diff --git a/test/testImages.ts b/test/testImages.ts index 7caec8ba..fe98b788 100644 --- a/test/testImages.ts +++ b/test/testImages.ts @@ -273,5 +273,17 @@ describe("Images Tests", () => { }); }); }); + + describe("GetImagesExtractAsSvg Test", () => { + + it("should return response with code 200", async () => { + + return BaseTest.getPdfApi().getImagesExtractSvg("Alfa.pdf", pageNumber, null, BaseTest.remoteTempFolder, null) + .then((result) => { + assert.equal(result.response.statusCode, 200); + assert.equal(13, result.body.list.length); + }); + }); + }); }); }); \ No newline at end of file diff --git a/testData/alfa.pdf b/testData/alfa.pdf new file mode 100644 index 00000000..f904d1f2 Binary files /dev/null and b/testData/alfa.pdf differ diff --git a/useCases/convertToPdf3A.js b/useCases/convertToPdf3A.js new file mode 100644 index 00000000..fd15fd24 --- /dev/null +++ b/useCases/convertToPdf3A.js @@ -0,0 +1,52 @@ +// Import necessary classes from the Aspose PDF Cloud library +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); +const { PdfAType } = require("asposepdfcloud/src/models/pdfAType"); + +// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ +const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + +// Set the document name +const fileName = "4pages.pdf"; +// Set the document name +const outputPath = "PDF3A/4pages.pdf"; +// Use default storage (null indicates default storage) +const storage = null; +// Set the folder where the document is stored +const folder = "Documents"; +// Set the pdf document has no password. +const password = null; + +/** + * Convert the PDF document to PDF3A using the Aspose.PDF Cloud API. + * + * This function performs the following steps: + * 1. Reads a PDF file from the local file system. + * 2. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 3. Convert PDF document to PDF3A format using the Aspose.PDF Cloud API. + * 5. Logs the result to the console. + * + * @returns {Promise} A Promise that resolves when the adding text is complete. + */ +async function getPdfInStorageToPdfA() +{ + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage) + // Swagger method for adding text: https://reference.aspose.cloud/pdf/#/Convert/PutPdfAInStorageToPdf + // Call the API to convert the specified PDF document to PDF3A format + const result = await api.putPdfInStorageToPdfA( + uploadResponse.body.uploaded[0], + outputPath, + PdfAType.PDFA3A, + folder, + storage, + password); + + // Log the response to console. + console.log(result.body.status); // Log the status of the operation +} + +// Execute the putAddText function +getPdfInStorageToPdfA(); diff --git a/useCases/textAdd.js b/useCases/textAdd.js new file mode 100644 index 00000000..31dcb7a0 --- /dev/null +++ b/useCases/textAdd.js @@ -0,0 +1,158 @@ +// Import necessary classes from the Aspose PDF Cloud library +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); +const { Color } = require("asposepdfcloud/src/models/color"); +const { FontStyles } = require("asposepdfcloud/src/models/fontStyles"); +const { LineSpacing } = require("asposepdfcloud/src/models/lineSpacing"); +const { Paragraph } = require("asposepdfcloud/src/models/paragraph"); +const { TextHorizontalAlignment } = require("asposepdfcloud/src/models/textHorizontalAlignment"); +const { VerticalAlignment } = require("asposepdfcloud/src/models/verticalAlignment"); +const { WrapMode } = require("asposepdfcloud/src/models/wrapMode"); +const { TextLine } = require("asposepdfcloud/src/models/textLine"); +const { Segment } = require("asposepdfcloud/src/models/segment"); +const { Rectangle } = require("asposepdfcloud/src/models/rectangle"); +const { TextState } = require("asposepdfcloud/src/models/textState"); + +// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ +const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + +// Set the document name +const fileName = "4pages.pdf"; +// Set the page number where the text will be added +const pageNumber = 3; +// Use default storage (null indicates default storage) +const storage = null; +// Set the folder where the document is stored +const folder = "Documents"; + +/** + * Add text to a PDF document page using the Aspose.PDF Cloud API. + * + * This function performs the following steps: + * 1. Reads a PDF file from the local file system. + * 2. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 3. Creates an `Paragraph` object with the inserted text. + * 4. Put text on the third page of PDF document using the Aspose.PDF Cloud API. + * 5. Logs the result to the console. + * + * @returns {Promise} A Promise that resolves when the adding text is complete. + */ +async function putAddText() +{ + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // Represents color DTO. + const foregroundColor = new Color(); + // Set an alpha component. + foregroundColor.a = 255; + // Set the red component. + foregroundColor.r = 0; + // Set the green component. + foregroundColor.g = 0; + // Set the blue component. + foregroundColor.b = 255; + + // Represents color DTO. + const backgroundColor = new Color(); + // Set an alpha component. + backgroundColor.a = 100; + // Set the red component. + backgroundColor.r = 255; + // Set the green component. + backgroundColor.g = 255; + // Set the blue component. + backgroundColor.b = 0; + + // Create the new paragraph object to represent text paragraphs + const rectangle = new Rectangle(); + // Lower left x coordinate + rectangle.lLX = 10; + // Lower left y coordinate + rectangle.lLY = 10; + // Upper right x coordinate + rectangle.uRX = 300; + // Upper right y coordinate + rectangle.uRY = 500; + + // Create the new text state. + const textState = new TextState(); + // Set font size of the text + textState.fontSize = 20; + // Set font name of the text + textState.font = "Arial"; + // Set foreground color of the text + textState.foregroundColor = foregroundColor; + // Set background color of the text + textState.backgroundColor = backgroundColor; + // Set font style of the text + textState.fontStyle = FontStyles.Regular; + // Font file path in storage (null means default font) + textState.fontFile = null; + // Set underline for the text + textState.underline = true; + // Set strikeout for the text + textState.strikeOut = false; + // Set superscript mode for the text + textState.superscript = false; + // Set subscript mode for the text + textState.subscript = false; + + // Create the new text segment. + const segment = new Segment(); + // Text value for the segment + segment.value = "segment text 1 with text state"; + // Define the text state for formatting + segment.textState = textState; + + // Create the new text line. + const textLine = new TextLine(); + // Set the line's horizontal alignment to Right + textLine.horizontalAlignment = TextHorizontalAlignment.Right; + // Define the segments that form the line + textLine.segments = [segment]; + + // Create new text paragraph. + const paragraph = new Paragraph(); + // Set the line spacing mode to FullSize + paragraph.lineSpacing = LineSpacing.FullSize; + // Set the word wrap mode to wrap by words + paragraph.wrapMode = WrapMode.ByWords; + // Set the horizontal alignment for the text inside the paragraph + paragraph.horizontalAlignment = TextHorizontalAlignment.FullJustify; + // Set the left margin for the paragraph + paragraph.leftMargin = 100; + // Set the right margin for the paragraph + paragraph.rightMargin = 100; + // Set the top margin for the paragraph + paragraph.topMargin = 200; + // Set the bottom margin for the paragraph + paragraph.bottomMargin = 200; + // Define the rectangle area for the paragraph + paragraph.rectangle = rectangle; + // Set the rotation angle of the text in degrees + paragraph.rotation = 10, + // Set the indent for subsequent lines + paragraph.subsequentLinesIndent = 30, + // Set the vertical alignment for the text inside the paragraph + paragraph.vercolorticalAlignment = VerticalAlignment.Center, + // Define an array of text lines for the paragraph + paragraph.lines = [textLine]; + + // Swagger method for adding text: https://reference.aspose.cloud/pdf/#/Text/PutAddText + // Call the API to add text to the specified PDF document page + const result = await api.putAddText( + uploadResponse.body.uploaded[0], + pageNumber, + paragraph, + folder, + storage); + + // Log the response to console. + console.log(result.body.status); // Log the status of the operation +} + +// Execute the putAddText function +putAddText(); diff --git a/useCases/textExtract.js b/useCases/textExtract.js new file mode 100644 index 00000000..11c3a365 --- /dev/null +++ b/useCases/textExtract.js @@ -0,0 +1,71 @@ +// Import necessary classes from the Aspose PDF Cloud library +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); + +// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ +const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + +// The document name. +const fileName = "4pages.pdf"; +// Use default storage. +const storage = null; +// Set document folder. +const folder = "Documents"; + +/** + * Extract text of a PDF document using the Aspose.PDF Cloud API. + * + * This function performs the following steps: + * 1. Reads a PDF file from the local file system. + * 2. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 3. Initializing parameters for searching text on a PDF document page. + * 4. Read text of PDF document using the Aspose.PDF Cloud API. + * 5. Logs an extracted text. + * + * @returns {Promise} A promise that is resolves after text extraction is complete. + */ +async function extractText() +{ + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // X-coordinate of lower-left corner. + const llx = 100; + // Y-coordinate of lower-left corner. + const lly = 700; + // X-coordinate of upper-right corner. + const urx = 200; + // Y-coordinate of upper-right corner. + const ury = 800; + // List of formats to search. + const format = [ ".* Page" ]; + // Formats are specified as a regular expression. + const regex = true; + // Split result fragments (default is true). + const splitRects = true; + + // Swagger method definition available at + // https://reference.aspose.cloud/pdf/#/Text/GetText + // Extract document text. + const result = await api.getText( + uploadResponse.body.uploaded[0], + llx, + lly, + urx, + ury, + format, + regex, + splitRects, + folder, + storage); + + // Log extracted text. + for (const text of result.body.textOccurrences.list) + { + console.log(text.text); + } +} + +extractText(); diff --git a/useCases/textReplace.js b/useCases/textReplace.js new file mode 100644 index 00000000..91ea1cb9 --- /dev/null +++ b/useCases/textReplace.js @@ -0,0 +1,131 @@ +// Import necessary classes from the Aspose PDF Cloud library +const fs = require("fs"); +const { PdfApi } = require("asposepdfcloud"); +const { Color } = require("asposepdfcloud/src/models/color"); +const { FontStyles } = require("asposepdfcloud/src/models/fontStyles"); +const { Rectangle } = require("asposepdfcloud/src/models/rectangle"); +const { TextState } = require("asposepdfcloud/src/models/textState"); +const { TextReplace } = require("asposepdfcloud/src/models/textReplace"); +const { TextReplaceListRequest } = require("asposepdfcloud/src/models/textReplaceListRequest"); + +// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/ +const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY"); + +// Set the document name +const fileName = "4pages.pdf"; +// Use default storage (null indicates default storage) +const storage = null; +// Set the folder where the document is stored +const folder = "Documents"; + +/** + * Replace text of a PDF document using the Aspose.PDF Cloud API. + * + * This function performs the following steps: + * 1. Reads a PDF file from the local file system. + * 2. Uploads the PDF file to the Aspose.PDF Cloud storage. + * 3. Creates an `TextReplaceListRequest` object with the replacements list. + * 4. Replace text of PDF document using the Aspose.PDF Cloud API. + * 5. Logs the result to the console. + * + * @returns {Promise} A promise that is resolves after text replacement is complete. + */ +async function postDocumentTextReplace() +{ + // Read file from file system. + const buffer = fs.readFileSync("testData/" + fileName); + // Upload file to cloud storage. + const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage) + + // Represents color DTO. + const foregroundColor = new Color(); + // Set an alpha component. + foregroundColor.a = 255; + // Set the red component. + foregroundColor.r = 0; + // Set the green component. + foregroundColor.g = 0; + // Set the blue component. + foregroundColor.b = 255; + + // Represents color DTO. + const backgroundColor = new Color(); + // Set an alpha component. + backgroundColor.a = 100; + // Set the red component. + backgroundColor.r = 255; + // Set the green component. + backgroundColor.g = 255; + // Set the blue component. + backgroundColor.b = 0; + + // Create the new paragraph object to represent text paragraphs. + const rectangle = new Rectangle(); + // Lower left x coordinate. + rectangle.lLX = 10; + // Lower left y coordinate. + rectangle.lLY = 10; + // Upper right x coordinate. + rectangle.uRX = 300; + // Upper right y coordinate. + rectangle.uRY = 500; + + // Create the new text state. + const textState = new TextState(); + // Set font size of the text. + textState.fontSize = 12; + // Set font name of the text. + textState.font = "Arial"; + // Set foreground color of the text. + textState.foregroundColor = foregroundColor; + // Set background color of the text. + textState.backgroundColor = backgroundColor; + // Set font style of the text. + textState.fontStyle = FontStyles.Regular; + // Font file path in storage (null means default font). + textState.fontFile = null; + // Set underline for the text. + textState.underline = true; + // Set strikeout for the text. + textState.strikeOut = false; + // Set superscript mode for the text. + textState.superscript = false; + // Set subscript mode for the text. + textState.subscript = false; + + // Create TextReplace request. + const textReplace = new TextReplace(); + // Set the text to replace. + textReplace.oldValue = "Page"; + // Set the replacement text. + textReplace.newValue = "Replacement"; + // Set the oldValue is regex. + textReplace.regex = false; + // Set the text state. + textReplace.textState = textState; + // Set the text aligment. + textReplace.centerTextHorizontally = false; + + // Create TextReplaceListRequest instance. + const textReplaceList = new TextReplaceListRequest(); + // Set the text replaces list. + textReplaceList.textReplaces = [textReplace]; + // Set the start index of text items to replace. + textReplaceList.startIndex = 2; + // Set the count replacements. + textReplaceList.countReplace = 2; + + // Swagger method for adding text: https://reference.aspose.cloud/pdf/#/TextReplace/PostDocumentTextReplace + // Call the API to replace text in the specified PDF document. + const result = await api.postDocumentTextReplace( + uploadResponse.body.uploaded[0], + textReplaceList, + storage, + folder); + + // Log the response to console. + console.log(result.body.status); +} + +// Execute the postDocumentTextReplace function +postDocumentTextReplace();