Skip to content

Commit 6cf3053

Browse files
committed
update articles for work with compression documents
1 parent 544b9e0 commit 6cf3053

2 files changed

Lines changed: 68 additions & 530 deletions

File tree

net/developer-guide/advanced-usage/converting/conversion-options-by-document-family/convert-contents-of-rar-or-zip-document-to-different-formats-and-compress.md

Lines changed: 29 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,32 @@ hideChildren: False
1010
toc: True
1111
---
1212

13-
GroupDocs.Conversion provides flexible options for working with archive files like ZIP, RAR, 7z, and TAR. This guide covers three common workflows for processing archive contents using the FluentConverter API.
13+
GroupDocs.Conversion provides three workflows for processing archive files (ZIP, RAR, 7z, TAR).
1414

15-
## Prerequisites
15+
## Three Archive Workflows
1616

17-
The workflows in this guide require the **FluentConverter API** (introduced in v22.1, reworked in v23.6). All examples use the v24.10+ syntax with `SaveContext`.
18-
19-
## Three Ways to Work with Archives
20-
21-
GroupDocs.Conversion supports three distinct workflows for archive files:
22-
23-
| Workflow | What It Does | When to Use | Result |
24-
|----------|-------------|-------------|--------|
25-
| **[Workflow 1](#workflow-1-extract-and-convert-to-individual-files)** | Extract and convert each file separately | You need individual converted files, not an archive | Separate files (e.g., doc-1.pdf, doc-2.pdf) |
26-
| **[Workflow 2](#workflow-2-repackage-archive-format)** | Change archive format without modifying contents | Change compression format for compatibility or size | New archive format (e.g., ZIP → 7z) |
27-
| **[Workflow 3](#workflow-3-convert-contents-and-re-compress)** | Convert contents AND create new archive | Need converted files packaged in an archive | New archive with converted contents |
17+
| Workflow | What It Does | Result |
18+
|----------|-------------|--------|
19+
| **[Workflow 1](#workflow-1-extract-and-convert-to-individual-files)** | Extract and convert each file separately | Individual converted files |
20+
| **[Workflow 2](#workflow-2-repackage-archive-format)** | Change archive format without modifying contents | New archive format (ZIP → 7z) |
21+
| **[Workflow 3](#workflow-3-convert-contents-and-re-compress)** | Convert contents AND create new archive | New archive with converted contents |
2822

2923
## Workflow 1: Extract and Convert to Individual Files
3024

31-
**Use Case:** You have a ZIP file containing multiple Word documents and need each one as a separate PDF file.
32-
33-
This is the most common workflow. Files are extracted from the archive, converted to your target format, and saved as individual files—no re-compression.
34-
35-
### Example: ZIP with DOCX Files → Separate PDFs
25+
Extract files from an archive and convert each one separately (no re-compression).
3626

3727
```csharp
3828
using GroupDocs.Conversion.Fluent;
3929
using GroupDocs.Conversion.Options.Convert;
30+
using GroupDocs.Conversion.Contracts;
4031
using System.IO;
4132

4233
// ZIP contains: report.docx, summary.docx, analysis.docx
4334
FluentConverter.Load("documents.zip")
4435
.ConvertTo((SaveContext saveContext) =>
4536
{
4637
// Create separate output file for each document
47-
string fileName = $"converted-document-{saveContext.PageNumber}.pdf";
38+
string fileName = $"converted-document-{saveContext.ItemIndex}.pdf";
4839
return File.Create(Path.Combine(@"C:\output", fileName));
4940
})
5041
.WithOptions(new PdfConvertOptions())
@@ -53,25 +44,13 @@ FluentConverter.Load("documents.zip")
5344
// Output: converted-document-1.pdf, converted-document-2.pdf, converted-document-3.pdf
5445
```
5546

56-
### What Happens
57-
58-
1. **Load:** Opens the archive file
59-
2. **ConvertTo:** Defines where each converted file should be saved
60-
3. **WithOptions:** Specifies the target format (PDF in this example)
61-
4. **Convert:** Executes the conversion
62-
63-
Note: There is no `.Compress()` call, so files are saved individually, not re-compressed into an archive.
64-
65-
### Using Original Filenames
66-
67-
You can preserve original filenames from the archive:
47+
**Using original filenames:**
6848

6949
```csharp
7050
FluentConverter.Load("documents.zip")
7151
.ConvertTo((SaveContext saveContext) =>
7252
{
73-
// Use original filename with new extension
74-
string originalName = saveContext.SourceFileName ?? $"document-{saveContext.PageNumber}";
53+
string originalName = saveContext.SourceFileName ?? $"document-{saveContext.ItemIndex}";
7554
string fileName = Path.ChangeExtension(originalName, ".pdf");
7655
return File.Create(Path.Combine(@"C:\output", fileName));
7756
})
@@ -83,15 +62,7 @@ FluentConverter.Load("documents.zip")
8362

8463
## Workflow 2: Repackage Archive Format
8564

86-
**Use Case:** You have a ZIP file but need it as a 7z archive for better compression, without changing the files inside.
87-
88-
This workflow changes the archive format while preserving the original file contents. No document conversion occurs.
89-
90-
GroupDocs.Conversion provides **three methods** to accomplish this. Use whichever fits your needs:
91-
92-
### Method 1: Standard Converter API (Recommended - Simplest!)
93-
94-
The most straightforward approach for basic format conversion:
65+
Change archive format while preserving contents. Use the standard Converter API:
9566

9667
```csharp
9768
using GroupDocs.Conversion;
@@ -110,93 +81,16 @@ using (var converter = new Converter("archive.zip"))
11081
// Output: archive.7z containing the same files as the original ZIP
11182
```
11283

113-
### Method 2: FluentConverter with WithOptions (Clean Alternative)
114-
115-
If you prefer FluentConverter syntax:
116-
117-
```csharp
118-
using GroupDocs.Conversion.Fluent;
119-
using GroupDocs.Conversion.Options.Convert;
120-
using GroupDocs.Conversion.Contracts;
121-
using GroupDocs.Conversion.FileTypes;
122-
using System.IO;
123-
124-
FluentConverter.Load("archive.zip")
125-
.ConvertTo((SaveContext saveContext) => File.Create("archive.7z"))
126-
.WithOptions(new CompressionConvertOptions
127-
{
128-
Format = CompressionFileType.SevenZ
129-
})
130-
.Convert();
131-
132-
// Output: archive.7z containing the same files as the original ZIP
133-
```
134-
135-
### Method 3: FluentConverter with Compress (Advanced Scenarios)
136-
137-
For advanced stream-based workflows:
138-
139-
```csharp
140-
using GroupDocs.Conversion.Fluent;
141-
using GroupDocs.Conversion.Options.Convert;
142-
using GroupDocs.Conversion.Contracts;
143-
using GroupDocs.Conversion.FileTypes;
144-
using System.IO;
145-
146-
FluentConverter.Load("archive.zip")
147-
.ConvertTo((SaveContext saveContext) => new MemoryStream())
148-
.Compress(new CompressionConvertOptions
149-
{
150-
Format = CompressionFileType.SevenZ
151-
})
152-
.OnCompressionCompleted(compressedStream =>
153-
{
154-
using (var fileStream = File.Create("archive.7z"))
155-
{
156-
compressedStream.CopyTo(fileStream);
157-
}
158-
})
159-
.Convert();
160-
161-
// Output: archive.7z containing the same files as the original ZIP
162-
```
163-
164-
**Which method to choose?**
165-
- **Method 1** (Standard API): Simplest, recommended for most users
166-
- **Method 2** (WithOptions): Clean alternative if using FluentConverter
167-
- **Method 3** (Compress): Advanced scenarios with stream handling
168-
169-
See [Convert Archive Formats]({{< ref "conversion/net/developer-guide/advanced-usage/converting/conversion-options-by-document-family/convert-to-compression-with-advanced-options.md" >}}) for detailed comparison and more examples.
170-
171-
### Why Repackage Archives?
172-
173-
- **Better compression:** Convert ZIP to 7z for smaller file sizes
174-
- **Cross-platform compatibility:** Convert proprietary formats to open standards (e.g., RAR to ZIP)
175-
- **Standardization:** Consolidate different archive formats to one standard format
176-
- **Add security:** Repackage with password protection (see [CompressionConvertOptions]({{< ref "conversion/net/developer-guide/advanced-usage/converting/conversion-options-by-document-family/convert-to-compression-with-advanced-options.md" >}}) for details)
177-
178-
### Supported Output Formats
179-
180-
You can repackage archives to these formats:
181-
182-
- **ZIP** - Most widely supported, good compression
183-
- **7z (SevenZ)** - Best compression ratio, open source
184-
- **TAR** - Standard on Unix/Linux systems
185-
- **Others:** TAR.GZ, TAR.BZ2, and more
186-
187-
**Note:** RAR output is not supported due to licensing restrictions. RAR archives can be read as input but not created as output.
84+
For more examples and advanced options, see [Convert Archive Formats]({{< ref "conversion/net/developer-guide/advanced-usage/converting/conversion-options-by-document-family/convert-to-compression-with-advanced-options.md" >}}).
18885

18986
## Workflow 3: Convert Contents and Re-compress
19087

191-
**Use Case:** You have a RAR file containing Word documents and need them converted to PDFs, packaged in a new ZIP archive.
192-
193-
This workflow combines content conversion with re-compression. Files are extracted, converted to a target format, and packaged into a new archive.
194-
195-
### Example: RAR with DOCX → ZIP with PDFs
88+
Extract files, convert them, and package into a new archive:
19689

19790
```csharp
19891
using GroupDocs.Conversion.Fluent;
19992
using GroupDocs.Conversion.Options.Convert;
93+
using GroupDocs.Conversion.Contracts;
20094
using GroupDocs.Conversion.FileTypes;
20195
using System.IO;
20296

@@ -219,9 +113,7 @@ FluentConverter.Load("documents.rar")
219113
// Output: converted-documents.zip containing PDFs
220114
```
221115

222-
### Password Protection Example
223-
224-
Create a password-protected archive:
116+
**With password protection:**
225117

226118
```csharp
227119
FluentConverter.Load("sensitive-files.zip")
@@ -242,69 +134,36 @@ FluentConverter.Load("sensitive-files.zip")
242134
.Convert();
243135
```
244136

245-
For more advanced options including different compression formats, optimization settings, and best practices, see [Convert Archive Formats (ZIP, 7z, TAR, RAR)]({{< ref "conversion/net/developer-guide/advanced-usage/converting/conversion-options-by-document-family/convert-to-compression-with-advanced-options.md" >}}).
246-
247137
## Choosing the Right Workflow
248138

249-
Use this decision guide to select the appropriate workflow:
250-
251-
| Your Goal | Workflow | Recommended Method |
252-
|-----------|----------|-------------------|
253-
| Extract and convert each file separately | **Workflow 1** | FluentConverter: `Load()``ConvertTo()``WithOptions()``Convert()` |
254-
| Change archive format only (no conversion) | **Workflow 2** | Standard API: `new Converter().Convert()` with `CompressionConvertOptions` |
255-
| Convert contents AND create new archive | **Workflow 3** | FluentConverter: `Load()``ConvertTo()``WithOptions()``Compress()``Convert()` |
256-
257-
**Workflow 2 Options (all work):**
258-
- **Method 1:** Standard Converter API - `new Converter().Convert()` (simplest)
259-
- **Method 2:** FluentConverter with `.WithOptions()` - clean alternative
260-
- **Method 3:** FluentConverter with `.Compress()` - advanced scenarios
261-
262-
**Quick Tips:**
263-
264-
- **Workflow 1:** FluentConverter required (multiple output files)
265-
- **Workflow 2:** Standard API recommended (simplest for format change)
266-
- **Workflow 3:** FluentConverter required (content conversion + compression)
139+
| Your Goal | Use |
140+
|-----------|-----|
141+
| Extract and convert each file separately | **Workflow 1** |
142+
| Change archive format only (no conversion) | **Workflow 2** (Standard Converter API) |
143+
| Convert contents AND create new archive | **Workflow 3** |
267144

268145
## Supported Archive Formats
269146

270-
### Input Formats (Read)
271-
272-
GroupDocs.Conversion can read from these archive formats:
273-
274-
- ZIP, RAR, 7z (7-Zip)
275-
- TAR, TAR.GZ, TAR.BZ2, TAR.XZ
276-
- CAB, LZ, CPIO, ISO
277-
- And more
147+
**Input (read):** ZIP, RAR, 7z, TAR, TAR.GZ, TAR.BZ2, TAR.XZ, CAB, LZ, CPIO, ISO
278148

279-
### Output Formats (Write)
280-
281-
You can create these archive formats:
282-
283-
- ZIP (most compatible)
284-
- 7z/SevenZ (best compression)
285-
- TAR and compressed TAR variants
286-
- Other open formats
287-
288-
**Important:** RAR archives can only be read, not created (licensing restrictions).
149+
**Output (write):** ZIP, 7z, TAR, TAR.GZ, TAR.BZ2, TAR.XZ (RAR output not supported due to licensing)
289150

290151
## Version Compatibility
291152

292-
All examples in this guide use **v24.10+ syntax** with `SaveContext`:
153+
All examples use **v24.10+ syntax** with `SaveContext`:
293154

294155
```csharp
295156
.ConvertTo((SaveContext saveContext) => ...)
296157
```
297158

298-
If you're using a version **before v24.10**, use the older syntax without `SaveContext`:
159+
For versions **before v24.10**, use:
299160

300161
```csharp
301162
.ConvertTo(() => ...)
302163
```
303164

304-
The rest of the code remains the same.
305-
306165
## See Also
307166

308-
- [Convert to Compression with advanced options]({{< ref "conversion/net/developer-guide/advanced-usage/converting/conversion-options-by-document-family/convert-to-compression-with-advanced-options.md" >}}) - Complete API reference for CompressionConvertOptions
309-
- [Common Conversion Options]({{< ref "conversion/net/developer-guide/advanced-usage/converting/common-conversion-options/_index.md" >}}) - Watermarks, page selection, and more
310-
- [FluentConverter API Reference](https://reference.groupdocs.com/conversion/net/groupdocs.conversion.fluent/fluentconverter/) - Complete API documentation
167+
- [Convert Archive Formats (ZIP, 7z, TAR, RAR)]({{< ref "conversion/net/developer-guide/advanced-usage/converting/conversion-options-by-document-family/convert-to-compression-with-advanced-options.md" >}})
168+
- [Common Conversion Options]({{< ref "conversion/net/developer-guide/advanced-usage/converting/common-conversion-options/_index.md" >}})
169+
- [FluentConverter API Reference](https://reference.groupdocs.com/conversion/net/groupdocs.conversion.fluent/fluentconverter/)

0 commit comments

Comments
 (0)