This guide provides a quick overview of how to set up and start using GroupDocs.Conversion for Java. This library enables developers to convert between various file formats (e.g., DOCX, PDF, PNG) with minimal configuration.
Prerequisites
To proceed, make sure you have:
Configured your development environment as described in the System Requirements topic.
Optionally, obtained a Temporary License to test all product features.
Set Up Your Development Environment
Install GroupDocs.Conversion for Java
Download the latest GroupDocs.Conversion for Java from the official website or include it in your project via Maven:
business-plan.docx is sample file used in this example. Click here to download it.
business-plan.pdf is expected output PDF file. Click here to download it.
Explanation
Converter("./business-plan.docx"): Initializes the converter with the DOCX file.
PdfConvertOptions(): Specifies the output format as PDF.
converter.convert("./business-plan.pdf", options): Converts the DOCX file to PDF and saves it.
Example 2: Convert PDF Pages to PNG
Java Implementation
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.contracts.SavePageStream;importcom.groupdocs.conversion.filetypes.ImageFileType;importcom.groupdocs.conversion.options.convert.ImageConvertOptions;importjava.io.FileOutputStream;importjava.io.IOException;publicclassConvertPdfPagesToPng{publicstaticvoidmain(String[]args){StringinputFilePath="./annual-review.pdf";StringoutputFile="./converted-pages/pdf-converted-page-%d.png";SavePageStreamgetPageStream=page->{try{returnnewFileOutputStream(String.format(outputFile,page));}catch(IOExceptione){e.printStackTrace();returnnull;// Return null to handle it later
}};try(Converterconverter=newConverter(inputFilePath)){ImageConvertOptionsoptions=newImageConvertOptions();options.setFormat(ImageFileType.PNG);converter.convert(getPageStream,options);System.out.println("PDF pages converted to PNG successfully.");}catch(Exceptione){e.printStackTrace();}}}
annual-review.pdf is sample file used in this example. Click here to download it.
converted-pages is output folder where converted pages are stored. Click here to download the output PNG files.
Explanation
Converter("./annual-review.pdf"): Initializes the converter with the PDF file.
SavePageStream: Implements a lambda function that provides an output stream for each page.
ImageConvertOptions(): Specifies the output format as image.
ImageFileType.PNG: Sets the output image format to PNG.
converter.convert(getPageStream, png_convert_options): Converts the PDF file pages to PNG and saves output file in converted-pages folder.
Next Steps
After completing the basics, explore additional resources to enhance your usage: