Convert contents of RAR or ZIP to different formats and compress

GroupDocs.Conversion provides a flexible API to control the conversion of archives that contain other documents.

The following code snippet shows how to convert each constituent file of a RAR archive into a PDF format and then compress them to a single ZIP archive:

var converter = new Converter();

converter.Load("sample.rar")
    .ConvertTo(p => new MemoryStream()).WithOptions(new PdfConvertOptions())
    .Compress(new CompressionConvertOptions { Format = CompressionFileType.Zip }).OnCompressionCompleted(
        compressedStream =>
        {
            using (var fs = new FileStream("converted.zip", FileMode.Create))
            {
                compressedStream.CopyTo(fs);
            }
        })
    .Convert();

The following code snippet shows how to convert each constituent file of a ZIP archive to a PDF format and then compress them as password-protected ZIP archive:

var converter = new Converter();

converter.Load("sample.zip")
    .ConvertTo(p => new MemoryStream()).WithOptions(new PdfConvertOptions())
    .Compress(new CompressionConvertOptions 
    { 
        Format = CompressionFileType.Zip,
        Password = "123"
    }).OnCompressionCompleted(
        compressedStream =>
        {
            using (var fs = new FileStream("converted.zip", FileMode.Create))
            {
                compressedStream.CopyTo(fs);
            }
        })
    .Convert();