Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GroupDocs.Conversion for Node.js via Java examples, plugins and showcase projects

License

NotificationsYou must be signed in to change notification settings

groupdocs-conversion/GroupDocs.Conversion-for-Node.js-via-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Quick Start

Prerequisites

  • Node.js 20 LTS or later
  • Java JRE/JDK 8+ (17 LTS recommended)
  • Java Environment: SetJAVA_HOME and 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:

Installation

npm install

This installs the bundled package (@groupdocs/groupdocs.conversion) referenced inpackage.json.

Running Examples

Run All Examples

Execute all examples:

npm start

Or directly:

node Examples/runExamples.js

Outputs are saved toExamples/Output/<example-name>/.

Example Structure

Examples are organized into three categories:

QuickStart

Minimal examples to get started:

  • setLicense.js - License setup from stream (callback-based API)
  • setLicenseFromFile.js - License setup from file path
  • setLicenseFromStream.js - License setup from file stream

BasicUsage

Core conversion functionality examples:

FileWhat It Demonstrates
convertToPdf.jsConvert DOCX to PDF
convertToHtml.jsConvert document to HTML
convertToWordProcessing.jsConvert PDF to DOCX
convertToSpreadsheet.jsConvert DOCX to XLSX
convertToPresentation.jsConvert DOCX to PPTX
convertToImagePng.jsConvert DOCX to PNG image
getPossibleConversions.jsGet all supported conversion formats for a document
getSourceDocumenInfo.jsGet document metadata and properties

AdvancedUsage

Advanced scenarios organized by feature:

Converting (AdvancedUsage/Converting/)

  • convertToPdfWithAdvancedOptions.js - Convert password-protected document to PDF with page selection, rotation, DPI, and custom dimensions
  • convertToHtmlWithAdvancedOptions.js - Convert password-protected document to HTML with fixed layout and page selection
  • convertToImageWithAdvancedOptions.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 specification
  • convertToSpreadsheetWithAdvancedOptions.js - Convert password-protected document to XLS with page selection
  • convertToPresentationWithAdvancedOptions.js - Convert password-protected document to PPT with page selection
  • common/addWatermark.js - Add watermark text during conversion
  • common/convertNConsecutivePages.js - Convert a range of consecutive pages
  • common/convertSpecificPages.js - Convert specific pages by page numbers

Loading (AdvancedUsage/Loading/)

LoadOptionsFromDifferentSources:

  • loadDocumentFromLocalDisk.js - Load document from local file system
  • loadDocumentFromStream.js - Load document from file stream
  • loadDocumentFromUrl.js - Download and convert document from URL

LoadOptionsByDocumentType:

PDF:

  • Pdf/convertPdfAndFlattenAllFields.js - Flatten PDF form fields during conversion
  • Pdf/convertPdfAndHideAnnotations.js - Hide PDF annotations during conversion
  • Pdf/convertPdfAndRemoveEmbeddedFiles.js - Remove embedded files from PDF

Word Processing:

  • WordProcessing/convertWordProcessingByHidingComments.js - Hide comments in Word documents
  • WordProcessing/convertWordProcessingByHidingTrackedChanges.js - Hide tracked changes in Word documents
  • WordProcessing/convertWordProcessingBySpecifyingFontSubstitution.js - Custom font substitution for Word documents

Spreadsheet:

  • Spreadsheet/convertSpreadsheetAndHideComments.js - Hide comments in spreadsheets
  • Spreadsheet/convertSpreadsheetByShowingGridLines.js - Show grid lines in spreadsheet conversion
  • Spreadsheet/convertSpreadsheetBySkippingEmptyRowsAndColumns.js - Skip empty rows and columns
  • Spreadsheet/convertSpreadsheetBySpecifyingRange.js - Convert specific row range (e.g., rows 10-30)
  • Spreadsheet/convertSpreadsheetBySpecifyingFontsubstitution.js - Custom font substitution for spreadsheets
  • Spreadsheet/convertSpreadsheetWithHiddenSheetsIncluded.js - Include hidden sheets in conversion

Presentation:

  • Presentation/convertPresentationByHidingComments.js - Hide comments in presentations
  • Presentation/convertPresentationBySpecifyingFontSubstitution.js - Custom font substitution for presentations
  • Presentation/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 delimiter
  • Csv/convertCsvBySpecifyingEncoding.js - Convert CSV with specific encoding
  • Csv/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 layouts
  • Cad/convertCadAndSpecifyWidthAndHeight.js - Convert CAD with custom dimensions

Note:

  • Note/convertNoteBySpecifyingFontSubstitution.js - Custom font substitution for OneNote documents

Example Code Snippets

Basic Conversion (DOCX to PDF)

// BasicUsage/convertToPdf.jsconstconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constconvertOptions=newgroupdocs.PdfConvertOptions();constoutputPath=`${Constants.OUTPUT_FOLDER}/ConvertToPdf.pdf`;awaitconverter.convert(outputPath,convertOptions);

Basic Conversion (Document to HTML)

// BasicUsage/convertToHtml.jsconstconverter=newgroupdocs.Converter(Constants.SAMPLE_DOCX);constconvertOptions=newgroupdocs.MarkupConvertOptions();constoutputPath=`${Constants.OUTPUT_FOLDER}/ConvertToHtml.html`;awaitconverter.convert(outputPath,convertOptions);

Password-Protected Document

// 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);

Add Watermark

// 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);

Convert Specific Pages

// 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);

Load from Stream

// 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);

Load from URL

// 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);

Get Document Info

// 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()}`);

Get Possible Conversions

// 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`);}

Using the Examples Module

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();

Project Structure

├── 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 and Output

  • 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.

License Setup (Optional)

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

Supported Formats

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

Troubleshooting

Java Not Detected

SetJAVA_HOME and add toPATH (see Prerequisites above).

Build Errors

Install build tools:

  • Windows: Visual Studio Build Tools
  • Linux:sudo apt-get install build-essential
  • macOS:xcode-select --install

Output Permission Errors

Ensure write access toExamples/Output/ directory.

Missing Fonts

Install common fonts (especially on Linux servers):

  • Microsoft Core Fonts
  • Liberation Fonts
  • DejaVu Fonts

License Errors

If you see license-related messages, ensure:

  1. License file path is correct in.env orConstants.LICENSE_PATH
  2. License file is valid and not expired
  3. License matches the product version

Resources


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

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp