Aspose.Slides将ppt/pptx转成pdf

用Aspose.Slides将ppt/pptx转成pdf
/// <summary>
        /// ppt转pdf
        /// </summary>
        /// <param name="path">文件地址</param>
        /// <param name="newFilePath">转换后的文件地址</param>
        /// <returns></returns>
        public static void PptToPdf(string path, string newFilePath)
        {
            var dir = newFilePath.Substring(0, newFilePath.LastIndexOf("/") + 1);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            Crack();//生成之前先调用破解方法,去掉水印。
            Aspose.Slides.Presentation ppt = new Aspose.Slides.Presentation(path);
            ppt.Save(newFilePath, Aspose.Slides.Export.SaveFormat.Pdf);
        }
        
        //去掉水印
        public static void Crack()//使用前调用一次即可
        {
            try
            {
                ////调用Crack方法实现软破解
                //HOTPathchAsposeSlides解密
                string[] stModule = new string[8]
                {
                    "u0003u2003u2009u2004",
                    "u0005u2003u2009u2004",
                    "u000Fu2003u2001u2003",
                    "u0003u2000",
                    "u000F",
                    "u0002u2000",
                    "u0003",
                    "u0002"
                };
                Assembly assembly = Assembly.GetAssembly(typeof(License));
                Type typeLic = null, typeIsTrial = null, typeHelper = null;
                foreach (Type type in assembly.GetTypes())
                {
                    if ((typeLic == null) && (type.Name == stModule[0]))
                    {
                        typeLic = type;
                    }
                    else if ((typeIsTrial == null) && (type.Name == stModule[1]))
                    {
                        typeIsTrial = type;
                    }
                    else if ((typeHelper == null) && (type.Name == stModule[2]))
                    {
                        typeHelper = type;
                    }
                }
                if (typeLic == null || typeIsTrial == null || typeHelper == null)
                {
                    throw new Exception();
                }
                object lic = Activator.CreateInstance(typeLic);
                int findCount = 0;
                foreach (FieldInfo field in typeLic.GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
                {
                    if (field.FieldType == typeLic && field.Name == stModule[3])
                    {
                        field.SetValue(null, lic);
                        ++findCount;
                    }
                    else if (field.FieldType == typeof(DateTime) && field.Name == stModule[4])
                    {
                        field.SetValue(lic, DateTime.MaxValue);
                        ++findCount;
                    }
                    else if (field.FieldType == typeIsTrial && field.Name == stModule[5])
                    {
                        field.SetValue(lic, 1);
                        ++findCount;
                    }

                }
                foreach (FieldInfo field in typeHelper.GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
                {
                    if (field.FieldType == typeof(bool) && field.Name == stModule[6])
                    {
                        field.SetValue(null, false);
                        ++findCount;
                    }
                    if (field.FieldType == typeof(int) && field.Name == stModule[7])
                    {
                        field.SetValue(null, 128);
                        ++findCount;
                    }
                }
                if (findCount < 5)
                {
                    throw new NotSupportedException("无效的版本");
                }
            }
            catch (Exception e)
            {
                
            }
        }

原文地址:https://www.cnblogs.com/jiangqw/p/12123956.html