The following example shows the most common use case for converting DOC document to PDF. The source DOC 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 DOC filevarconverter=newDocToPdfConverter("business-plan.doc");// Convert DOC 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
DimconverterAsNewDocToPdfConverter("business-plan.doc")' Convert DOC 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=newDocToPdfConverter("business-plan.doc")// Convert DOC to PDF
converter.Convert("business-plan.pdf")0
This section covers only the main scenarios. You also refer to the API references for the WordProcessingLoadOptions for a complete list of options that you can specify.
Convert Protected DOC to PDF
The following example shows how to convert protected DOC 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=newDocToPdfConverter("protected.doc",options=>{options.Password="12345";});// Convert DOC 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
DimconverterAsNewDocToPdfConverter("protected.doc",Sub(options)options.Password="12345"EndSub)' Convert DOC 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 license
License.Set(publicKey,privateKey)// Provide password through load options
letconverter=newDocToPdfConverter("protected.doc",funoptions->options.Password<-"12345")// Convert DOC to PDF
converter.Convert("not-protected.pdf")0
The examples in this section shows how you can adjust the output using PdfConvertOptions.
Convert Specific DOC 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 DOC 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=newDocToPdfConverter("business-plan.doc");// 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
DimconverterAsNewDocToPdfConverter("business-plan.doc")' 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=newDocToPdfConverter("business-plan.doc")// Save first three pages to PDF
converter.Convert("pages-1-2-3.pdf",funconvertOptions->convertOptions.Pages<-List<int>([1;2;3]))0//returnexitcode