filePath – The path where the output file will be saved. It can be an absolute path (e.g., C:\files\converted.pdf) or a relative path (e.g., converted.pdf).
convertOptions – Options specifying the conversion settings, such as the output format or specific configurations related to the conversion process.
Note
If the specified output file does not exist, it will be automatically created.
If the file already exists, it may be overwritten unless specified otherwise in the options.
The following code snippet demonstrates how to convert a Word document (.docx) to a PDF file and save it to a specified directory on your local disk:
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.options.convert.PdfConvertOptions;publicclassConvertDocxToPdf{publicstaticvoidconvert(){// Specify the source file location
Converterconverter=newConverter("c:\\files\\business-plan.docx");// Define conversion options (in this case, converting to PDF)
PdfConvertOptionsoptions=newPdfConvertOptions();// Specify the output file location and perform the conversion
converter.convert("c:\\files\\business-plan.pdf",options);}publicstaticvoidmain(String[]args){convert();}}
business-plan.docx is sample file used in this example. Click here to download it.
business-plan.pdf is converted PDF document. Click here to download it.
Explanation:
Source File Specification:
The Converter object is initialized with the path to the source document (business-plan.docx).
Conversion Options:
The PdfConvertOptions object is created to configure settings specific to PDF conversion. Depending on the library you are using, you may have options to customize aspects such as page size, orientation, or compression.
Saving the Converted File:
The convert() method is called with the desired output file path (c:\\files\\business-plan.pdf) and the conversion options (options). The file will be saved in the specified directory.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.