GroupDocs.Conversion.LowCode provides two ways to save converted documents: to a file or a stream. This allows you to use any output storage location.
In this topic, we use the DocxToPdfConverter class as an example. The same approach applies to other converter classes.
Convert Methods
Each converter class provides two Convert methods inherited from the base Converter class:
public void Convert(string filePath, Action<TConvertOptions> convertOptionsAction = null)
public void Convert(Stream targetStream, Action<TConvertOptions> convertOptionsAction = null)
The first method saves the converted file to a specified file path, and the second one saves it to a provided writable stream. Both methods accept an optional second parameter that enables you to configure the convert options.
Example 1: Save to File Path
The following example shows how to save a converted PDF file to the business-plan.pdf file by specifying the relative file path. The file is going to be saved in the current directory.
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 example demonstrates how to save the converted file to a Stream.
usingSystem;usingSystem.IO;usingGroupDocs.Conversion.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply licenseLicense.Set(publicKey,privateKey);// Load DOCX file as streamusingvarstream=File.OpenRead("business-plan.docx");// Create a converter from streamvarconverter=newDocxToPdfConverter(stream);// Instantiate output file streamusingvarconvertedFile=File.Create("business-plan.pdf");// Convert DOCX to PDFconverter.Convert(convertedFile);
ImportsSystemImportsSystem.IOImportsGroupDocs.Conversion.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKeyAsString=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKeyAsString=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply license
License.Set(publicKey,privateKey)' Load DOCX file as stream
UsinginputStreamAsFileStream=File.OpenRead("business-plan.docx"),outputStreamAsFileStream=File.Create("business-plan.pdf")' Create a converter from stream
DimconverterAsNewDocxToPdfConverter(inputStream)' Convert DOCX to PDF
converter.Convert(outputStream)EndUsingEndSubEndModule
openSystemopenSystem.IOopenGroupDocs.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)// Use 'use' bindings for automatic disposal
useinputStream=File.OpenRead("business-plan.docx")useoutputStream=File.Create("business-plan.pdf")// Create a converter from stream
letconverter=newDocxToPdfConverter(inputStream)// Convert DOCX to PDF
converter.Convert(outputStream)0//returnexitcode
You can use optional convert options to adjust the output according to your requirements. Each converter has its own corresponding convert options.
The following code example shows how to set convert options to convert first three DOCX doucument pages to PDF file.
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);// Provide password through load optionsvarconverter=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)' Provide password through load options
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