Skip to content

Commit 7ae276f

Browse files
Added merge use case
1 parent 87927c0 commit 7ae276f

File tree

4 files changed

+288
-0
lines changed

4 files changed

+288
-0
lines changed

UsesCases/Merge/merge.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Merging the PDF documents using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF files from the local file system.
7+
* 3. Uploads the PDF files to the Aspose.PDF Cloud storage.
8+
* 4. Merging the PDF documents using the Aspose.PDF Cloud API.
9+
* 5. Logs the result to the console.
10+
*
11+
*/
12+
13+
// Import necessary classes.
14+
const fs = require("fs");
15+
const { PdfApi } = require("asposepdfcloud");
16+
const { MergeDocuments } = require("asposepdfcloud/src/models/mergeDocuments");
17+
18+
/**
19+
* Merging the PDF documents using the Aspose.PDF Cloud API.
20+
*
21+
* @returns {Promise<void>} A Promise that resolves when the splitting document is complete.
22+
*/
23+
async function mergeDocument()
24+
{
25+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
26+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
27+
28+
const fileName = "merged.pdf";
29+
// Set the document names to merge.
30+
const fileNames = ["4pages.pdf", "alfa.pdf"];
31+
// Use default storage (null indicates default storage).
32+
const storage = null;
33+
// Set the folder where the document is stored.
34+
const folder = "Documents";
35+
36+
// Initialize merge documents request.
37+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/MergeDocuments.md
38+
const mergeRequest = new MergeDocuments();
39+
mergeRequest.list = [];
40+
await Promise.all(
41+
fileNames.map(async fileName =>
42+
{
43+
// Read file from file system.
44+
const buffer = fs.readFileSync("testData/" + fileName);
45+
// Upload file to cloud storage.
46+
const response = await api.uploadFile(folder + "/" + fileName, buffer, storage);
47+
// Push uploaded file name to merge request.
48+
mergeRequest.list.push(folder + "/" + fileName);
49+
})
50+
);
51+
52+
// Swagger documentation available at:
53+
// https://reference.aspose.cloud/pdf/#/Merge/PutMergeDocuments
54+
// Merge PDF documents using PDF Cloud API.
55+
const result = await api.putMergeDocuments(
56+
fileName,
57+
mergeRequest,
58+
storage,
59+
folder);
60+
61+
// Log the response to console.
62+
console.log(result.body.status);
63+
// Log split result.
64+
result.body.result.documents.forEach((document, index) =>
65+
{
66+
console.log(index + 1 + ") " + document.href);
67+
});
68+
}
69+
70+
// Execute the mergeDocument function.
71+
mergeDocument();

UsesCases/Split/parts/parts.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Splitting the PDF document to pages using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF file from the local file system.
7+
* 3. Uploads the PDF file to the Aspose.PDF Cloud storage.
8+
* 4. Splitting document to pages using the Aspose.PDF Cloud API.
9+
* 5. Logs the result to the console.
10+
*
11+
*/
12+
13+
// Import necessary classes.
14+
const fs = require("fs");
15+
const { PdfApi } = require("asposepdfcloud");
16+
17+
/**
18+
* Splitting the PDF document per pages using the Aspose.PDF Cloud API.
19+
*
20+
* @returns {Promise<void>} A Promise that resolves when the splitting document is complete.
21+
*/
22+
async function splitDocumentRanges()
23+
{
24+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
25+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
26+
27+
// Set the document name.
28+
const fileName = "4pages.pdf";
29+
// Set the page ranges for splitting.
30+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/SplitRangePdfOptions.md
31+
const options =
32+
{
33+
pageRanges: [
34+
// first and second pages.
35+
{
36+
to: 2
37+
},
38+
// third and fourth pages.
39+
{
40+
from: 3
41+
},
42+
// second and third pages.
43+
{
44+
from: 2,
45+
to: 3
46+
},
47+
// first page.
48+
{
49+
from: 1,
50+
to: 1
51+
}
52+
]
53+
};
54+
// Use default storage (null indicates default storage).
55+
const storage = null;
56+
// Set the folder where the document is stored.
57+
const folder = "Documents";
58+
59+
// Read the file from file system.
60+
const buffer = fs.readFileSync("testData/" + fileName);
61+
// Upload the file to cloud storage.
62+
const uploadResponse = await api.uploadFile(folder + "/" + fileName, buffer, storage)
63+
64+
// Swagger documentation available at:
65+
// https://reference.aspose.cloud/pdf/#/Document/PostSplitRangePdfDocument
66+
// Split the PDF document to page ranges.
67+
const result = await api.postSplitRangePdfDocument(
68+
uploadResponse.body.uploaded[0],
69+
options,
70+
storage,
71+
folder);
72+
73+
// Log the response to console.
74+
console.log(result.body.status);
75+
// Log split result.
76+
result.body.result.documents.forEach((document, index) =>
77+
{
78+
console.log(index + 1 + ") " + document.href);
79+
});
80+
}
81+
82+
// Execute the splitDocumentRanges function.
83+
splitDocumentRanges();

