File compression is the process of reducing the size of one or more files. It shrinks big files into much smaller ones by removing unneeded data. The compressed file archive makes it easier to send and back up large files or groups of files. Moreover, such files make downloading faster and easier, besides, they allow more data to be stored on removable media. There are various compression formats. Below, we are going to describe how to convert the most popular compression file formats using GroupDocs.Conversion.
With GroupDocs.Conversion you can easily extract content from your archives. For example, a code snippet of extraction from a ZIP archive will look like this:
// Load the source ZIP fileusing(Converterconverter=newConverter("sample.zip")){converter.Convert(()=>newMemoryStream(),(StreamconvertedStream,stringsourceFileName)=>{// store extracted contentstringfileName=Path.Combine(outputFolder,sourceFileName);Directory.CreateDirectory(Path.GetDirectoryName(fileName)!);using(varfs=newFileStream(fileName,FileMode.Create)){convertedStream.CopyTo(fs);}},(_,_)=>null);}
Put it simply - you just load a ZIP file into the Converter class, provide null convert options and a handler in which to store the result and GroupDocs.Conversion does all the rest.
Note
Refer to the API reference for more conversion options and customizations.
Extract and convert from a RAR
You also can convert the archive content during extraction to a desired format. Extraction and conversion to PDF format are also quite simple and natural.
The following code snippet shows how to convert the content of a RAR archive to PDF in C# using GroupDocs.Conversion.
// Load the source RAR fileusing(Converterconverter=newConverter("sample.rar")){// Set the convert option for PDF format. This will convert each file in the archive to PDFPdfConvertOptionsoptions=newPdfConvertOptions();inti=0;// Extract and convert to PDFconverter.Convert(()=>newFileStream(Path.Combine(outputFolder,$"converted-{++i}.pdf"),FileMode.Create),options);}
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.