简体   繁体   English

如何在C#中使用sevenzipsharper压缩PDF文件?

[英]How to compress PDF file using sevenzipsharper in c#?

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. 但是我想压缩成一个PDF文件。 How can I compress into a single PDF file? 如何压缩成单个PDF文件?

Use the SevenZipCompressor.CompressFiles method instead of SevenZipCompressor.CompressDirectory . 使用SevenZipCompressor.CompressFiles方法而不是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(); SevenZipCompressor tmp =新的SevenZipCompressor(); tmp.CompressStream(File.OpenRead(sourceFile), File.Create(destinationFile)); 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. 在CodeProject上有一个示例,该示例使用SDK为7z创建C#接口。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM