Extract and Convert Archive Contents

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.

Two Content Extraction Workflows

WorkflowWhat It DoesResult
Workflow 1Extract and convert each file separatelyIndividual converted files (e.g., doc-1.pdf, doc-2.pdf)
Workflow 2Convert contents AND create new archiveNew archive with converted contents

Workflow 1: Extract and Convert to Individual Files

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

Workflow 2: Convert Contents and Re-compress

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();

Choosing the Right Workflow

Your GoalUse
Extract and convert each file separatelyWorkflow 1
Convert contents AND create new archiveWorkflow 2
Change archive format only (no conversion)See Convert Archive Formats

Supported 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)

Version Compatibility

All examples use v24.10+ syntax with SaveContext:

.ConvertTo((SaveContext saveContext) => ...)

For versions before v24.10, use:

.ConvertTo(() => ...)

See Also

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.