- Notifications
You must be signed in to change notification settings - Fork2
GroupDocs.Conversion for Node.js via Java examples, plugins and showcase projects
License
groupdocs-conversion/GroupDocs.Conversion-for-Node.js-via-Java
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This repository contains runnable code examples demonstrating how to use GroupDocs.Conversion for Node.js via Java to convert documents, spreadsheets, presentations, PDFs, images, emails, and more between various formats.
- Node.js 20 LTS or later
- Java JRE/JDK 8+ (17 LTS recommended)
- Java Environment: Set
JAVA_HOMEand add toPATH
Windows PowerShell:
$env:JAVA_HOME="C:\Program Files\Java\jdk-17"$env:Path="$env:JAVA_HOME\bin;$env:Path"
Linux/macOS:
export JAVA_HOME=/usr/lib/jvm/java-17-openjdkexport PATH=$JAVA_HOME/bin:$PATH
For detailed installation instructions and platform-specific notes, refer to the documentation:
npm install
This installs the bundled package (@groupdocs/groupdocs.conversion) referenced inpackage.json.
Execute all examples:
npm start
Or directly:
node Examples/runExamples.js
Outputs are saved toExamples/Output/<example-name>/.
Examples are organized into three categories:
Minimal examples to get started:
setLicense.js- License setup from stream (callback-based API)setLicenseFromFile.js- License setup from file pathsetLicenseFromStream.js- License setup from file stream
Core conversion functionality examples:
| File | What It Demonstrates |
|---|---|
convertToPdf.js | Convert DOCX to PDF |
convertToHtml.js | Convert document to HTML |
convertToWordProcessing.js | Convert PDF to DOCX |
convertToSpreadsheet.js | Convert DOCX to XLSX |
convertToPresentation.js | Convert DOCX to PPTX |
convertToImagePng.js | Convert DOCX to PNG image |
getPossibleConversions.js | Get all supported conversion formats for a document |
getSourceDocumenInfo.js | Get document metadata and properties |
Advanced scenarios organized by feature:
convertToPdfWithAdvancedOptions.js- Convert password-protected document to PDF with page selection, rotation, DPI, and custom dimensionsconvertToHtmlWithAdvancedOptions.js- Convert password-protected document to HTML with fixed layout and page selectionconvertToImageWithAdvancedOptions.js- Convert PDF to PNG with image transformations (flip, brightness, contrast, gamma, grayscale, resolution)convertToWordProcessingWithAdvancedOptions.js- Convert PDF to DOCX with page selection and format specificationconvertToSpreadsheetWithAdvancedOptions.js- Convert password-protected document to XLS with page selectionconvertToPresentationWithAdvancedOptions.js- Convert password-protected document to PPT with page selectioncommon/addWatermark.js- Add watermark text during conversioncommon/convertNConsecutivePages.js- Convert a range of consecutive pagescommon/convertSpecificPages.js- Convert specific pages by page numbers
LoadOptionsFromDifferentSources:
loadDocumentFromLocalDisk.js- Load document from local file systemloadDocumentFromStream.js- Load document from file streamloadDocumentFromUrl.js- Download and convert document from URL
LoadOptionsByDocumentType:
PDF:
Pdf/convertPdfAndFlattenAllFields.js- Flatten PDF form fields during conversionPdf/convertPdfAndHideAnnotations.js- Hide PDF annotations during conversionPdf/convertPdfAndRemoveEmbeddedFiles.js- Remove embedded files from PDF
Word Processing:
WordProcessing/convertWordProcessingByHidingComments.js- Hide comments in Word documentsWordProcessing/convertWordProcessingByHidingTrackedChanges.js- Hide tracked changes in Word documentsWordProcessing/convertWordProcessingBySpecifyingFontSubstitution.js- Custom font substitution for Word documents
Spreadsheet:
Spreadsheet/convertSpreadsheetAndHideComments.js- Hide comments in spreadsheetsSpreadsheet/convertSpreadsheetByShowingGridLines.js- Show grid lines in spreadsheet conversionSpreadsheet/convertSpreadsheetBySkippingEmptyRowsAndColumns.js- Skip empty rows and columnsSpreadsheet/convertSpreadsheetBySpecifyingRange.js- Convert specific row range (e.g., rows 10-30)Spreadsheet/convertSpreadsheetBySpecifyingFontsubstitution.js- Custom font substitution for spreadsheetsSpreadsheet/convertSpreadsheetWithHiddenSheetsIncluded.js- Include hidden sheets in conversion
Presentation:
Presentation/convertPresentationByHidingComments.js- Hide comments in presentationsPresentation/convertPresentationBySpecifyingFontSubstitution.js- Custom font substitution for presentationsPresentation/convertPresentationWithHiddenSlidesIncluded.js- Include hidden slides in conversion
Text:
Txt/convertTxtBySpecifyingEncoding.js- Convert text files with specific encoding (e.g., Shift-JIS)Txt/convertTxtByControllingLeadingSpacesBehavior.js- Control leading spaces behavior (convert to indent)Txt/convertTxtByControllingTrailingSpacesBehavior.js- Control trailing spaces behavior (trim)
CSV:
Csv/convertCsvBySpecifyingDelimiter.js- Convert CSV with custom delimiterCsv/convertCsvBySpecifyingEncoding.js- Convert CSV with specific encodingCsv/convertCsvByConvertingDateTimeAndNumericData.js- Automatic date/time and numeric data conversion
XML:
Xml/convertXmlAsDataSourceToSpreadsheet.js- Convert XML as data source to spreadsheet
Email:
Email/convertEmailWithAlteringFieldsVisibility.js- Control email field visibility (header, addresses, etc.)
CAD:
Cad/convertCadAndSpecifyLayouts.js- Convert specific CAD layoutsCad/convertCadAndSpecifyWidthAndHeight.js- Convert CAD with custom dimensions
Note:
Note/convertNoteBySpecifyingFontSubstitution.js- Custom font substitution for OneNote documents
// BasicUsage/convertToPdf.jsconstconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constconvertOptions=newgroupdocs.PdfConvertOptions();constoutputPath=`${Constants.OUTPUT_FOLDER}/ConvertToPdf.pdf`;awaitconverter.convert(outputPath,convertOptions);
// BasicUsage/convertToHtml.jsconstconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constconvertOptions=newgroupdocs.MarkupConvertOptions();constoutputPath=`${Constants.OUTPUT_FOLDER}/ConvertToHtml.html`;awaitconverter.convert(outputPath,convertOptions);
// AdvancedUsage/Converting/convertToPdfWithAdvancedOptions.jsconstloadOptions=newgroupdocs.WordProcessingLoadOptions();loadOptions.setPassword('12345');constconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX_WITH_PASSWORD,loadOptions);constconvertOptions=newgroupdocs.PdfConvertOptions();convertOptions.setPageNumber(2);convertOptions.setPagesCount(1);convertOptions.setRotate(groupdocs.Rotation.On180);convertOptions.setDpi(300);convertOptions.setWidth(1024);convertOptions.setHeight(768);awaitconverter.convert(outputPath,convertOptions);
// AdvancedUsage/Converting/common/addWatermark.jsconstconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constconvertOptions=newgroupdocs.PdfConvertOptions();constwatermark=newgroupdocs.WatermarkTextOptions("Sample watermark");watermark.setColor("red");watermark.setWidth(100);watermark.setHeight(100);watermark.setBackground(true);convertOptions.setWatermark(watermark);awaitconverter.convert(outputPath,convertOptions);
// AdvancedUsage/Converting/common/convertSpecificPages.jsconstArrayList=require('java').import('java.util.ArrayList');constconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constconvertOptions=newgroupdocs.PdfConvertOptions();constpages=newArrayList();pages.add(1);// First pagepages.add(3);// Third pageconvertOptions.setPages(pages);awaitconverter.convert(outputPath,convertOptions);
// AdvancedUsage/Loading/LoadOptionsFromDifferentSources/loadDocumentFromStream.jsconstfs=require('fs');constreadStream=fs.createReadStream(Constants.SAMPLE_DOCX);conststream=awaitgroupdocs.readDataFromStream(readStream);constconverter=newgroupdocs.Converter(stream);constconvertOptions=newgroupdocs.PdfConvertOptions();awaitconverter.convert(outputPath,convertOptions);
// AdvancedUsage/Loading/LoadOptionsFromDifferentSources/loadDocumentFromUrl.jsconstjava=require('java');constURL=java.import('java.net.URL');consturl='https://example.com/document.docx';conststream=newURL(url).openStream();constconverter=newgroupdocs.Converter(stream);constconvertOptions=newgroupdocs.PdfConvertOptions();awaitconverter.convert(outputPath,convertOptions);
// BasicUsage/getSourceDocumenInfo.jsconstconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constdocumentInfo=converter.getDocumentInfo();console.log(`Author:${documentInfo.getAuthor()}`);console.log(`Pages count:${documentInfo.getPagesCount()}`);console.log(`Width:${documentInfo.getWidth()}`);console.log(`Height:${documentInfo.getHeight()}`);
// BasicUsage/getPossibleConversions.jsconstconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constconversions=converter.getPossibleConversions();console.log(`Source type:${conversions.getSource().getExtension()}`);constitems=conversions.getAll();for(leti=0;i<items.size();i+=1){constitem=items.get(i);console.log(`${item.getFormat().getExtension()} as${item.isPrimary() ?'primary' :'secondary'} conversion`);}
All examples are accessible throughExamples/examples.js:
constexamples=require('./Examples/examples');// Basic examplesawaitexamples.getPossibleConversions();awaitexamples.getSourceDocumentInfo();awaitexamples.convertToHtml();awaitexamples.convertToPdf();awaitexamples.convertToWordProcessing();awaitexamples.convertToSpreadsheet();awaitexamples.convertToPresentation();awaitexamples.convertToImagePng();// Advanced examplesawaitexamples.convertToPdfWithAdvancedOptions();awaitexamples.addWatermark();awaitexamples.convertConsecutivePagesPdf();awaitexamples.convertSpecificPages();awaitexamples.loadDocumentFromStream();awaitexamples.loadDocumentFromUrl();awaitexamples.convertPdfAndFlattenAllFields();awaitexamples.convertWordProcessingByHidingComments();
├── Examples/│ ├── BasicUsage/ # Basic conversion examples│ │ ├── convertToPdf.js│ │ ├── convertToHtml.js│ │ ├── convertToWordProcessing.js│ │ ├── convertToSpreadsheet.js│ │ ├── convertToPresentation.js│ │ ├── convertToImagePng.js│ │ ├── getPossibleConversions.js│ │ └── getSourceDocumenInfo.js│ ││ ├── AdvancedUsage/ # Advanced features│ │ ├── Converting/ # Advanced conversion scenarios│ │ │ ├── convertToPdfWithAdvancedOptions.js│ │ │ ├── convertToHtmlWithAdvancedOptions.js│ │ │ ├── convertToImageWithAdvancedOptions.js│ │ │ └── common/│ │ │ ├── addWatermark.js│ │ │ ├── convertNConsecutivePages.js│ │ │ └── convertSpecificPages.js│ │ ││ │ └── Loading/ # Document loading options│ │ ├── LoadOptionsFromDifferentSources/│ │ │ ├── loadDocumentFromLocalDisk.js│ │ │ ├── loadDocumentFromStream.js│ │ │ └── loadDocumentFromUrl.js│ │ ││ │ └── LoadOptionsByDocumentType/│ │ ├── Pdf/│ │ ├── WordProcessing/│ │ ├── Spreadsheet/│ │ ├── Presentation/│ │ ├── Txt/│ │ ├── Csv/│ │ ├── Xml/│ │ ├── Email/│ │ ├── Cad/│ │ └── Note/│ ││ ├── QuickStart/ # Quick start examples│ │ ├── setLicense.js│ │ ├── setLicenseFromFile.js│ │ └── setLicenseFromStream.js│ ││ ├── Resources/│ │ └── SampleFiles/ # Sample input files│ │ ├── sample.docx│ │ ├── sample.pdf│ │ ├── sample.xlsx│ │ └── ...│ ││ ├── Output/ # Generated results (auto-created)│ ││ ├── constants.js # File paths and configuration│ ├── examples.js # Example runner module│ └── runExamples.js # Run all examples│├── .env.example # Environment variables template├── package.json└── README.md- Input Files:
Examples/Resources/SampleFiles/(configured inExamples/constants.js) - Output Files:
Examples/Output/<example-name>/(auto-created per example)
ModifyExamples/constants.js to change paths if needed.
Examples run in trial mode by default. To use a license:
Option 1: Environment variable
Create.env:
GROUPDOCS_LICENSE=C:\path\to\license.lic
Option 2: Programmatic
constexamples=require('./Examples/examples');awaitexamples.setLicenseFromFile(Constants.LICENSE_PATH);
Get a temporary license:GroupDocs Temporary License
GroupDocs.Conversion supports conversion between 50+ document formats including:
- Word Processing: DOC, DOCX, RTF, ODT, TXT
- Spreadsheet: XLS, XLSX, CSV, ODS
- Presentation: PPT, PPTX, ODP
- PDF: PDF
- Images: PNG, JPEG, BMP, TIFF, GIF, SVG
- Markup: HTML, XML
- Email: MSG, EML, EMLX
- CAD: DWG, DXF, DWF
- Note: ONE
- And more...
For a complete list, see:Supported File Formats
SetJAVA_HOME and add toPATH (see Prerequisites above).
Install build tools:
- Windows: Visual Studio Build Tools
- Linux:
sudo apt-get install build-essential - macOS:
xcode-select --install
Ensure write access toExamples/Output/ directory.
Install common fonts (especially on Linux servers):
- Microsoft Core Fonts
- Liberation Fonts
- DejaVu Fonts
If you see license-related messages, ensure:
- License file path is correct in
.envorConstants.LICENSE_PATH - License file is valid and not expired
- License matches the product version
- Documentation:docs.groupdocs.com/conversion/nodejs-java
- API Reference:apireference.groupdocs.com/conversion/nodejs-java
- Support Forum:forum.groupdocs.com/c/conversion
- Product Page:products.groupdocs.com/conversion/nodejs-java
Note: These are code examples demonstrating GroupDocs.Conversion features. For production use, ensure you have a valid license.
About
GroupDocs.Conversion for Node.js via Java examples, plugins and showcase projects
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.