csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer相关的知识,希望对你有一定的参考价值。

using GroupDocs.Viewer.Converter.Options;
using GroupDocs.Viewer.Domain;
using GroupDocs.Viewer.Domain.Containers;
using GroupDocs.Viewer.Domain.Image;
using GroupDocs.Viewer.Handler;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Viewer_Modren_UI.Helpers;

namespace Viewer_Modren_UI.Controllers
{
    [RoutePrefix("attachment/image")]
    public class AttachmentImageController : Controller
    {
        [Route("")]
        public ActionResult Get(int? width, int? height, string file,string attachment, int page, string watermarkText, int? watermarkColor, WatermarkPosition? watermarkPosition, int? watermarkWidth, byte watermarkOpacity)
        {
            ViewerImageHandler handler = Utils.CreateViewerImageHandler();
            ImageOptions o = new ImageOptions();
            List<int> pageNumberstoRender = new List<int>();
            pageNumberstoRender.Add(page);
            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber = page;
            o.CountPagesToRender = 1;
            if (watermarkText != "")
                o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            if (width.HasValue)
            {
                o.Width = Convert.ToInt32(width);
            }
            if (height.HasValue)
            {
                o.Height = Convert.ToInt32(height);
            }
            Stream stream = null;
            DocumentInfoContainer info = handler.GetDocumentInfo(file);

            // Iterate over the attachments collection
            foreach (AttachmentBase attachmentBase in info.Attachments.Where(x=>x.Name == attachment))
            {
                List<PageImage> pages = handler.GetPages(attachmentBase,o);
                foreach (PageImage attachmentPage in pages.Where(x=>x.PageNumber == page)) { stream = attachmentPage.Stream; };

            }
            return new FileStreamResult(stream, "image/png");
        }
    }
}

以上是关于csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer的主要内容,如果未能解决你的问题,请参考以下文章

csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer

csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer

csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer

csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer

csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer

csharp 适用于.NET MVC Modern UI的GroupDocs.Viewer