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?
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.