UsesCases/Split/single/single.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Splitting the PDF document to pages using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF file from the local file system.
7+
* 3. Uploads the PDF file to the Aspose.PDF Cloud storage.
8+
* 4. Splitting document to pages using the Aspose.PDF Cloud API.
9+
* 5. Logs the result to the console.
10+
*
11+
*/
12+
13+
// Import necessary classes.
14+
const fs = require("fs");
15+
const { PdfApi } = require("asposepdfcloud");
16+
17+
/**
18+
* Splitting the PDF document per pages using the Aspose.PDF Cloud API.
19+
*
20+
* @returns {Promise<void>} A Promise that resolves when the splitting document is complete.
21+
*/
22+
async function splitDocument()
23+
{
24+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
25+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
26+
27+
// Set the document name.
28+
const fileName = "4pages.pdf";
29+
// Set the start page number.
30+
const pageFrom = 2;
31+
// Set the end page number same as pageFrom.
32+
const pageTo = 2;
33+
// Set the resulting documents format.
34+
// Available formats are: PDF, PDFA1A, PDFA1B, PDFA3A, PDFA3B, DOC, DOCX, XLS, XPS, TIFF, SVG, JPEG, JPG, PNG, EMF, BMP, GIF, PPTX, EPUB.
35+
const format = "PDF";
36+
// Use default storage (null indicates default storage).
37+
const storage = null;
38+
// Set the folder where the document is stored.
39+
const folder = "Documents";
40+
41+
// Read the file from file system.
42+
const buffer = fs.readFileSync("testData/" + fileName);
43+
// Upload the file to cloud storage.
44+
const uploadResponse = await api.uploadFile(folder + "/" + fileName, buffer, storage)
45+
46+
// Swagger documentation available at:
47+
// https://reference.aspose.cloud/pdf/#/Document/PostSplitDocument
48+
// Split the PDF document to single page.
49+
const result = await api.postSplitDocument(
50+
uploadResponse.body.uploaded[0],
51+
format,
52+
pageFrom,
53+
pageTo,
54+
storage,
55+
folder);
56+
57+
// Log the response to console.
58+
console.log(result.body.status);
59+
// Log split result.
60+
result.body.result.documents.forEach((document, index) =>
61+
{
62+
console.log(index + 1 + ") " + document.href);
63+
});
64+
}
65+
66+
// Execute the splitDocument function.
67+
splitDocument();

UsesCases/Split/split.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Splitting the PDF document to pages using the Aspose.PDF Cloud API.
3+
*
4+
* This use case performs the following steps:
5+
* 1. Import the necessary classes.
6+
* 2. Reads a PDF file from the local file system.
7+
* 3. Uploads the PDF file to the Aspose.PDF Cloud storage.
8+
* 4. Splitting document to pages using the Aspose.PDF Cloud API.
9+
* 5. Logs the result to the console.
10+
*
11+
*/
12+
13+
// Import necessary classes.
14+
const fs = require("fs");
15+
const { PdfApi } = require("asposepdfcloud");
16+
17+
/**
18+
* Splitting the PDF document per pages using the Aspose.PDF Cloud API.
19+
*
20+
* @returns {Promise<void>} A Promise that resolves when the splitting document is complete.
21+
*/
22+
async function splitDocument()
23+
{
24+
// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
25+
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");
26+
27+
// Set the document name.
28+
const fileName = "4pages.pdf";
29+
// Set the start page number (null means from begin of document).
30+
const pageFrom = null;
31+
// Set the end page number (null means to end of document).
32+
const pageTo = null;
33+
// Set the resulting documents format.
34+
// Available formats are: PDF, PDFA1A, PDFA1B, PDFA3A, DOC, DOCX, XLS, XPS, TIFF, SVG, JPEG, JPG, PNG, EMF, BMP, GIF, PPTX, EPUB.
35+
const format = "PDF";
36+
// Use default storage (null indicates default storage).
37+
const storage = null;
38+
// Set the folder where the document is stored.
39+
const folder = "Documents";
40+
41+
// Read the file from file system.
42+
const buffer = fs.readFileSync("testData/" + fileName);
43+
// Upload the file to cloud storage.
44+
const uploadResponse = await api.uploadFile(folder + "/" + fileName, buffer, storage)
45+
46+
// Swagger documentation available at:
47+
// https://reference.aspose.cloud/pdf/#/Document/PostSplitDocument
48+
// Split the PDF document per page.
49+
const result = await api.postSplitDocument(
50+
uploadResponse.body.uploaded[0],
51+
format,
52+
pageFrom,
53+
pageTo,
54+
storage,
55+
folder);
56+
57+
// Log the response to console.
58+
console.log(result.body.status);
59+
// Log split result.
60+
result.body.result.documents.forEach((document, index) =>
61+
{
62+
console.log(index + 1 + ") " + document.href);
63+
});
64+
}
65+
66+
// Execute the splitDocument function.
67+
splitDocument();

0 commit comments

Comments
 (0)