Last active
April 12, 2022 11:32
-
-
Save groupdocs-com-kb/e70e63050f55e95b5264e6efde409545 to your computer and use it in GitHub Desktop.
How to Convert Word to PDF in Java. For more information, please follow link: https://kb.groupdocs.com/conversion/java/how-to-convert-word-to-pdf-in-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.groupdocs.conversion.Converter; | |
import com.groupdocs.conversion.licensing.License; | |
import com.groupdocs.conversion.options.convert.PdfConvertOptions; | |
import com.groupdocs.conversion.options.convert.Rotation; | |
public class ConvertWordToPdfInJava { | |
public static void main(String[] args) { // Main function to convert Word to PDF in Java | |
// Remove the watermark in output Text document by adding license | |
License lic = new License(); | |
lic.setLicense("GroupDocs.Conversion.lic"); | |
// Load the source Word file for conversion to PDF | |
Converter converter = new Converter("sample.docx"); | |
// Set the convert options for PDF document | |
PdfConvertOptions options = new PdfConvertOptions(); | |
options.setPageNumber(2); | |
options.setPagesCount(1); | |
options.setRotate(Rotation.On180); | |
options.setDpi(300); | |
options.setWidth(1024); | |
options.setHeight(768); | |
// Convert and save the DOCX in PDF format | |
converter.convert("converted.pdf", options); | |
System.out.println("Done"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment