示例#1
0
        public override bool Convert(string sourceFilePath, string targetPdfPath)
        {
            Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
            loadOptions.Encoding = Encoding.Default;
            var doc = new Aspose.Words.Document(sourceFilePath, loadOptions);

            doc.Save(targetPdfPath, Aspose.Words.SaveFormat.Pdf);

            return(File.Exists(targetPdfPath) && new FileInfo(targetPdfPath).Length > 0);
        }
示例#2
0
        public OpResult Preview(string id, string name)
        {
            var obj = AttachRepository.GetQuery(o => o.ItemId == id && o.NewName == name).FirstOrDefault();

            if (obj == null)
            {
                return(OpResult.Fail("ID或参数名不存在!"));
            }
            var fileName = FileHelper.GetUrlRoot + obj.Path.Replace("\\", "/") + obj.NewName;
            var fullName = FileHelper.GetRoot + obj.Path + obj.NewName;

            if (File.Exists(fullName))
            {
                if (obj.ExtName.StartsWith("doc", StringComparison.CurrentCultureIgnoreCase))
                {
                    var destFile = fullName.Substring(0, fullName.LastIndexOf(".") + 1) + "pdf";
                    if (!File.Exists(destFile))
                    {
                        Aspose.Words.Document doc = new Aspose.Words.Document(fullName);
                        doc.Save(destFile, Aspose.Words.SaveFormat.Pdf);
                    }
                }
                else if (obj.ExtName.StartsWith("txt", StringComparison.CurrentCultureIgnoreCase))
                {
                    var destFile = fullName.Substring(0, fullName.LastIndexOf(".") + 1) + "pdf";
                    if (!File.Exists(destFile))
                    {
                        var opt = new Aspose.Words.LoadOptions();
                        opt.LoadFormat = Aspose.Words.LoadFormat.Text;
                        opt.Encoding   = System.Text.Encoding.GetEncoding("gb2312");
                        Aspose.Words.Document doc = new Aspose.Words.Document(fullName, opt);
                        doc.Save(destFile, Aspose.Words.SaveFormat.Pdf);
                    }
                }
                else if (obj.ExtName.StartsWith("xls", StringComparison.CurrentCultureIgnoreCase))
                {
                    var destFile = fullName.Substring(0, fullName.LastIndexOf(".") + 1) + "pdf";
                    if (!File.Exists(destFile))
                    {
                        Aspose.Cells.Workbook doc = new Aspose.Cells.Workbook(fullName);
                        doc.Save(destFile, Aspose.Cells.SaveFormat.Pdf);
                    }
                }
            }
            fileName = fileName.Substring(0, fileName.LastIndexOf(".") + 1) + "pdf";
            return(OpResult.Success(fileName));
        }