How to compress PDF file using sevenzipsharper in c#?

876 Views Asked by At

I can compress a directory using the following code:

string dll = @"D:\7z.dll";
string source = @"D:\sample";
string output = @"D:\My7zipped.7z";
SevenZipBase.SetLibraryPath(dll);
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
compressor.CompressionMethod = CompressionMethod.Lzma2;
compressor.CompressionLevel = CompressionLevel.Normal;
compressor.CompressDirectory(source, output);

But i want to compress into a single PDF file. How can I compress into a single PDF file?

2

There are 2 best solutions below

2
nvoigt On

Use the SevenZipCompressor.CompressFiles method instead of SevenZipCompressor.CompressDirectory.

Please try to find out the basics (like this) yourself. You are supposed to do some work on your own before asking here.

0
lordkain On

SevenZipCompressor tmp = new SevenZipCompressor(); tmp.CompressStream(File.OpenRead(sourceFile), File.Create(destinationFile));

There is an example on CodeProject of someone creating a C# interface for 7z using the SDK.

http://www.codeproject.com/Articles/27148/C-NET-Interface-for-7-Zip-Archive-DLLs