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


    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 来转的话也很快

  • 相关阅读:
    javascript通用循环遍历方法forEach
    伪数组
    引用和基本类型
    谈谈Javascript的this指针
    理解内存分配
    理解undefined和null
    getElementsByClassName实现
    NSubstitute完全手册(十五)自动递归模拟
    NSubstitute完全手册(十七)参数匹配器上的操作
    NSubstitute完全手册(九)检查接收到的调用
  • 原文地址:https://www.cnblogs.com/wlphp/p/10339193.html
Copyright © 2020-2023  润新知