Extract and Convert Archive Contents

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Conversion MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-conversion -- dnx GroupDocs.Conversion.Mcp --yes
Folders, licensing and more →

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
    .WithEvents(e => e.OnCompressionCompleted = compressedStream =>
    {
        using (var fileStream = File.Create("converted-documents.zip"))
        {
            compressedStream.CopyTo(fileStream);
        }
    })
    .Load("documents.rar")
    .ConvertTo((SaveContext saveContext) => new MemoryStream())
    .WithOptions(new PdfConvertOptions())
    .Compress(new CompressionConvertOptions
    {
        Format = CompressionFileType.Zip
    })
    .Convert();

// Output: converted-documents.zip containing PDFs

Starting with v26.6, the compressed archive stream is delivered through the ConversionEvents aggregator via the WithEvents(...) entry-stage call. The previous .OnCompressionCompleted(...) chain method placed after .Compress(...) was removed in version 26.9.

With password protection:

FluentConverter
    .WithEvents(e => e.OnCompressionCompleted = compressedStream =>
    {
        using (var fileStream = File.Create("protected-archive.zip"))
        {
            compressedStream.CopyTo(fileStream);
        }
    })
    .Load("sensitive-files.zip")
    .ConvertTo((SaveContext saveContext) => new MemoryStream())
    .WithOptions(new PdfConvertOptions())
    .Compress(new CompressionConvertOptions
    {
        Format = CompressionFileType.Zip,
        Password = "SecurePassword123"
    })
    .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): 7z, AAR (Apple Archive), ALZ, BZ2, CAB, CPIO, GZ, GZIP, ISO, LHA, LZ, LZ4, LZMA, RAR, TAR, UUE, WIM, XAR, XZ, Z, ZIP, ZST

Output (write, Compress): 7z, AAR (Apple Archive), BZ2, CAB, CPIO, GZ, GZIP, ISO, LZ, LZ4, LZMA, TAR, UUE, XAR, XZ, Z, ZIP, ZST (ALZ, LHA, RAR and WIM can be read but not created)

See Also