Пример #1
0
        public HttpResponseMessage Get(string file)
        {
            ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler();

            Stream pdf = null;

            try
            {
                pdf = handler.GetPdfFile(file).Stream;
            }
            catch (Exception x)
            {
                throw x;
            }
            using (var ms = new MemoryStream())
            {
                pdf.CopyTo(ms);
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(ms.ToArray())
                };
                result.Content.Headers.ContentDisposition =
                    new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                {
                    FileName = Path.GetFileNameWithoutExtension(file) + ".pdf"
                };
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/pdf");

                return(result);
            }
        }
        /// <summary>
        /// Add Watermark to Html page representation
        /// </summary>
        public static void Add_Watermark_For_Html()
        {
            Console.WriteLine("***** {0} *****", "Add Watermark to Html page representation");

            /* ********************* SAMPLE ********************* */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "word.doc";

            HtmlOptions options = new HtmlOptions();

            // Set watermark properties
            Watermark watermark = new Watermark("This is watermark text");
            watermark.Color = System.Drawing.Color.Blue;
            watermark.Position = WatermarkPosition.Diagonal;
            watermark.Width = 100;

            options.Watermark = watermark;

            // Get document pages html representation with watermark
            List<PageHtml> pages = htmlHandler.GetPages(guid, options);
        }
        /// <summary>
        /// Render a document in html representation whom located at web/remote location.
        /// </summary>
        /// <param name="DocumentURL">URL of the document</param>
        /// <param name="DocumentPassword">Password Parameter is optional</param>
        public static void RenderDocumentAsHtml(Uri DocumentURL, String DocumentPassword = null)
        {
            //ExStart:RenderRemoteDocAsHtml
            //Get Configurations
            ViewerConfig config = Utilities.GetConfigurations();

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);

            //Instantiate the HtmlOptions object
            HtmlOptions options = new HtmlOptions();

            if (!String.IsNullOrEmpty(DocumentPassword))
            {
                options.Password = DocumentPassword;
            }

            //Get document pages in html form
            List <PageHtml> pages = htmlHandler.GetPages(DocumentURL, options);

            foreach (PageHtml page in pages)
            {
                //Save each page at disk
                Utilities.SaveAsHtml(page.PageNumber + "_" + Path.GetFileName(DocumentURL.LocalPath), page.HtmlContent);
            }
            //ExEnd:RenderRemoteDocAsHtml
        }
Пример #4
0
        public static HttpResponseMessage GetPageHtml(string file, int page)
        {
            ViewerHtmlHandler handler             = Utils.CreateViewerHtmlHandler();
            List <int>        pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o = new HtmlOptions();

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            o.HtmlResourcePrefix  = (String.Format(
                                         "/page/resource?file=%s&page=%d&resource=",
                                         file,
                                         page
                                         ));

            List <PageHtml> list = Utils.LoadPageHtmlList(handler, file, o);

            string fullHtml = "";

            foreach (PageHtml pageHtml in list.Where(x => x.PageNumber == page))
            {
                fullHtml = pageHtml.HtmlContent;
            }
            ;
            var response = new HttpResponseMessage();

            response.Content = new StringContent(fullHtml);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            return(response);
        }
        /// <summary>
        /// Get Document Information
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("***** {0} *****", "Get Document Information");

            /* ********************* SAMPLE ********************* */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);

            string documentName = "word.doc";
            // Get document information
            DocumentInfoOptions options = new DocumentInfoOptions(documentName);
            DocumentInfoContainer documentInfo = htmlHandler.GetDocumentInfo(options);

            Console.WriteLine("DateCreated: {0}", documentInfo.DateCreated);
            Console.WriteLine("DocumentType: {0}", documentInfo.DocumentType);
            Console.WriteLine("Extension: {0}", documentInfo.Extension);
            Console.WriteLine("FileType: {0}", documentInfo.FileType);
            Console.WriteLine("Guid: {0}", documentInfo.Guid);
            Console.WriteLine("LastModificationDate: {0}", documentInfo.LastModificationDate);
            Console.WriteLine("Name: {0}", documentInfo.Name);
            Console.WriteLine("PageCount: {0}", documentInfo.Pages.Count);
            Console.WriteLine("Size: {0}", documentInfo.Size);

            foreach (PageData pageData in documentInfo.Pages)
            {
                Console.WriteLine("Page number: {0}", pageData.Number);
                Console.WriteLine("Page name: {0}", pageData.Name);
            }
        }
        public ActionResult Get(string file, int page, string watermarkText, int?watermarkColor, WatermarkPosition?watermarkPosition, int?watermarkWidth, byte watermarkOpacity)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler();

            List <int> pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions options = new HtmlOptions();

            options.PageNumbersToRender = pageNumberstoRender;
            options.PageNumber          = page;
            options.CountPagesToRender  = 1;
            options.HtmlResourcePrefix  = "/page/resource?file=" + file + "&page=" + page + "&resource=";
            if (watermarkText != "")
            {
                options.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }

            List <PageHtml> list     = Utils.LoadPageHtmlList(handler, file, options);
            string          fullHtml = "";

            foreach (PageHtml pageHtml in list.Where(x => x.PageNumber == page))
            {
                fullHtml = pageHtml.HtmlContent;
            }
            ;
            return(Content(fullHtml));
        }
        /// <summary>
        /// How to use custom input data handler
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("***** {0} *****", "How to use custom input data handler");

            /* ********************* SAMPLE ********************* */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // File guid
            string guid = @"word.doc";

            // Use custom IInputDataHandler implementation
            IInputDataHandler inputDataHandler = new FtpInputDataHandler();

            // Get file HTML representation
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config, inputDataHandler);

            List<PageHtml> pages = htmlHandler.GetPages(guid);

            Console.WriteLine("Pages count: {0}", pages.Count);

            // Get list of entities for ftp root folder
            FileTreeOptions options = new FileTreeOptions(@"ftp://localhost");
            FileTreeContainer container = htmlHandler.LoadFileTree(options);
        }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var file = GetValueFromQueryString("file");
            ViewerHtmlHandler handler  = Utils.CreateViewerHtmlHandler();
            Stream            original = null;

            try
            {
                original = handler.GetFile(file).Stream;
            }
            catch (Exception x)
            {
                throw x;
            }

            using (var ms = new MemoryStream())
            {
                original.CopyTo(ms);
                ms.WriteTo(HttpContext.Current.Response.OutputStream);
                Response.AddHeader("content-disposition", "attachment; filename=" + file);
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.End();
            }
        }
