The following example shows the most common use case for converting DOCX document to PDF. The source DOCX file is loaded from a current folder. The converted file is saved to the same folder.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Create a converter for the DOCX filevarconverter=newDocxToPdfConverter("business-plan.docx");// Convert DOCX as PDFconverter.Convert("business-plan.pdf");
ImportsSystemImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Create a converter from file path
DimconverterAsNewDocxToPdfConverter("business-plan.docx")' Convert DOCX to PDF
converter.Convert("business-plan.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Create a converter from file path
letconverter=newDocxToPdfConverter("business-plan.docx")// Convert DOCX to PDF
converter.Convert("business-plan.pdf")0
This section covers only the main scenarious you also reffer to the API references for the WordProcessingLoadOptions for a complete list of options that you can specify.
Convert Protected DOCX to PDF
The following example shows how to convert protected DOCX file and save it to unprotected PDF file.
In case you do not specify password for protected document PasswordRequiredException is going to be thrown.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Provide password through load optionsvarconverter=newDocxToPdfConverter("protected.docx",options=>{options.Password="12345";});// Convert DOCX to PDFconverter.Convert("not-protected.pdf");
ImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Provide password through load options
DimconverterAsNewDocxToPdfConverter("protected.docx",Sub(options)options.Password="12345"EndSub)' Convert DOCX to PDF
converter.Convert("not-protected.pdf")EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Provide password through load options
letconverter=newDocxToPdfConverter("protected.docx",funoptions->options.Password<-"12345")// Convert DOCX to PDF
converter.Convert("not-protected.pdf")0
The examples in this section shows how you can adjust the output using PdfConvertOptions.
Convert Specific DOCX Pages to PDF
To convert only a portion of the document instead of all pages. You can specify which pages to include in the output PDF using the Pages property of PdfConvertOptions class.
As an alternative you can use PageNumber to specify the page number to start conversion from and PagesCount to set number of pages to convert starting from PageNumber.
The following example shows how to convert the first three pages of a DOCX file to PDF:
usingSystem;usingSystem.Collections.Generic;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Create the convertervarconverter=newDocxToPdfConverter("business-plan.docx");// Save first three pages to PDFconverter.Convert("pages-1-2-3.pdf",(convertOptions)=>{convertOptions.Pages=newList<int>{1,2,3};});
ImportsSystemImportsSystem.Collections.GenericImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKeyAsString=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKeyAsString=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Create the converter
DimconverterAsNewDocxToPdfConverter("business-plan.docx")' Save first three pages to PDF
converter.Convert("pages-1-2-3.pdf",Sub(convertOptions)convertOptions.Pages=NewList(OfInteger)From{1,2,3}EndSub)EndSubEndModule
openSystemopenSystem.Collections.GenericopenGroupDocs.Conversion.LowCode[<EntryPoint>]letmainargv=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply license
License.Set(publicKey,privateKey)// Create the converter
letconverter=newDocxToPdfConverter("business-plan.docx")// Save first three pages to PDF
converter.Convert("pages-1-2-3.pdf",funconvertOptions->convertOptions.Pages<-List<int>([1;2;3]))0//returnexitcode