Skip to content

Commit 4f406c1

Browse files
Split use cases
1 parent 87927c0 commit 4f406c1

File tree

3 files changed

+220
-0
lines changed

3 files changed

+220
-0
lines changed

UsesCases/Split/parts/parts.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
const api = new PdfApi("http://172.17.0.1:5000/v3.0");
27+
28+
// Set the document name.
29+
const fileName = "4pages.pdf";
30+
// Set the page ranges for splitting.
31+
// Documentation available at: https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-node.js/blob/master/docs/SplitRangePdfOptions.md
32+
const options =
33+
{
34+
pageRanges: [
35+
// first and second pages.
36+
{
37+
to: 2
38+
},
39+
// third and fourth pages.
40+
{
41+
from: 3
42+
},
43+
// second and third pages.
44+
{
45+
from: 2,
46+
to: 3
47+
},
48+
// first page.
49+
{
50+
from: 1,
51+
to: 1
52+
}
53+
]
54+
};
55+
// Use default storage (null indicates default storage).
56+
const storage = null;
57+
// Set the folder where the document is stored.
58+
const folder = "Documents";
59+
60+
// Read file from file system.
61+
const buffer = fs.readFileSync("testData/" + fileName);
62+
// Upload file to cloud storage.
63+
const uploadResponse = await api.uploadFile(folder + "/" + fileName, buffer, storage)
64+
65+
// Swagger documentation available at:
66+
// https://reference.aspose.cloud/pdf/#/Document/PostSplitRangePdfDocument
67+
// Split PDF document to page ranges.
68+
const result = await api.postSplitRangePdfDocument(
69+
uploadResponse.body.uploaded[0],
70+
options,
71+
storage,
72+
folder);
73+
74+
// Log the response to console.
75+
console.log(result.body.status);
76+
// Log split result.
77+
result.body.result.documents.forEach((document, index) =>
78+
{
79+
console.log(index + 1 + ") " + document.href);
80+
});
81+
}
82+
83+
// Execute the splitDocumentRanges function.
84+
splitDocumentRanges();

UsesCases/Split/single/single.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
const api = new PdfApi("http://172.17.0.1:5000/v3.0");
27+
28+
// Set the document name.
29+
const fileName = "4pages.pdf";
30+
// Set the start page number.
31+
const pageFrom = 2;
32+
// Set the end page number same as pageFrom.
33+
const pageTo = 2;
34+
// Set the resulting documents format.
35+
// Available formats are: PDF, PDFA1A, PDFA1B, PDFA3A, PDFA3B, DOC, DOCX, XLS, XPS, TIFF, SVG, JPEG, JPG, PNG, EMF, BMP, GIF, PPTX, EPUB.
36+
const format = "PDF";
37+
// Use default storage (null indicates default storage).
38+
const storage = null;
39+
// Set the folder where the document is stored.
40+
const folder = "Documents";
41+
42+
// Read file from file system.
43+
const buffer = fs.readFileSync("testData/" + fileName);
44+
// Upload file to cloud storage.
45+
const uploadResponse = await api.uploadFile(folder + "/" + fileName, buffer, storage)
46+
47+
// Swagger documentation available at:
48+
// https://reference.aspose.cloud/pdf/#/Document/PostSplitDocument
49+
// Split PDF document to single page.
50+
const result = await api.postSplitDocument(
51+
uploadResponse.body.uploaded[0],
52+
format,
53+
pageFrom,
54+
pageTo,
55+
storage,
56+
folder);
57+
58+
// Log the response to console.
59+
console.log(result.body.status);
60+
// Log split result.
61+
result.body.result.documents.forEach((document, index) =>
62+
{
63+
console.log(index + 1 + ") " + document.href);
64+
});
65+
}
66+
67+
// Execute the splitDocument function.
68+
splitDocument();

UsesCases/Split/split.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
const api = new PdfApi("http://172.17.0.1:5000/v3.0");
27+
28+
// Set the document name.
29+
const fileName = "4pages.pdf";
30+
// Set the start page number (null means from begin of document).
31+
const pageFrom = null;
32+
// Set the end page number (null means to end of document).
33+
const pageTo = null;
34+
// Set the resulting documents format.
35+
// Available formats are: PDF, PDFA1A, PDFA1B, PDFA3A, DOC, DOCX, XLS, XPS, TIFF, SVG, JPEG, JPG, PNG, EMF, BMP, GIF, PPTX, EPUB.
36+
const format = "PDF";
37+
// Use default storage (null indicates default storage).
38+
const storage = null;
39+
// Set the folder where the document is stored.
40+
const folder = "Documents";
41+
42+
// Read file from file system.
43+
const buffer = fs.readFileSync("testData/" + fileName);
44+
// Upload file to cloud storage.
45+
const uploadResponse = await api.uploadFile(folder + "/" + fileName, buffer, storage)
46+
47+
// Swagger documentation available at:
48+
// https://reference.aspose.cloud/pdf/#/Document/PostSplitDocument
49+
// Split PDF document per page.
50+
const result = await api.postSplitDocument(
51+
uploadResponse.body.uploaded[0],
52+
format,
53+
pageFrom,
54+
pageTo,
55+
storage,
56+
folder);
57+
58+
// Log the response to console.
59+
console.log(result.body.status);
60+
// Log split result.
61+
result.body.result.documents.forEach((document, index) =>
62+
{
63+
console.log(index + 1 + ") " + document.href);
64+
});
65+
}
66+
67+
// Execute the splitDocument function.
68+
splitDocument();

0 commit comments

Comments
 (0)