Пример #9
0
        public ActionResult Get(string file, int page)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler();

            List <int> pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o = new HtmlOptions();

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            o.HtmlResourcePrefix  = (String.Format(
                                         "/page/resource?file=%s&page=%d&resource=",
                                         file,
                                         page
                                         ));

            List <PageHtml> list     = Utils.LoadPageHtmlList(handler, file, o);
            string          fullHtml = "";

            foreach (PageHtml pageHtml in list.Where(x => x.PageNumber == page))
            {
                fullHtml = pageHtml.HtmlContent;
            }
            ;
            return(Content(fullHtml));
        }
        /// <summary>
        /// Get document html representation with embedded resources
        /// </summary>
        public static void Get_Html_EmbeddedResources()
        {
            Console.WriteLine("***** {0} *****", "Get document html representation with embedded resources");

            /* ********************* SAMPLE ********************* */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "word.doc";

            HtmlOptions options = new HtmlOptions();
            options.IsResourcesEmbedded = true;

            List<PageHtml> pages = htmlHandler.GetPages(guid, options);

            foreach (PageHtml page in pages)
            {
                Console.WriteLine("Page number: {0}", page.PageNumber);
                Console.WriteLine("Html content: {0}", page.HtmlContent);
            }
        }
        public static void InHtmlRepresentation()
        {
            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "document.xlsx";

            // Set html options to show grid lines
            HtmlOptions options = new HtmlOptions();
            options.CellsOptions.ShowHiddenSheets = true;

            DocumentInfoContainer container = htmlHandler.GetDocumentInfo(new DocumentInfoOptions(guid));

            foreach (PageData page in container.Pages)
                Console.WriteLine("Page number: {0}, Page Name: {1}, IsVisible: {2}", page.Number, page.Name, page.IsVisible);

            List<PageHtml> pages = htmlHandler.GetPages(guid, options);

            foreach (PageHtml page in pages)
            {
                Console.WriteLine("Page number: {0}", page.PageNumber);
                //Console.WriteLine("Html content: {0}", page.HtmlContent);
            }
        }
        /// <summary>
        /// Get document html representation
        /// </summary>
        public static void Get_Html_With_Resources()
        {
            Console.WriteLine("***** {0} *****", "Get document html representation");

            /* ********************* SAMPLE ********************* */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "word.doc";

            List<PageHtml> pages = htmlHandler.GetPages(guid);

            foreach (PageHtml page in pages)
            {
                Console.WriteLine("Page number: {0}", page.PageNumber);
                Console.WriteLine("Resources count: {0}", page.HtmlResources.Count);
                Console.WriteLine("Html content: {0}", page.HtmlContent);

                // Html resources descriptions
                foreach (HtmlResource resource in page.HtmlResources)
                {
                    Console.WriteLine(resource.ResourceName, resource.ResourceType);

                    // Get html page resource stream
                    Stream resourceStream = htmlHandler.GetResource(guid, resource);
                }
            }
        }
        public static void Run()
        {
            // Setup viewer config
            ViewerConfig viewerConfig = new ViewerConfig();
            viewerConfig.StoragePath = @"c:\\storage";
            viewerConfig.LocalesPath = @"c:\\locales";

            // Create html handler
            CultureInfo cultureInfo = new CultureInfo("fr-FR");
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(viewerConfig, cultureInfo); 
        }
        public void Page_Load(object sender, EventArgs e)
        {
            var file       = GetValueFromQueryString("file");
            var page       = Convert.ToInt32(GetValueFromQueryString("page"));
            var attachment = GetValueFromQueryString("attachment");

            string            watermarkText     = GetValueFromQueryString("watermarkText");
            int?              watermarkColor    = Convert.ToInt32(GetValueFromQueryString("watermarkColor"));
            WatermarkPosition watermarkPosition = (WatermarkPosition)Enum.Parse(typeof(WatermarkPosition), GetValueFromQueryString("watermarkPosition"), true);
            string            widthFromQuery    = GetValueFromQueryString("watermarkWidth");
            int?              watermarkWidth    = GetValueFromQueryString("watermarkWidth") == "null" ? null : (int?)Convert.ToInt32(GetValueFromQueryString("watermarkWidth"));
            byte              watermarkOpacity  = Convert.ToByte(GetValueFromQueryString("watermarkOpacity"));


            ViewerHtmlHandler handler             = Utils.CreateViewerHtmlHandler();
            List <int>        pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o = new HtmlOptions();

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            o.HtmlResourcePrefix  = (String.Format(
                                         "/page/resource?file=%s&page=%d&resource=",
                                         file,
                                         page
                                         ));
            if (watermarkText != "")
            {
                o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }
            var docInfo = handler.GetDocumentInfo(file);

            List <PageHtml> list = Utils.LoadPageHtmlList(handler, file, o);

            string fullHtml = "";

            foreach (AttachmentBase attachmentBase in docInfo.Attachments.Where(x => x.Name == attachment))
            {
                // Get attachment document html representation
                List <PageHtml> pages = handler.GetPages(attachmentBase, o);
                foreach (PageHtml pageHtml in pages.Where(x => x.PageNumber == page))
                {
                    fullHtml += pageHtml.HtmlContent;
                }
                ;
            }

            HttpContext.Current.Response.ContentType = "text/html";
            HttpContext.Current.Response.Write(fullHtml);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
Пример #15
0
 public static List <PageHtml> LoadAttachmentHtmlList(ViewerHtmlHandler handler, String filename, String attahchment, HtmlOptions options)
 {
     try
     {
         return(handler.GetPages(_cachePath + "\\" + Path.GetFileNameWithoutExtension(filename) + Path.GetExtension(filename).Replace(".", "_") + "\\attachments\\" + attahchment, options));
     }
     catch (Exception x)
     {
         throw x;
     }
 }
 public static List <PageHtml> LoadPageHtmlList(ViewerHtmlHandler handler, String filename, HtmlOptions options)
 {
     try
     {
         return(handler.GetPages(filename, options));
     }
     catch (Exception x)
     {
         throw x;
     }
 }
        public ViewerController()
        {
            _config = new ViewerConfig
            {
                StoragePath = _storagePath,
                TempPath    = _tempPath,
                UseCache    = true
            };

            _htmlHandler  = new ViewerHtmlHandler(_config);
            _imageHandler = new ViewerImageHandler(_config);
        }
        public ViewerController()
        {
            _config = new ViewerConfig
            {
                StoragePath = _storagePath,
                TempPath = _tempPath,
                UseCache = true
            };

            _htmlHandler = new ViewerHtmlHandler(_config);
            _imageHandler = new ViewerImageHandler(_config);
        }
Пример #19
0
        public ActionResult Get(string file)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerHtmlHandler     handler = Utils.CreateViewerHtmlHandler();
            DocumentInfoContainer info    = null;
            ResultModel           model   = new ResultModel();
            DocumentInfoOptions   options = new DocumentInfoOptions(file);

            try
            {
                if (Path.GetExtension(file).ToLower().StartsWith(".xls"))
                {
                    info = handler.GetDocumentInfo(file, new GroupDocs.Viewer.Domain.Options.DocumentInfoOptions()
                    {
                        CellsOptions = new GroupDocs.Viewer.Converter.Options.CellsOptions()
                        {
                            CountRowsPerPage = 150, OnePagePerSheet = false
                        }
                    });
                }
                else
                {
                    info = handler.GetDocumentInfo(file);
                }
            }
            catch (Exception x)
            {
                throw x;
            }
            model.pages = info.Pages;
            List <Attachment> attachmentList = new List <Attachment>();

            foreach (AttachmentBase attachment in info.Attachments)
            {
                List <int>      count = new List <int>();
                List <PageHtml> pages = handler.GetPages(attachment);
                for (int i = 1; i <= pages.Count; i++)
                {
                    count.Add(i);
                }
                model.attachments.Add(new Attachment(attachment.Name, count));
            }
            return(Content(JsonConvert.SerializeObject(
                               model,
                               Formatting.Indented,
                               new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }
                               ), "application/json"));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _htmlHandler = (ViewerHtmlHandler)Session["htmlHandler"];

            GetResourceForHtmlParameters parameters = new GetResourceForHtmlParameters();


            parameters.DocumentPath = GetValueFromQueryString("documentPath");
            parameters.ResourceName = GetValueFromQueryString("resourceName");
            parameters.PageNumber   = int.Parse(GetValueFromQueryString("pageNumber") != String.Empty ? GetValueFromQueryString("pageNumber") : "0");

            if (!string.IsNullOrEmpty(parameters.ResourceName) &&
                parameters.ResourceName.IndexOf("/", StringComparison.Ordinal) >= 0)
            {
                parameters.ResourceName = parameters.ResourceName.Replace("/", "");
            }


            try
            {
                var resource = new HtmlResource
                {
                    ResourceName       = parameters.ResourceName,
                    ResourceType       = Utils.GetResourceType(parameters.ResourceName),
                    DocumentPageNumber = parameters.PageNumber
                };
                var stream = _htmlHandler.GetResource(parameters.DocumentPath, resource);
                if (stream == null || stream.Length == 0)
                {
                    Response.StatusCode = ((int)HttpStatusCode.Gone);
                    Response.End();
                }
                else
                {
                    byte[] Bytes = new byte[stream.Length];
                    stream.Read(Bytes, 0, Bytes.Length);
                    //string contentDispositionString = "attachment; filename=\"" + parameters.ResourceName + "\"";
                    string contentDispositionString = new ContentDisposition {
                        FileName = parameters.ResourceName, Inline = true
                    }.ToString();

                    HttpContext.Current.Response.ContentType = Utils.GetImageMimeTypeFromFilename(parameters.ResourceName);
                    HttpContext.Current.Response.AddHeader("Content-Disposition", contentDispositionString);
                    HttpContext.Current.Response.AddHeader("Content-Length", stream.Length.ToString());
                    HttpContext.Current.Response.OutputStream.Write(Bytes, 0, Bytes.Length);
                    HttpContext.Current.Response.Flush();
                    HttpContext.Current.Response.End();
                }
            }
            catch
            {
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var file = GetValueFromQueryString("file");
            var page = Convert.ToInt32(GetValueFromQueryString("page"));

            string            watermarkText     = GetValueFromQueryString("watermarkText");
            int?              watermarkColor    = Convert.ToInt32(GetValueFromQueryString("watermarkColor"));
            WatermarkPosition watermarkPosition = (WatermarkPosition)Enum.Parse(typeof(WatermarkPosition), GetValueFromQueryString("watermarkPosition"), true);
            string            widthFromQuery    = GetValueFromQueryString("watermarkWidth");
            int?              watermarkWidth    = GetValueFromQueryString("watermarkWidth") == "null" ? null : (int?)Convert.ToInt32(GetValueFromQueryString("watermarkWidth"));
            byte              watermarkOpacity  = Convert.ToByte(GetValueFromQueryString("watermarkOpacity"));

            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerHtmlHandler handler             = Utils.CreateViewerHtmlHandler();
            List <int>        pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o = new HtmlOptions();

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            o.HtmlResourcePrefix  = (String.Format(
                                         "/page/resource?file=%s&page=%d&resource=",
                                         file,
                                         page
                                         ));
            if (watermarkText != "")
            {
                o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }

            List <PageHtml> list = Utils.LoadPageHtmlList(handler, file, o);

            string fullHtml = "";

            foreach (PageHtml pageHtml in list.Where(x => x.PageNumber == page))
            {
                fullHtml = pageHtml.HtmlContent;
            }
            ;

            HttpContext.Current.Response.ContentType = "text/html";
            HttpContext.Current.Response.Write(fullHtml);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
Пример #22
0
        public HomeController()
        {
            LicenseHelper.SetGroupDocsViewerLicense();

            _config = new ViewerConfig
            {
                StoragePath = _storagePath,
                TempPath    = _tempPath,
                UseCache    = true
            };

            _htmlHandler = new ViewerHtmlHandler(_config);
            //_imageHandler = new ViewerImageHandler(_config);
        }
Пример #23
0
        public HttpResponseMessage Get(string file, string attachment, int page, string watermarkText, int?watermarkColor, WatermarkPosition?watermarkPosition, int?watermarkWidth, byte watermarkOpacity)
        {
            var attachmentPath             = "cache\\" + Path.GetFileNameWithoutExtension(file) + Path.GetExtension(file).Replace(".", "_") + "\\attachments\\" + attachment;
            ViewerHtmlHandler handler      = Utils.CreateViewerHtmlHandler();
            var        docInfo             = handler.GetDocumentInfo(file);
            List <int> pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o = new HtmlOptions();

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            o.HtmlResourcePrefix  = "/AttachmentResource?file=" + file + "&attachment=" + attachment + "&page=" + page + "&resource=";
            if (watermarkText != "")
            {
                o.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }
            string fullHtml       = "";
            var    attachmentFile = _cachePath + "\\" + Path.GetFileNameWithoutExtension(file) + Path.GetExtension(file).Replace(".", "_") + "\\attachments";

            if (Directory.Exists(attachmentFile.Replace(@"\\", @"\")))
            {
                List <PageHtml> pages = handler.GetPages(attachmentPath, o);
                foreach (PageHtml pageHtml in pages.Where(x => x.PageNumber == page))
                {
                    fullHtml += pageHtml.HtmlContent;
                }
                ;
            }
            else
            {
                foreach (AttachmentBase attachmentBase in docInfo.Attachments.Where(x => x.Name == attachment))
                {
                    // Get attachment document html representation
                    List <PageHtml> pages = handler.GetPages(attachmentBase, o);
                    foreach (PageHtml pageHtml in pages.Where(x => x.PageNumber == page))
                    {
                        fullHtml += pageHtml.HtmlContent;
                    }
                    ;
                }
            }
            var response = new HttpResponseMessage();

            response.Content = new StringContent(fullHtml);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            return(response);
        }
Пример #24
0
        public JsonResult <List <string> > Get()
        {
            ViewerHtmlHandler      handler = Utils.CreateViewerHtmlHandler();
            List <FileDescription> tree    = null;

            tree = handler.GetFileList().Files;
            List <String> result = tree.Where(
                x => x.Name != "README.txt" &&
                !x.IsDirectory &&
                !String.IsNullOrWhiteSpace(x.Name) &&
                !String.IsNullOrWhiteSpace(x.FileFormat)
                ).Select(x => x.Name).ToList();

            return(Json(result));
        }
        public static void Reorder_Pages_In_Html_Mode()
        {
            Console.WriteLine("***** {0} *****", "Reorder pages in Html mode");

            /* ********************* SAMPLE ********************* */
            /* ********************   Reorder 1st and 2nd pages  *********************** */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "word.doc";
            int pageNumber = 1;
            int newPosition = 2;

            // Perform page reorder
            ReorderPageOptions options = new ReorderPageOptions(guid, pageNumber, newPosition);
            htmlHandler.ReorderPage(options);


            /* ********************  Retrieve all document pages including transformation *********************** */

            // Set html options to include reorder transformations
            HtmlOptions htmlOptions = new HtmlOptions
            {
                Transformations = Transformation.Reorder
            };

            // Get html representation of all document pages, including reorder transformations 
            List<PageHtml> pages = htmlHandler.GetPages(guid, htmlOptions);


            /* ********************  Retrieve all document pages excluding transformation *********************** */

            // Set html options NOT to include ANY transformations
            HtmlOptions noTransformationsOptions = new HtmlOptions
            {
                Transformations = Transformation.None // This is by default
            };

            // Get html representation of all document pages, without transformations 
            List<PageHtml> pagesWithoutTransformations = htmlHandler.GetPages(guid, noTransformationsOptions);

            // Get html representation of all document pages, without transformations
            List<PageHtml> pagesWithoutTransformations2 = htmlHandler.GetPages(guid);
        }
Пример #26
0
        public ResultModel Get(string file)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }

            ViewerHtmlHandler     handler = Utils.CreateViewerHtmlHandler();
            ResultModel           model   = new ResultModel();
            DocumentInfoContainer info    = null;

            try
            {
                if (Path.GetExtension(file).ToLower().StartsWith(".xls"))
                {
                    info = handler.GetDocumentInfo(file, new GroupDocs.Viewer.Domain.Options.DocumentInfoOptions()
                    {
                        CellsOptions = new GroupDocs.Viewer.Converter.Options.CellsOptions()
                        {
                            CountRowsPerPage = 150, OnePagePerSheet = false
                        }
                    });
                }
                else
                {
                    info = handler.GetDocumentInfo(file);
                }
            }
            catch (Exception x)
            {
                throw x;
            }

            model.pages = Convert(info.Pages);
            List <Attachment> attachmentList = new List <Attachment>();

            foreach (AttachmentBase attachment in info.Attachments)
            {
                List <int>      count = new List <int>();
                List <PageHtml> pages = handler.GetPages(attachment);
                for (int i = 1; i <= pages.Count; i++)
                {
                    count.Add(i);
                }
                model.attachments.Add(new Attachment(attachment.Name, count));
            }
            return(model);
        }
Пример #27
0
        public HttpResponseMessage Get(string file, string attachment, int page, string resource)
        {
            var attachmentPath                        = "cache\\" + Path.GetFileNameWithoutExtension(file) + Path.GetExtension(file).Replace(".", "_") + "\\attachments\\" + attachment;
            ViewerHtmlHandler     handler             = Utils.CreateViewerHtmlHandler();
            DocumentInfoContainer info                = handler.GetDocumentInfo(file);
            List <int>            pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o          = new HtmlOptions();
            int         pageNumber = page;

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;
            List <PageHtml>     pages         = handler.GetPages(attachmentPath, o);
            List <HtmlResource> htmlResources = pages.Where(x => x.PageNumber == page).Select(x => x.HtmlResources).FirstOrDefault();
            var    fileResource = htmlResources.Where(x => x.ResourceName == resource).FirstOrDefault();
            string type         = "";

            if (fileResource != null)
            {
                switch (fileResource.ResourceType)
                {
                case HtmlResourceType.Font:
                    type = "application/font-woff";
                    break;

                case HtmlResourceType.Style:

                    type = "text/css";
                    break;

                case HtmlResourceType.Image:
                    type = "image/jpeg";
                    break;

                case HtmlResourceType.Graphics:
                    type = "image/svg+xml";
                    break;
                }
                Stream stream = handler.GetResource(attachmentPath, fileResource);
                var    result = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue(type);
                return(result);
            }
            return(null);
        }
Пример #28
0
        public HttpResponseMessage Get(string file, int page, string resource)
        {
            ViewerHtmlHandler handler             = Utils.CreateViewerHtmlHandler();
            List <int>        pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o          = new HtmlOptions();
            int         pageNumber = page;

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;

            List <PageHtml>     list          = Utils.LoadPageHtmlList(handler, file, o);
            List <HtmlResource> htmlResources = list.Where(x => x.PageNumber == page).Select(x => x.HtmlResources).FirstOrDefault();
            var    fileResource = htmlResources.Where(x => x.ResourceName == resource).FirstOrDefault();
            string type         = "";

            if (fileResource != null)
            {
                switch (fileResource.ResourceType)
                {
                case HtmlResourceType.Font:
                    type = "application/font-woff";
                    break;

                case HtmlResourceType.Style:

                    type = "text/css";
                    break;

                case HtmlResourceType.Image:
                    type = "image/jpeg";
                    break;

                case HtmlResourceType.Graphics:
                    type = "image/svg+xml";
                    break;
                }
                Stream stream = handler.GetResource(file, fileResource);
                var    result = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new StreamContent(stream);
                result.Content.Headers.ContentType = new MediaTypeHeaderValue(type);
                return(result);
            }
            return(null);
        }
        /// <summary>
        ///  document in html representation and reorder a page
        /// </summary>
        /// <param name="DocumentName">file/document name</param>
        /// <param name="CurrentPageNumber">Page existing order number</param>
        /// <param name="NewPageNumber">Page new order number</param>
        /// <param name="DocumentPassword">Password Parameter is optional</param>
        public static List <HtmlInfo> RenderDocumentAsHtml(String DocumentName, int CurrentPageNumber, int NewPageNumber, String DocumentPassword = null)
        {
            //ExStart:RenderAsHtmlAndReorderPage
            //Get Configurations
            ViewerConfig config = Utilities.GetConfigurations();

            // Cast ViewerHtmlHandler class object to its base class(ViewerHandler).
            ViewerHandler <PageHtml> handler = new ViewerHtmlHandler(config);

            // Guid implies that unique document name
            string guid = DocumentName;

            //Instantiate the HtmlOptions object with setting of Reorder Transformation
            HtmlOptions options = new HtmlOptions {
                Transformations = Transformation.Reorder
            };

            //to get html representations of pages with embedded resources
            options.IsResourcesEmbedded = true;

            // Set password if document is password protected.
            if (!String.IsNullOrEmpty(DocumentPassword))
            {
                options.Password = DocumentPassword;
            }

            //Call ReorderPage and pass the reference of ViewerHandler's class  parameter by reference.
            Utilities.PageTransformations.ReorderPage(ref handler, guid, CurrentPageNumber, NewPageNumber);

            //down cast the handler(ViewerHandler) to viewerHtmlHandler
            ViewerHtmlHandler htmlHandler = (ViewerHtmlHandler)handler;

            //Get document pages in html form
            List <PageHtml> pages = htmlHandler.GetPages(guid, options);

            List <HtmlInfo> contents = new List <HtmlInfo>();

            foreach (PageHtml page in pages)
            {
                HtmlInfo htmlInfo = new HtmlInfo();
                htmlInfo.HtmlContent = page.HtmlContent;
                htmlInfo.PageNmber   = page.PageNumber;
                contents.Add(htmlInfo);
            }
            return(contents);
            //ExEnd:RenderAsHtmlAndReorderPage
        }
Пример #30
0
        public ActionResult Get(string file)
        {
            ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler();

            Stream pdf = null;

            try
            {
                pdf = handler.GetPdfFile(file).Stream;
            }
            catch (Exception x)
            {
                throw x;
            }

            return(new FileStreamResult(pdf, "application/pdf"));
        }
        public static List <HtmlInfo> RotateDocumentAsHtml(String DocumentName, int pageNumber, int RotationAngle, String DocumentPassword = null)
        {
            //ExStart:RenderAsImageWithRotationTransformation
            //Get Configurations
            ViewerConfig config = Utilities.GetConfigurations();

            // Create image handler
            ViewerHandler <PageHtml> handler = new ViewerHtmlHandler(config);

            // Guid implies that unique document name
            string guid = DocumentName;

            //Initialize ImageOptions Object and setting Rotate Transformation
            HtmlOptions options = new HtmlOptions {
                Transformations = Transformation.Rotate
            };

            // Set password if document is password protected.
            if (!String.IsNullOrEmpty(DocumentPassword))
            {
                options.Password = DocumentPassword;
            }

            //Call RotatePages to apply rotate transformation to a page
            Utilities.PageTransformations.RotatePages(ref handler, guid, pageNumber, RotationAngle);

            //down cast the handler(ViewerHandler) to viewerHtmlHandler
            ViewerHtmlHandler htmlHandler = (ViewerHtmlHandler)handler;

            //Get document pages in image form
            List <PageHtml> pages = htmlHandler.GetPages(guid, options);

            List <HtmlInfo> contents = new List <HtmlInfo>();

            foreach (PageHtml page in pages)
            {
                HtmlInfo htmlInfo = new HtmlInfo();
                htmlInfo.HtmlContent = page.HtmlContent;
                htmlInfo.PageNmber   = page.PageNumber;
                contents.Add(htmlInfo);
            }

            return(contents);
            //ExEnd:RenderAsImageWithRotationTransformation
        }
Пример #32
0
        protected void Page_Load(object sender, EventArgs e)
        {
            License lic = new License();

            lic.SetLicense("E:/GroupDocs.Total.lic");
            _config = new ViewerConfig
            {
                StoragePath = _storagePath,
                TempPath    = _tempPath,
                UseCache    = true
            };

            _htmlHandler  = new ViewerHtmlHandler(_config);
            _imageHandler = new ViewerImageHandler(_config);

            HttpContext.Current.Session["imageHandler"] = _imageHandler;
            HttpContext.Current.Session["htmlHandler"]  = _htmlHandler;
        }
        public ActionResult Index(string file, int page, string resource)
        {
            ViewerHtmlHandler handler             = Utils.CreateViewerHtmlHandler();
            List <int>        pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions o          = new HtmlOptions();
            int         pageNumber = page;

            o.PageNumbersToRender = pageNumberstoRender;
            o.PageNumber          = page;
            o.CountPagesToRender  = 1;

            List <PageHtml>     list          = Utils.LoadPageHtmlList(handler, file, o);
            List <HtmlResource> htmlResources = list.Where(x => x.PageNumber == page).Select(x => x.HtmlResources).FirstOrDefault();
            var    fileResource = htmlResources.Where(x => x.ResourceName == resource).FirstOrDefault();
            string type         = "";

            if (fileResource != null)
            {
                switch (fileResource.ResourceType)
                {
                case HtmlResourceType.Font:
                    type = "application/font-woff";
                    break;

                case HtmlResourceType.Style:

                    type = "text/css";
                    break;

                case HtmlResourceType.Image:
                    type = "image/jpeg";
                    break;

                case HtmlResourceType.Graphics:
                    type = "image/svg+xml";
                    break;
                }
                Stream stream = handler.GetResource(file, fileResource);
                return(new FileStreamResult(stream, type));
            }
            return(null);
        }
Пример #34
0
        public HttpResponseMessage Get(string file, int page, string watermarkText, int?watermarkColor, WatermarkPosition?watermarkPosition, int?watermarkWidth, byte watermarkOpacity)
        {
            if (Utils.IsValidUrl(file))
            {
                file = Utils.DownloadToStorage(file);
            }
            ViewerHtmlHandler handler = Utils.CreateViewerHtmlHandler();

            List <int> pageNumberstoRender = new List <int>();

            pageNumberstoRender.Add(page);
            HtmlOptions options = new HtmlOptions();

            options.PageNumbersToRender = pageNumberstoRender;
            options.PageNumber          = page;
            options.CountPagesToRender  = 1;

            if (Path.GetExtension(file).ToLower().StartsWith(".xls"))
            {
                options.CellsOptions.OnePagePerSheet  = false;
                options.CellsOptions.CountRowsPerPage = 150;
            }

            options.HtmlResourcePrefix = "/pageresource?file=" + file + "&page=" + page + "&resource=";
            if (watermarkText != "")
            {
                options.Watermark = Utils.GetWatermark(watermarkText, watermarkColor, watermarkPosition, watermarkWidth, watermarkOpacity);
            }

            List <PageHtml> list     = Utils.LoadPageHtmlList(handler, file, options);
            string          fullHtml = "";

            foreach (PageHtml pageHtml in list.Where(x => x.PageNumber == page))
            {
                fullHtml = pageHtml.HtmlContent;
            }
            ;
            var response = new HttpResponseMessage();

            response.Content = new StringContent(fullHtml);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            return(response);
        }
        static void RenderTestFile(string fileName, DropboxClient client)
        {
            var storage = new DropboxStorage(client);

            var config = new ViewerConfig
            {
                EnableCaching = true
            };
            var viewer = new ViewerHtmlHandler(config, storage);

            var pages = viewer.GetPages(fileName);

            foreach (var page in pages)
            {
                Console.WriteLine(page.HtmlContent);
            }

            viewer.ClearCache(fileName);
        }
Пример #36
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _config = new ViewerConfig
            {
                StoragePath = _storagePath,
                TempPath    = _tempPath,
                UseCache    = true
                              // CachePath=_CachePath
            };

            _htmlHandler  = new ViewerHtmlHandler(_config);
            _imageHandler = new ViewerImageHandler(_config);

            HttpContext.Current.Session["imageHandler"] = _imageHandler;
            HttpContext.Current.Session["htmlHandler"]  = _htmlHandler;

            // _streams.Add("Stream1.pdf", HttpWebRequest.Create("http://unfccc.int/resource/docs/convkp/kpeng.pdf").GetResponse().GetResponseStream());
            //_streams.Add("StreamExample_2.doc", HttpWebRequest.Create("http://www.acm.org/sigs/publications/pubform.doc").GetResponse().GetResponseStream());
        }
        public void ShouldRender()
        {
            // Create a file to be rendered
            string filePath = "sample/file.txt";

            using (Stream testStream = GetTestFileStream())
            {
                _fileStorage.SaveFile(filePath, testStream);
            }

            // Create IFileStorage and run the rendering
            AzureBlobStorage  storage = new AzureBlobStorage(TestContainerName);
            ViewerHtmlHandler handler = new ViewerHtmlHandler(storage);
            List <PageHtml>   pages   = handler.GetPages("sample/file.txt");


            Assert.True(pages.Count > 0);
            Assert.NotNull(pages[0].HtmlContent);
        }
        public ActionResult Get(string file)
        {
            ViewerHtmlHandler handler  = Utils.CreateViewerHtmlHandler();
            Stream            original = null;

            try
            {
                original = handler.GetFile(file).Stream;
            }
            catch (Exception x)
            {
                throw x;
            }

            using (var ms = new MemoryStream())
            {
                original.CopyTo(ms);
                return(File(ms.ToArray(), "application/octet-stream", file));
            }
        }
        /// <summary>
        /// Remove cache files
        /// </summary>
        public static void RemoveCacheFiles()
        {
            try
            {
                //ExStart:RemoveCacheFiles
                // Setup GroupDocs.Viewer config
                ViewerConfig config = Utilities.GetConfigurations();

                // Init viewer image or html handler
                ViewerHtmlHandler viewerImageHandler = new ViewerHtmlHandler(config);

                //Clear all cache files
                viewerImageHandler.ClearCache();
                //ExEnd:RemoveCacheFiles
            }
            catch (System.Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
        public ViewerController()
        {
            var htmlConfig = new ViewerConfig
            {
                StoragePath = _storagePath,
                CachePath = _cachePath,
                UseCache = true
            };

            _htmlHandler = new ViewerHtmlHandler(htmlConfig);

            var imageConfig = new ViewerConfig
            {
                StoragePath = _storagePath,
                CachePath = _cachePath,
                UseCache = true,
                UsePdf = UsePdfInImageEngine
            };

            _imageHandler = new ViewerImageHandler(imageConfig);
        }
        public static void InHtmlRepresentation()
        {
            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "document.xlsx";

            // Set html options to show grid lines
            HtmlOptions options = new HtmlOptions();
            options.CellsOptions.ShowGridLines = true;
            List<PageHtml> pages = htmlHandler.GetPages(guid, options);

            foreach (PageHtml page in pages)
            {
                Console.WriteLine("Page number: {0}", page.PageNumber);
                Console.WriteLine("Html content: {0}", page.HtmlContent);
            }
        }
        /// <summary>
        /// Perform multiple transformations in Html mode
        /// </summary>
        public static void Multiple_Transformations_For_Html()
        {
            Console.WriteLine("***** {0} *****", "Perform multiple transformations in Html mode");

            /* ********************* SAMPLE ********************* */

            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "word.doc";

            // Rotate first page 90 degrees
            htmlHandler.RotatePage(new RotatePageOptions(guid, 1, 90));

            // Rotate second page 180 degrees
            htmlHandler.RotatePage(new RotatePageOptions(guid, 2, 180));

            // Reorder first and second pages
            htmlHandler.ReorderPage(new ReorderPageOptions(guid, 1, 2));

            // Set options to include rotate and reorder transformations
            HtmlOptions options = new HtmlOptions { Transformations = Transformation.Rotate | Transformation.Reorder };

            // Set watermark properties
            Watermark watermark = new Watermark("This is watermark text")
            {
                Color = System.Drawing.Color.Blue,
                Position = WatermarkPosition.Diagonal,
                Width = 100
            };

            options.Watermark = watermark;

            // Get document pages html representation with multiple transformations
            List<PageHtml> pages = htmlHandler.GetPages(guid, options);
        }
        /// <summary>
        /// Rotate page in Html mode
        /// </summary>
        public static void Rotate_Page_In_Html_Mode()
        {
            Console.WriteLine("***** {0} *****", "Rotate page in Html mode");

            /* ********************* SAMPLE ********************* */

            string licensePath = @"D:\GroupDocs.Viewer.lic";

            // Setup license
            GroupDocs.Viewer.License lic = new GroupDocs.Viewer.License();
            lic.SetLicense(licensePath);

            /* ********************  SAMPLE BEGIN ************************ */
            /* ********************  Rotate 1st page of the document by 90 deg *********************** */
            // Setup GroupDocs.Viewer config
            ViewerConfig config = new ViewerConfig();
            config.StoragePath = @"C:\storage";

            // Create html handler
            ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
            string guid = "word.doc";

            // Set rotation angle 90 for page number 1
            RotatePageOptions rotateOptions = new RotatePageOptions(guid, 1, 90);

            // Perform page rotation
            htmlHandler.RotatePage(rotateOptions);


            /* ********************  Retrieve all document pages including transformation *********************** */
            // Set html options to include rotate transformations
            HtmlOptions htmlOptions = new HtmlOptions
            {
                Transformations = Transformation.Rotate
            };

            // Get html representation of all document pages, including rotate transformations 
            List<PageHtml> pages = htmlHandler.GetPages(guid, htmlOptions);


            /* ********************  Retrieve all document pages excluding transformation *********************** */
            // Set html options NOT to include ANY transformations
            HtmlOptions noTransformationsOptions = new HtmlOptions
            {
                Transformations = Transformation.None // This is by default
            };

            // Get html representation of all document pages, without transformations 
            List<PageHtml> pagesWithoutTransformations = htmlHandler.GetPages(guid, noTransformationsOptions);

            // Get html representation of all document pages, without transformations
            List<PageHtml> pagesWithoutTransformations2 = htmlHandler.GetPages(guid);

            /*********************  SAMPLE END *************************/
            //foreach (PageHtml page in pages)
            //{
            //    // Page number
            //    Console.WriteLine("Page number: {0}", page.PageNumber);
            //}
        }