Exemple #1
0
        ///<Summary>
        /// ConvertDiagramToSingleImage method to convert diagram file to single image
        ///</Summary>
        public Response ConvertDiagramToSingleImage(string fileName, string folderName, string outputType)
        {
            if (outputType.Equals("tiff") || outputType.Equals("xps") || outputType.Equals("svg"))
            {
                SaveFileFormat format = SaveFileFormat.TIFF;

                if (outputType.Equals("svg"))
                {
                    format = SaveFileFormat.SVG;
                }
                else if (outputType.Equals("xps"))
                {
                    format = SaveFileFormat.XPS;
                }

                return(ProcessTask(fileName, folderName, "." + outputType, false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
                {
                    using (FileStream stream = new FileStream(inFilePath, FileMode.Open))
                    {
                        Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(stream);
                        diagram.Save(outPath, format);

                        stream.Flush();
                        stream.Close();
                    }
                }));
            }

            return(new Response
            {
                FileName = null,
                Status = "Output type not found",
                StatusCode = 500
            });
        }
Exemple #2
0
        ///<Summary>
        /// ConvertDiagramToPdf method to convert diagram file to pdf
        ///</Summary>
        public Response ConvertDiagramToPdf(string fileName, string folderName, string outputType)
        {
            return(ProcessTask(fileName, folderName, ".pdf", false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();

                if (outputType == "pdfa_1b")
                {
                    pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
                }
                else if (outputType == "pdfa_1a")
                {
                    pdfSaveOptions.Compliance = PdfCompliance.PdfA1a;
                }
                else if (outputType == "pdf_15")
                {
                    pdfSaveOptions.Compliance = PdfCompliance.Pdf15;
                }

                using (FileStream stream = new FileStream(inFilePath, FileMode.Open))
                {
                    Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(stream);
                    diagram.Save(outPath, pdfSaveOptions);

                    stream.Flush();
                    stream.Close();
                }
            }));
        }
Exemple #3
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);
        }
Exemple #4
0
        ///<Summary>
        /// ConvertDiagramToSingleImage method to convert diagram file to images
        ///</Summary>
        public Response ConvertDiagramToImages(string fileName, string folderName, string outputType)
        {
            if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png"))
            {
                ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFileFormat.BMP);

                if (outputType.Equals("jpg"))
                {
                    saveOptions = new ImageSaveOptions(SaveFileFormat.JPEG);
                }
                else if (outputType.Equals("png"))
                {
                    saveOptions = new ImageSaveOptions(SaveFileFormat.PNG);
                }

                return(ProcessTask(fileName, folderName, "." + outputType, true, true, delegate(string inFilePath, string outPath, string zipOutFolder)
                {
                    using (FileStream stream = new FileStream(inFilePath, FileMode.Open))
                    {
                        Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(stream);

                        string outfileName = "";

                        if (diagram.Pages.Count > 1)
                        {
                            outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}";
                            for (int i = 0; i < diagram.Pages.Count; i++)
                            {
                                outPath = zipOutFolder + "/" + outfileName;
                                saveOptions.PageIndex = i;

                                diagram.Save(string.Format(outPath, (i + 1) + "." + outputType), saveOptions);
                            }
                        }
                        else
                        {
                            outfileName = Path.GetFileNameWithoutExtension(fileName);
                            outPath = zipOutFolder + "/" + outfileName;
                            saveOptions.PageIndex = 0;

                            diagram.Save(outPath + "." + outputType, saveOptions);
                        }

                        stream.Flush();
                        stream.Close();
                    }
                }));
            }

            return(new Response
            {
                FileName = null,
                Status = "Output type not found",
                StatusCode = 500
            });
        }
Exemple #5
0
        ///<Summary>
        /// ConvertDiagramToHtml method to convert diagram file to html
        ///</Summary>
        public Response ConvertDiagramToHtml(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, ".html", true, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                using (FileStream stream = new FileStream(inFilePath, FileMode.Open))
                {
                    Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(stream);
                    diagram.Save(outPath, SaveFileFormat.HTML);

                    stream.Flush();
                    stream.Close();
                }
            }));
        }
