예제 #1
0
        private static void VisioToImage()
        {
            Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(@"C:\test.vsd");

            Aspose.Diagram.Saving.ImageSaveOptions options = new Aspose.Diagram.Saving.ImageSaveOptions(SaveFileFormat.JPEG);

            diagram.Save(@"C:\VISIO.jpg", options);
        }
예제 #2
0
        private List <string> GetDocumentPages(string file, string folderName, int currentPage)
        {
            List <string> lstOutput   = new List <string>();
            string        outfileName = "page_{0}";
            string        outPath     = Config.Configuration.OutputDirectory + folderName + "/" + outfileName;

            currentPage = currentPage - 1;
            Directory.CreateDirectory(Config.Configuration.OutputDirectory + folderName);
            string imagePath = string.Format(outPath, currentPage) + ".jpeg";

            if (System.IO.File.Exists(imagePath) && currentPage > 0)
            {
                lstOutput.Add(imagePath);
                return(lstOutput);
            }

            int i = currentPage;

            var filename = System.IO.File.Exists(Config.Configuration.WorkingDirectory + folderName + "/" + file)
                                ? Config.Configuration.WorkingDirectory + folderName + "/" + file
                                : Config.Configuration.OutputDirectory + folderName + "/" + file;

            using (FilePathLock.Use(filename))
            {
                try
                {
                    Aspose.Diagram.Live.Demos.UI.Models.License.SetAsposeDiagramLicense();

                    // Load the document from disk.
                    Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(filename);

                    Aspose.Diagram.Saving.ImageSaveOptions options = new Aspose.Diagram.Saving.ImageSaveOptions(SaveFileFormat.JPEG);
                    options.PageCount = 1;

                    // Save each page of the document as image.
                    options.PageIndex = currentPage;
                    diagram.Save(imagePath, options);
                    lstOutput.Add(diagram.Pages.Count.ToString());
                    lstOutput.Add(imagePath);

                    return(lstOutput);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
예제 #3
0
        private static void GenerateDiagramPreview(int previewsFolderId, Stream docStream)
        {
            var document = new Aspose.Diagram.Diagram(docStream);

            if (StartIndex == 0)
            {
                SetPageCount(document.Pages.Count);
            }

            var firstIndex = 0;
            var lastIndex  = 0;

            SetIndexes(StartIndex, document.Pages.Count, out firstIndex, out lastIndex, MaxPreviewCount);

            for (var i = firstIndex; i <= lastIndex; i++)
            {
                //if (!CheckActuality(file))
                //    break;

                try
                {
                    using (var imgStream = new MemoryStream())
                    {
                        var options = new Aspose.Diagram.Saving.ImageSaveOptions(Aspose.Diagram.SaveFileFormat.PNG)
                        {
                            PageIndex  = i,
                            Resolution = 300
                        };

                        document.Save(imgStream, options);
                        if (imgStream.Length == 0)
                        {
                            continue;
                        }

                        SavePreviewAndThumbnail(imgStream, i + 1, previewsFolderId);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ContentId, i + 1, ex: ex, startIndex: StartIndex, version: Version);
                    SaveEmptyPreview(i + 1, previewsFolderId);
                }
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sourcePath"></param>
 /// <param name="targetPath"></param>
 /// <param name="currentPage"></param>
 /// <param name="originalDocumentName"></param>
 /// <returns></returns>
 public int Process(string sourcePath, string targetPath, int currentPage, string originalDocumentName, int qualitySet)
 {
     var qSet = new QualitySet();
     
     var targetFileName = targetPath.PathSplit();
     var targetFileExt = targetFileName[targetFileName.Length - 1].Split('.');
     var diagram = new Diagram(sourcePath);
     var options = new Aspose.Diagram.Saving.ImageSaveOptions(SaveFileFormat.JPEG)
                   {
                       PageIndex = currentPage - 1,
                       Resolution = qSet.Get(qualitySet).Resolution,
                       JpegQuality = qSet.Get(qualitySet).Quality
                   };
     var targetImage = targetPath.Replace("." + targetFileExt[targetFileExt.Length - 1], string.Empty) + currentPage + ConfigurationManager.AppSettings["ImageExtension"];
     diagram.Save(targetImage + "X", options);
     AddHeader(targetImage + "X", diagram.Pages[currentPage - 1].Name);
     return diagram.Pages.Count;
 }