Extract and Convert Archive Contents
Leave feedback
On this page
GroupDocs.Conversion can extract files from archives (ZIP, RAR, 7z, TAR) and convert each file to a different format. This guide covers two workflows for processing archive contents.
To convert archive formats (ZIP to 7z, etc.) without extracting contents, see Convert Archive Formats.
| Workflow | What It Does | Result |
|---|---|---|
| Workflow 1 | Extract and convert each file separately | Individual converted files (e.g., doc-1.pdf, doc-2.pdf) |
| Workflow 2 | Convert contents AND create new archive | New archive with converted contents |
Extract files from an archive and convert each one separately (no re-compression).
using GroupDocs.Conversion.Fluent;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Contracts;
using System.IO;
// ZIP contains: report.docx, summary.docx, analysis.docx
FluentConverter.Load("documents.zip")
.ConvertTo((SaveContext saveContext) =>
{
// Create separate output file for each document
string fileName = $"converted-document-{saveContext.ItemIndex}.pdf";
return File.Create(Path.Combine(@"C:\output", fileName));
})
.WithOptions(new PdfConvertOptions())
.Convert();
// Output: converted-document-1.pdf, converted-document-2.pdf, converted-document-3.pdf
Using original filenames:
FluentConverter.Load("documents.zip")
.ConvertTo((SaveContext saveContext) =>
{
string originalName = saveContext.SourceFileName ?? $"document-{saveContext.ItemIndex}";
string fileName = Path.ChangeExtension(originalName, ".pdf");
return File.Create(Path.Combine(@"C:\output", fileName));
})
.WithOptions(new PdfConvertOptions())
.Convert();
// Output: report.pdf, summary.pdf, analysis.pdf
Extract files, convert them, and package into a new archive:
using GroupDocs.Conversion.Fluent;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.Contracts;
using GroupDocs.Conversion.FileTypes;
using System.IO;
FluentConverter.Load("documents.rar")
.ConvertTo((SaveContext saveContext) => new MemoryStream())
.WithOptions(new PdfConvertOptions())
.Compress(new CompressionConvertOptions
{
Format = CompressionFileType.Zip
})
.OnCompressionCompleted(compressedStream =>
{
using (var fileStream = File.Create("converted-documents.zip"))
{
compressedStream.CopyTo(fileStream);
}
})
.Convert();
// Output: converted-documents.zip containing PDFs
With password protection:
FluentConverter.Load("sensitive-files.zip")
.ConvertTo((SaveContext saveContext) => new MemoryStream())
.WithOptions(new PdfConvertOptions())
.Compress(new CompressionConvertOptions
{
Format = CompressionFileType.Zip,
Password = "SecurePassword123"
})
.OnCompressionCompleted(compressedStream =>
{
using (var fileStream = File.Create("protected-archive.zip"))
{
compressedStream.CopyTo(fileStream);
}
})
.Convert();
| Your Goal | Use |
|---|---|
| Extract and convert each file separately | Workflow 1 |
| Convert contents AND create new archive | Workflow 2 |
| Change archive format only (no conversion) | See Convert Archive Formats |
Input (read): ZIP, RAR, 7z, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, CAB, LZ, CPIO, ISO
Output (write): ZIP, 7z, TAR, TAR.GZ, TAR.BZ2, TAR.XZ (RAR output not supported due to licensing)
All examples use v24.10+ syntax with SaveContext:
.ConvertTo((SaveContext saveContext) => ...)
For versions before v24.10, use:
.ConvertTo(() => ...)
- Convert Archive Formats (ZIP, 7z, TAR, RAR) - Change archive format without extracting contents
- Common Conversion Options
- FluentConverter API Reference
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.