Exemple #6
0
        private static bool SavePdfToStream(string inputFile, MemoryStream fileStream, MemoryStream documentStream, ref bool isLandscape)
        {
            var extension = Path.GetExtension(inputFile);
            if (string.IsNullOrEmpty(extension))
                throw new ArgumentException(inputFile);

            try
            {
                fileStream.Position = 0;
                switch (extension.ToUpperInvariant())
                {
                    case ".DOC":
                    case ".DOCX":
                    case ".RTF":
                    case ".DOT":
                    case ".DOTX":
                        var doc = new Aspose.Words.Document(fileStream);
                        if (doc.PageCount > 0)
                        {
                            var pageInfo = doc.GetPageInfo(0);
                            isLandscape = pageInfo.WidthInPoints > pageInfo.HeightInPoints;
                        }
                        doc.Save(documentStream, Aspose.Words.SaveFormat.Pdf);
                        break;
                    case ".XLS":
                    case ".XLSX":
                        var workbook = new Aspose.Cells.Workbook(fileStream);
                        for (var i = 0; i < workbook.Worksheets.Count; i++)
                        {
                            if (!workbook.Worksheets[i].IsVisible) continue;
                            isLandscape = workbook.Worksheets[i].PageSetup.Orientation == Aspose.Cells.PageOrientationType.Landscape;
                            break;
                        }
                        workbook.Save(documentStream, Aspose.Cells.SaveFormat.Pdf);
                        break;
                    //Microsoft Visio 
                    case ".VSD":
                    case ".VSS":
                    case ".VST":
                    case ".VSX":
                    case ".VTX":
                    case ".VDW":
                    case ".VDX":
                        var vsdDiagram = new Aspose.Diagram.Diagram(fileStream);
                        if (vsdDiagram.Pages.Count > 0)
                            isLandscape = vsdDiagram.Pages[0].PageSheet.PrintProps.PrintPageOrientation.Value == Aspose.Diagram.PrintPageOrientationValue.Landscape;
                        vsdDiagram.Save(documentStream, Aspose.Diagram.SaveFileFormat.PDF);
                        break;
                    //Microsoft Project
                    case ".MPP":
                        var project = new Aspose.Tasks.Project(fileStream);
                        project.Save(documentStream, Aspose.Tasks.Saving.SaveFileFormat.PDF);
                        isLandscape = true;
                        break;
                    //PowerPoint
                    case ".PPT":
                    case ".PPS":
                    case ".POT":
                        using (var pres = new Aspose.Slides.Presentation(fileStream))
                        {
                            isLandscape = pres.SlideSize.Size.Width > pres.SlideSize.Size.Height;
                            pres.Save(documentStream, Aspose.Slides.Export.SaveFormat.Pdf);
                        }
                        break;
                    case ".PPTX":
                    case ".PPSX":
                    case ".POTX":
                        //case ".XPS":
                        using (var presEx = new Aspose.Slides.Presentation(fileStream))
                        {
                            isLandscape = presEx.SlideSize.Orientation == Aspose.Slides.SlideOrienation.Landscape;
                            presEx.Save(documentStream, Aspose.Slides.Export.SaveFormat.Pdf);
                        }
                        break;

                    case ".PDF":
                        {
                            using (var pdf = new Aspose.Pdf.Document(fileStream))
                            {
                                var page = pdf.Pages.OfType<Aspose.Pdf.Page>().FirstOrDefault();
                                if (page != null && page.MediaBox != null)
                                {
                                    isLandscape = page.MediaBox.Width > page.MediaBox.Height;
                                }
                            }

                            fileStream.Seek(0, SeekOrigin.Begin);
                            fileStream.CopyTo(documentStream);
                        }

                        break;
                }
            }
            finally
            {
                fileStream.Close();
            }

            return true;
        }