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

  • 相关阅读:
    IIS主机托管的FSO设置用户权限问题
    关于使用UTF8开发ASP网站
    构建Android开发环境
    iOS如何取得APP的版本信息跟服务器对比进行升级提示?
    经典讲解VB.NET线程方法之访问数据库
    IIS7.0下ASP+Access(MDB)应用环境设置要点
    一文明白数据库事务隔离级别
    EA鼻祖,Zachman,6 行(视点)+ 6 列(W5H)+ 6 条规则
    C语言位运算详解
    关于while 和if
  • 原文地址:https://www.cnblogs.com/wlphp/p/10339193.html
Copyright © 2020-2023  润新知