The following example shows the most common use case for converting XLSX document to PDF. The source XLSX 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 XLSX filevarconverter=newXlsxToPdfConverter("cost-analysis.xlsx");// Convert XLSX to PDFconverter.Convert("cost-analysis.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
DimconverterAsNewXlsxToPdfConverter("cost-analysis.xlsx")' Convert XLSX to PDF
converter.Convert("cost-analysis.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=newXlsxToPdfConverter("cost-analysis.xlsx")// Convert XLSX to PDF
converter.Convert("cost-analysis.pdf")0
This section covers only the main scenarios. You can also refer to the API references for the SpreadsheetLoadOptions for a complete list of options that you can specify.
Convert Protected XLSX to PDF
The following example shows how to convert protected XLSX 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=newXlsxToPdfConverter("protected.xlsx",options=>{options.Password="12345";});// Convert XLSX 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
DimconverterAsNewXlsxToPdfConverter("protected.xlsx",Sub(options)options.Password="12345"EndSub)' Convert XLSX 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=newXlsxToPdfConverter("protected.xlsx",funoptions->options.Password<-"12345")// Convert XLSX to PDF
converter.Convert("not-protected.pdf")0
The following example shows how to convert only specific sheets from an XLSX file to PDF using the SheetIndexes property.
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);// Convert only specific sheets (first and third sheets)varconverter=newXlsxToPdfConverter("invoice-tracker.xlsx",options=>{options.SheetIndexes=newList<int>{0,2};// 0-based indexing});// Convert XLSX to PDFconverter.Convert("specific-sheets.pdf");
ImportsSystemImportsSystem.Collections.GenericImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Convert only specific sheets (first and third sheets)
DimconverterAsNewXlsxToPdfConverter("invoice-tracker.xlsx",Sub(options)options.SheetIndexes=NewList(OfInteger)From{0,2}' 0-based indexing
EndSub)' Convert XLSX to PDF
converter.Convert("specific-sheets.pdf")EndSubEndModule
openSystemopenSystem.Collections.GenericopenGroupDocs.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)// Convert only specific sheets (first and third sheets)
letconverter=newXlsxToPdfConverter("invoice-tracker.xlsx",funoptions->options.SheetIndexes<-List<int>([0;2])// 0-based indexing
)// Convert XLSX to PDF
converter.Convert("specific-sheets.pdf")0
By default hidden sheets are not added to the output PDF.
The following example shows how to include hidden sheets when converting XLSX to PDF using the ShowHiddenSheets property.
usingSystem;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Include hidden sheets in conversionvarconverter=newXlsxToPdfConverter("hidden-worksheets.xlsx",options=>{options.ShowHiddenSheets=true;});// Convert XLSX to PDFconverter.Convert("with-hidden-sheets.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)' Include hidden sheets in conversion
DimconverterAsNewXlsxToPdfConverter("hidden-worksheets.xlsx",Sub(options)options.ShowHiddenSheets=TrueEndSub)' Convert XLSX to PDF
converter.Convert("with-hidden-sheets.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)// Include hidden sheets in conversion
letconverter=newXlsxToPdfConverter("hidden-worksheets.xlsx",funoptions->options.ShowHiddenSheets<-true)// Convert XLSX to PDF
converter.Convert("with-hidden-sheets.pdf")0
The examples in this section shows how you can adjust the output using PdfConvertOptions.
Convert XLSX to PDF with Specific PDF Format
You can specify the PDF format for the output file using the PdfFormat property in PdfOptions class. This allows you to create PDF files that conform to specific standards like PDF/A for archiving or PDF/X for print production.
The following example shows how to convert an XLSX file to PDF/A-1b format, which is commonly used for long-term archiving:
usingSystem;usingGroupDocs.Conversion.LowCode;usingGroupDocs.Conversion.Options.Convert;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Create the convertervarconverter=newXlsxToPdfConverter("cost-analysis.xlsx");// Convert to PDF/A-1b format for archivingconverter.Convert("archived-cost-analysis.pdf",convertOptions=>{convertOptions.PdfOptions.PdfFormat=PdfFormats.PdfA_1B;});
ImportsGroupDocs.Conversion.LowCodeImportsGroupDocs.Conversion.Options.ConvertModuleProgramSubMain()' Load license keys
DimpublicKeyAsString=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKeyAsString=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Create the converter
DimconverterAsNewXlsxToPdfConverter("cost-analysis.xlsx")' Convert to PDF/A-1b format for archiving
converter.Convert("archived-cost-analysis.pdf",Sub(convertOptions)convertOptions.PdfOptions.PdfFormat=PdfFormats.PdfA_1BEndSub)EndSubEndModule
openSystemopenGroupDocs.Conversion.LowCodeopenGroupDocs.Conversion.Options.Convert[<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=newXlsxToPdfConverter("cost-analysis.xlsx")// Convert to PDF/A-1b format for archiving
converter.Convert("archived-cost-analysis.pdf",funconvertOptions->convertOptions.PdfOptions.PdfFormat<-PdfFormats.PdfA_1B)0//returnexitcode