隐藏

C# 将Word,Execl,PPT,Project, 文件转成PDF, 不依赖Office!!

发布:2020/1/15 10:20:23作者:管理员 来源:本站 浏览次数:1036

git 地址

https://gitee.com/bandung/Execl_WordTOPDF.git 

包括了各种破解的dll

Word转PDF

挨个引用

Word转PDF

复制代码
    public void WordToPDF(String from,String to)
        { try {
                Document doc = new Document(from); //保存为PDF文件,此处的SaveFormat支持很多种格式,如图片,epub,rtf 等等 //权限这块的设置成不可复制 PdfSaveOptions saveOptions = new PdfSaveOptions(); // Create encryption details and set owner password. PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128); // Start by disallowing all permissions. encryptionDetails.Permissions = PdfPermissions.DisallowAll; // Extend permissions to allow editing or modifying annotations. encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
                saveOptions.EncryptionDetails = encryptionDetails; // Render the document to PDF format with the specified permissions.  doc.Save(to , saveOptions); //doc.Save(to, SaveFormat.Pdf); Console.WriteLine("成功!");
            } catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("强行报错!");
            }
         
        }
复制代码

Execl转 PDF

复制代码
 public void ExeclToPDF(String from, String to)
        { try {

                Aspose.Cells.Workbook xls = new Aspose.Cells.Workbook(from);
                Aspose.Cells.PdfSaveOptions xlsSaveOption = new Aspose.Cells.PdfSaveOptions();
                xlsSaveOption.SecurityOptions = new Aspose.Cells.Rendering.PdfSecurity.PdfSecurityOptions(); #region pdf 加密 //Set the user password //PDF加密功能 //xlsSaveOption.SecurityOptions.UserPassword = "pdfKey"; //Set the owner password //xlsSaveOption.SecurityOptions.OwnerPassword = "sxbztxmgzxt"; #endregion //Disable extracting content permission xlsSaveOption.SecurityOptions.ExtractContentPermission = false; //Disable print permission xlsSaveOption.SecurityOptions.PrintPermission = false;
                xlsSaveOption.AllColumnsInOnePagePerSheet = true; //权限这块的设置成不可复制 PdfSaveOptions saveOptions = new PdfSaveOptions(); // Create encryption details and set owner password. PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128); // Start by disallowing all permissions. encryptionDetails.Permissions = PdfPermissions.DisallowAll; // Extend permissions to allow editing or modifying annotations. encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
                saveOptions.EncryptionDetails = encryptionDetails; // Render the document to PDF format with the specified permissions. //doc.Save(to, saveOptions);  xls.Save(to, xlsSaveOption);

                Console.WriteLine("转换成功!");
            } catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("强行报错!");
            }

        }
复制代码

PPT转PDF

 

复制代码
public void pptToPdf(string from, string to)
        {
            Presentation ppt = new Presentation(from);
            ppt.Save(to, Aspose.Slides.Export.SaveFormat.Pdf);
            Console.WriteLine("成功!");
        }
复制代码

Project 文件转PDF

复制代码
   public void project()
        { var project = new Aspose.Tasks.Project("1.mpp"); // save in different formats project.Save("file\\output.pdf", Aspose.Tasks.Saving.SaveFileFormat.PDF);
            project.Save("file\\output.html", Aspose.Tasks.Saving.SaveFileFormat.HTML);
            project.Save("file\\output.xml", Aspose.Tasks.Saving.SaveFileFormat.XML);
            project.Save("file\\output.png", Aspose.Tasks.Saving.SaveFileFormat.PNG);

            Console.WriteLine("成功!");

        }
复制代码

把文件压缩成压缩包

using (var archive = new Archive())
            {
               archive.CreateEntry("1.pptx", @"1.pptx");
               archive.Save(@"result.zip");
            }

 

 如果想在其他语言调用使用Thrift吧,其实java 来转的话也很快