コード例 #1
0
        /// <summary>
        /// Adds watermark on document if its specified in configuration file.
        /// </summary>
        /// <param name="options"></param>
        private static void SetWatermarkOptions(ViewOptions options)
        {
            Watermark watermark = null;

            if (!string.IsNullOrEmpty(globalConfiguration.GetViewerConfiguration().GetWatermarkText()))
            {
                // Set watermark properties
                watermark = new Watermark(globalConfiguration.GetViewerConfiguration().GetWatermarkText())
                {
                    Color    = System.Drawing.Color.Blue,
                    Position = Position.Diagonal,
                };
            }

            if (watermark != null)
            {
                options.Watermark = watermark;
            }
        }
コード例 #2
0
        private HtmlViewOptions CreateHtmlViewOptions(int passedPageNumber = -1, int newAngle = 0)
        {
            HtmlViewOptions htmlViewOptions = HtmlViewOptions.ForExternalResources(
                pageNumber =>
            {
                string fileName      = $"p{pageNumber}.html";
                string cacheFilePath = this.cache.GetCacheFilePath(fileName);

                return(File.Create(cacheFilePath));
            },
                (pageNumber, resource) =>
            {
                string fileName      = $"p{pageNumber}_{resource.FileName}";
                string cacheFilePath = this.cache.GetCacheFilePath(fileName);

                return(File.Create(cacheFilePath));
            },
                (pageNumber, resource) =>
            {
                var urlPrefix = "/viewer/resources/" + Path.GetFileName(this.filePath).Replace(".", "_");
                return($"{urlPrefix}/p{ pageNumber}_{ resource.FileName}");
            });

            htmlViewOptions.SpreadsheetOptions = SpreadsheetOptions.ForOnePagePerSheet();
            htmlViewOptions.SpreadsheetOptions.TextOverflowMode = TextOverflowMode.HideText;
            htmlViewOptions.SpreadsheetOptions.RenderGridLines  = globalConfiguration.GetViewerConfiguration().GetShowGridLines();
            htmlViewOptions.SpreadsheetOptions.RenderHeadings   = true;

            SetWatermarkOptions(htmlViewOptions);

            if (passedPageNumber >= 0 && newAngle != 0)
            {
                Rotation rotationAngle = GetRotationByAngle(newAngle);
                htmlViewOptions.RotatePage(passedPageNumber, rotationAngle);
            }

            return(htmlViewOptions);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewerApiController"/> class.
        /// </summary>
        public ViewerApiController()
        {
            List <string> fontsDirectory = new List <string>();

            if (!string.IsNullOrEmpty(globalConfiguration.GetViewerConfiguration().GetFontsDirectory()))
            {
                fontsDirectory.Add(globalConfiguration.GetViewerConfiguration().GetFontsDirectory());
            }
        }