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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用Apache POI和Apache Parquet库来将Java中的Excel文件转换为Parquet文件。首先,您需要使用POI库读取Excel文件中的数据,然后将其转换为Parquet格式并写入Parquet文件。您可以使用ParquetWriter类来写入Parquet文件。以下是一个示例代码片段: ``` // 导入所需的库 import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.parquet.hadoop.ParquetWriter; import org.apache.parquet.hadoop.metadata.CompressionCodecName; import org.apache.parquet.schema.MessageType; import org.apache.parquet.schema.MessageTypeParser; import org.apache.parquet.schema.Types; // 读取Excel文件 Workbook workbook = new XSSFWorkbook(new FileInputStream("input.xlsx")); Sheet sheet = workbook.getSheetAt(); // 定义Parquet文件的模式 MessageType schema = MessageTypeParser.parseMessageType("message ExcelData {\n" + " required binary column1;\n" + " required binary column2;\n" + "}"); // 创建Parquet文件的写入器 ParquetWriter<GenericRecord> writer = AvroParquetWriter.<GenericRecord>builder(new Path("output.parquet")) .withSchema(schema) .withCompressionCodec(CompressionCodecName.SNAPPY) .withDataModel(GenericData.get()) .build(); // 将Excel数据转换为Parquet格式并写入Parquet文件 for (Row row : sheet) { GenericRecord record = new GenericData.Record(schema); record.put("column1", row.getCell().getStringCellValue()); record.put("column2", row.getCell(1).getStringCellValue()); writer.write(record); } // 关闭写入器 writer.close(); ``` 请注意,您需要将上述代码中的输入和输出文件路径替换为您自己的路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值