Skip to content

Commit 781354b

Browse files
RakhimAimaganbetovMrRakhimyevgen-nykytenko
authored
Initial examples implementation
* initial commit * initial commit #2 * add gitignore * add dependency dowloader, module & lowerize the method names * Update README.md * Update README.md * update Readme.md * make all files camelCased * remove dsStores & move runExample into examples * Update README.md * interacting with a published package * update readme.md * process files without license --------- Co-authored-by: Rakhim <rz.aimaganbetov@gmail.com> Co-authored-by: Yevgen Nykytenko <yevgen.nykytenko@aspose.com>
1 parent 9d8edfb commit 781354b

19 files changed

Lines changed: 2915 additions & 2 deletions

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
### VisualStudioCode ###
2+
.vscode
3+
.vscode/*
4+
!.vscode/settings.json
5+
!.vscode/tasks.json
6+
!.vscode/launch.json
7+
!.vscode/extensions.json
8+
!.vscode/*.code-snippets
9+
10+
# Local History for Visual Studio Code
11+
.history/
12+
13+
# Built Visual Studio Code Extensions
14+
*.vsix
15+
16+
# Ignore all local history of files
17+
.history
18+
.ionide
19+
20+
### macOS ###
21+
# General
22+
.DS_Store
23+
.AppleDouble
24+
.LSOverride
25+
26+
### Node ###
27+
# Logs
28+
logs
29+
*.log
30+
npm-debug.log*
31+
yarn-debug.log*
32+
yarn-error.log*
33+
lerna-debug.log*
34+
.pnpm-debug.log*
35+
36+
# Compiled binary addons (https://nodejs.org/api/addons.html)
37+
build/Release
38+
Output
39+
40+
# Dependency directories
41+
node_modules/
42+
43+
# Optional npm cache directory
44+
.npm
45+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* This example demonstrates how to convert DOCX file into PDF format with advanced options.
3+
* For more details about Microsoft Word Open XML Document (.docx) to Portable Document (.pdf) conversion please check this documentation article
4+
* https://docs.groupdocs.com/conversion
5+
*/
6+
async function convertToPdfWithAdvancedOptions(groupdocs, inputFilePath) {
7+
const loadOptions = new groupdocs.conversion.WordProcessingLoadOptions()
8+
loadOptions.setPassword('12345')
9+
10+
const converter = new groupdocs.conversion.Converter(inputFilePath, loadOptions)
11+
12+
const outputPath = `${groupdocs.outputFolder}/ConvertToPdfWithAdvancedOptions.pdf`
13+
const convertOptions = new groupdocs.conversion.PdfConvertOptions()
14+
convertOptions.setPageNumber(2)
15+
convertOptions.setPagesCount(1)
16+
convertOptions.setRotate(groupdocs.conversion.Rotation.On180)
17+
convertOptions.setDpi(300)
18+
convertOptions.setWidth(1024)
19+
convertOptions.setHeight(768)
20+
console.log(`Converted to ${outputPath}`)
21+
return converter.convert(outputPath, convertOptions)
22+
}
23+
24+
module.exports = convertToPdfWithAdvancedOptions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This example demonstrates how to convert DOCX file into PDF format.
3+
* For more details about Microsoft Word Open XML Document (.docx) to Portable Document (.pdf) conversion please check this documentation article
4+
* https://docs.groupdocs.com/conversion
5+
*/
6+
async function convertToPdf(groupdocs, inputFilePath) {
7+
const converter = new groupdocs.conversion.Converter(inputFilePath)
8+
const convertOptions = new groupdocs.conversion.PdfConvertOptions()
9+
const outputPath = `${groupdocs.outputFolder}/output.pdf`
10+
11+
console.log(`Converted to ${outputPath}`)
12+
return converter.convert(outputPath, convertOptions)
13+
}
14+
15+
module.exports = convertToPdf
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This example demonstrates how to convert DOCX file into PPTX format.
3+
* For more details about Microsoft Word Open XML Document (.docx) to PowerPoint Open XML Presentation (.pptx) conversion please check this documentation article
4+
* https://docs.groupdocs.com/conversion
5+
*/
6+
async function convertToPresentation(groupdocs, inputFilePath) {
7+
const converter = new groupdocs.conversion.Converter(inputFilePath)
8+
const convertOptions = new groupdocs.conversion.PresentationConvertOptions()
9+
const outputPath = `${groupdocs.outputFolder}/output.pptx`
10+
11+
console.log(`Converted to ${outputPath}`)
12+
return converter.convert(outputPath, convertOptions)
13+
}
14+
15+
module.exports = convertToPresentation
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This example demonstrates how to convert DOCX file into XLSX format.
3+
* For more details about Microsoft Word Open XML Document (.docx) to Microsoft Excel Open XML Spreadsheet (.xlsx) conversion please check this documentation article
4+
* https://docs.groupdocs.com/conversion
5+
*/
6+
async function convertToSpreadsheet(groupdocs, inputFilePath) {
7+
const converter = new groupdocs.conversion.Converter(inputFilePath)
8+
const convertOptions = new groupdocs.conversion.SpreadsheetConvertOptions()
9+
const outputPath = `${groupdocs.outputFolder}/output.xlsx`
10+
11+
console.log(`Converted to ${outputPath}`)
12+
return converter.convert(outputPath, convertOptions)
13+
}
14+
15+
module.exports = convertToSpreadsheet
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This example demonstrates how to convert PDF file into DOCX format.
3+
* For more details about Portable Document (.pdf) to Microsoft Word Open XML Document (.docx) conversion please check this documentation article
4+
* https://docs.groupdocs.com/conversion
5+
*/
6+
async function convertToWordProcessing(groupdocs, inputFilePath) {
7+
const converter = new groupdocs.conversion.Converter(inputFilePath)
8+
const convertOptions = new groupdocs.conversion.WordProcessingConvertOptions()
9+
const outputPath = `${groupdocs.outputFolder}/output.docx`
10+
11+
console.log(`Converted to ${outputPath}`)
12+
return converter.convert(outputPath, convertOptions)
13+
}
14+
15+
module.exports = convertToWordProcessing
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const util = require('util')
2+
3+
/**
4+
* This example demonstrates how to get to what formats the source document could be converted
5+
*/
6+
function getPossibleConversions(groupdocs, inputFilePath) {
7+
const converter = new groupdocs.conversion.Converter(inputFilePath)
8+
const conversions = converter.getPossibleConversions()
9+
console.log(
10+
util.format(
11+
'%s is of type %s and could be converted to:\n',
12+
inputFilePath,
13+
conversions.getSource().getExtension()
14+
)
15+
)
16+
17+
const items = conversions.getAll()
18+
console.log(items)
19+
20+
items.spliterator().getExactSizeIfKnown()
21+
22+
for (let i = 0; i < items.size(); i += 1) {
23+
const item = items.get(i)
24+
console.log(
25+
`\t ${item.getFormat().getExtension()} as ${
26+
item.isPrimary() ? 'primary' : 'secondary'
27+
} conversion.\n`
28+
)
29+
}
30+
}
31+
32+
module.exports = getPossibleConversions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const util = require('util')
2+
const fs = require('fs')
3+
4+
/**
5+
* This example demonstrates how to convert DOCX file into PNG format.
6+
* For more details about Microsoft Word Open XML Document (.docx) to Portable Network Graphic (.png) conversion please check this documentation article
7+
* https://docs.groupdocs.com/conversion
8+
*/
9+
async function convertToImagePng(groupdocs, inputFilePath, outputFolder) {
10+
const outputFileTemplate = `${outputFolder}/converted-page-%d.png`
11+
12+
const getPageStream = fs.createWriteStream(util.format(outputFileTemplate, 1))
13+
const converter = new groupdocs.conversion.Converter(inputFilePath)
14+
15+
const convertOptions = new groupdocs.conversion.ImageConvertOptions()
16+
convertOptions.setFormat(groupdocs.conversion.ImageFileType.Png)
17+
convertOptions.setPagesCount(1)
18+
19+
console.log(`Converted to ${outputFolder}`)
20+
return converter.convert(getPageStream, convertOptions)
21+
}
22+
23+
module.exports = convertToImagePng
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* This example demonstrates how to get basic information about source document.
3+
*/
4+
function getSourceDocumentInfo(groupdocs, inputFilePath) {
5+
const converter = new groupdocs.conversion.Converter(inputFilePath)
6+
const pdfInfo = converter.getDocumentInfo()
7+
8+
console.log(`Author: ${pdfInfo.getAuthor()}`)
9+
console.log(`Creation date: ${pdfInfo.getCreationDate()}`)
10+
console.log(`Title: ${pdfInfo.getTitle()}`)
11+
console.log(`Version: ${pdfInfo.getVersion()}`)
12+
console.log(`Pages count: ${pdfInfo.getPagesCount()}`)
13+
console.log(`Width: ${pdfInfo.getWidth()}`)
14+
console.log(`Height: ${pdfInfo.getHeight()}`)
15+
console.log(`Is landscaped: ${pdfInfo.isLandscape()}`)
16+
console.log(`Is Encrypted: ${pdfInfo.isPasswordProtected()}`)
17+
18+
console.log('\nDocument info retrieved successfully.')
19+
}
20+
21+
module.exports = getSourceDocumentInfo

Examples/QuickStart/SetLicense.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fs = require('fs')
2+
3+
/**
4+
* This example demonstrates how to set license from stream.
5+
*/
6+
async function setLicense(groupdocs, licensePath) {
7+
const lic = new groupdocs.conversion.License()
8+
const readStream = fs.createReadStream(licensePath)
9+
10+
return new Promise((resolve, reject) =>
11+
// eslint-disable-next-line no-promise-executor-return
12+
groupdocs.conversion.License.setLicenseFromStream(lic, readStream, err => {
13+
if (err) {
14+
console.log("\nWe do not ship any license with this example. " +
15+
"\nVisit the GroupDocs site to obtain either a temporary or permanent license. " +
16+
"\nLearn more about licensing at https://purchase.groupdocs.com/faqs/licensing. " +
17+
"\nLear how to request temporary license at https://purchase.groupdocs.com/temporary-license.");
18+
resolve()
19+
} else {
20+
console.log('License set successfully.')
21+
resolve()
22+
}
23+
})
24+
)
25+
}
26+
27+
module.exports = setLicense

0 commit comments

Comments
 (0)