public byte[] ViewAsPdf(string filePath)
        {
            List <MemoryStream> pages = new List <MemoryStream>();
            var stringContent         = new StringBuilder();


            using (Viewer viewer = new Viewer(filePath))
            {
                var streamFactory = new MemoryFileStreamFactory();
                var options       = new PdfViewOptions(streamFactory);

                viewer.View(options);

                // Return or write stream
                var stream    = streamFactory.Stream;
                var byteArray = new byte[stream.Length];
                //var x = stream.Read(byteArray, 0, (int) stream.Length);
                byteArray = stream.ToArray();
                return(byteArray);
            }



            return(new byte[1]);
        }
示例#2
0
        public HttpResponseMessage DownloadPDFDocument(string file, string folderName)
        {
            file       = file.Replace("../", "").Replace("//", "");
            folderName = folderName.Replace("../", "").Replace("//", "");
            string outPath = AppSettings.OutputDirectory + folderName + "/" + Path.GetFileNameWithoutExtension(file) + ".pdf";

            //GroupDocs.Apps.API.Models.License.SetGroupDocsViewerLicense();

            PdfViewOptions options = new PdfViewOptions(outPath);

            GroupDocs.Viewer.Viewer viewer = new GroupDocs.Viewer.Viewer(AppSettings.WorkingDirectory + folderName + "/" + file);
            viewer.View(options);

            FileStream fileStream = new FileStream(outPath, FileMode.Open, FileAccess.Read);

            using (var ms = new MemoryStream())
            {
                fileStream.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/octet-stream");
                fileStream.Close();
                return(result);
            }
        }
示例#3
0
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "cmx_result_{0}.html");

            // TO HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CMX))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);

                viewer.View(options);

                // To render 2nd image, just specify
                //viewer.View(options,2);
            }

            // TO JPG
            pageFilePathFormat = Path.Combine(outputDirectory, "cmx_result_{0}.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CMX))
            {
                JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);

                viewer.View(options);

                // To render 2nd image, just specify
                //viewer.View(options,2);
            }

            // TO PNG
            pageFilePathFormat = Path.Combine(outputDirectory, "cmx_result_{0}.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CMX))
            {
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);

                viewer.View(options);

                // To render 2nd image, just specify
                //viewer.View(options,2);
            }

            // TO PDF
            pageFilePathFormat = Path.Combine(outputDirectory, "cmx_result.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CMX))
            {
                PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);

                viewer.View(options);

                // By default all images will be rendered in output.pdf, to render only 2nd image in output PDF
                //viewer.View(options,2);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputDirectory  = Utils.GetOutputDirectoryPath();
            string pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.html");

            // TO MULTI PAGES HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFileFullPath);

                viewer.View(options);
            }

            pageFileFullPath = Path.Combine(outputDirectory, "Txt_result_single_page.html");

            // TO SINGLE HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_2_TXT))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFileFullPath);
                options.RenderToSinglePage = true;

                viewer.View(options);
            }

            // TO JPG
            pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
            {
                JpgViewOptions options = new JpgViewOptions(pageFileFullPath);

                viewer.View(options);
            }

            // TO PNG
            pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
            {
                PngViewOptions options = new PngViewOptions(pageFileFullPath);

                viewer.View(options);
            }

            // TO PDF
            pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
            {
                PdfViewOptions options = new PdfViewOptions(pageFileFullPath);

                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
示例#5
0
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "result_page.html");

            // TO HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_VISIO))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
                options.VisioRenderingOptions.RenderFiguresOnly = true;
                options.VisioRenderingOptions.FigureWidth       = 250;

                viewer.View(options);
            }

            // TO JPG
            pageFilePathFormat = Path.Combine(outputDirectory, "visio_result.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_VISIO))
            {
                JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);
                options.VisioRenderingOptions.RenderFiguresOnly = true;
                options.VisioRenderingOptions.FigureWidth       = 250;

                viewer.View(options);
            }

            // TO PNG
            pageFilePathFormat = Path.Combine(outputDirectory, "visio_result.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_VISIO))
            {
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);
                options.VisioRenderingOptions.RenderFiguresOnly = true;
                options.VisioRenderingOptions.FigureWidth       = 250;

                viewer.View(options);
            }

            // TO PDF
            pageFilePathFormat = Path.Combine(outputDirectory, "visio_result.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_VISIO))
            {
                PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);
                options.VisioRenderingOptions.RenderFiguresOnly = true;
                options.VisioRenderingOptions.FigureWidth       = 250;

                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
示例#6
0
        public static void Run()
        {
            string outputDirectory = Utils.GetOutputDirectoryPath();
            string outputFilePath  = Path.Combine(outputDirectory, "output.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_DOCX))
            {
                PdfViewOptions options = new PdfViewOptions(outputFilePath);
                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
示例#7
0
        public IActionResult ViewDocument(string fileName)
        {
            var filePath       = _documentRepository.GetFilePath(fileName);
            var outputFilePath = _documentRepository.GetOutPutDirectory();
            var viewer         = new Viewer(filePath);
            var options        = new PdfViewOptions(outputFilePath);

            viewer.View(options);

            var fileStream = new FileStream(outputFilePath, FileMode.Open, FileAccess.Read);

            return(new FileStreamResult(fileStream, "application/pdf"));
        }
示例#8
0
        public static void Run()
        {
            string outputDirectory  = Utils.GetOutputDirectoryPath();
            string pageFileFullPath = Path.Combine(outputDirectory, "Excel_2003_Xml_result.html");

            /* Because the XML extension is associated with both an XML text document and Excel 2003 XML SpreadSheetML,
             * please specify the Excel2003XML fileType explicitly to render it as Excel 2003 XML SpreadSheetML.
             */

            LoadOptions loadOptions = new LoadOptions(FileType.Excel2003XML);

            // TO MULTI PAGES HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XML_SPREADSHEETML, loadOptions))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFileFullPath);

                viewer.View(options);
            }

            // TO JPG
            pageFileFullPath = Path.Combine(outputDirectory, "Excel_2003_Xml_result.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XML_SPREADSHEETML, loadOptions))
            {
                JpgViewOptions options = new JpgViewOptions(pageFileFullPath);

                viewer.View(options);
            }

            // TO PNG
            pageFileFullPath = Path.Combine(outputDirectory, "Excel_2003_Xml_result.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XML_SPREADSHEETML, loadOptions))
            {
                PngViewOptions options = new PngViewOptions(pageFileFullPath);

                viewer.View(options);
            }

            // TO PDF
            pageFileFullPath = Path.Combine(outputDirectory, "Excel_2003_Xml_result.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XML_SPREADSHEETML, loadOptions))
            {
                PdfViewOptions options = new PdfViewOptions(pageFileFullPath);

                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");

            // TO HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XLSX))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
                options.SpreadsheetOptions.RenderHeadings = true;

                viewer.View(options, 1, 2, 3);
            }

            // TO JPG
            pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XLSX))
            {
                JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);
                options.SpreadsheetOptions.RenderHeadings = true;

                viewer.View(options, 1, 2, 3);
            }

            // TO PNG
            pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XLSX))
            {
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);
                options.SpreadsheetOptions.RenderHeadings = true;

                viewer.View(options, 1, 2, 3);
            }

            // TO PDF
            pageFilePathFormat = Path.Combine(outputDirectory, "output.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_XLSX))
            {
                PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);
                options.SpreadsheetOptions.RenderHeadings = true;

                viewer.View(options, 1, 2, 3);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.html");

            // TO HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
                options.RenderToSinglePage = true; // Enable it if you want to convert all CHM content to single page

                //viewer.View(options,1,2,3); // Convert only 1,2,3 pages
                viewer.View(options);  // Convert all pages
            }

            // TO JPG
            pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
            {
                JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);

                viewer.View(options, 1, 2, 3); // Convert only 1,2,3 pages
                //viewer.View(options); // Convert all pages
            }

            // TO PNG
            pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
            {
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);

                viewer.View(options, 1, 2, 3); // Convert only 1,2,3 pages
                //viewer.View(options); // Convert all pages
            }

            // TO PDF
            pageFilePathFormat = Path.Combine(outputDirectory, "chm_result.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
            {
                PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);

                viewer.View(options); // Convert all pages
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
示例#11
0
        public static void Run()
        {
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_DOCX))
            {
                MemoryFileStreamFactory streamFactory = new MemoryFileStreamFactory();
                PdfViewOptions          options       = new PdfViewOptions(streamFactory);

                viewer.View(options);

                // Return or write stream
                MemoryStream stream = streamFactory.Stream;
            }

            Console.WriteLine("\nSource document rendered successfully.");
        }
示例#12
0
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "RAR_result_{0}.html");

            // TO HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_RAR_WITH_FOLDERS))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);

                viewer.View(options);
            }

            // TO JPG
            pageFilePathFormat = Path.Combine(outputDirectory, "RAR_result_{0}.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_RAR_WITH_FOLDERS))
            {
                JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);

                viewer.View(options);
            }

            // TO PNG
            pageFilePathFormat = Path.Combine(outputDirectory, "RAR_result_{0}.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_RAR_WITH_FOLDERS))
            {
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);

                viewer.View(options);
            }

            // TO PDF
            pageFilePathFormat = Path.Combine(outputDirectory, "RAR_result.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_RAR_WITH_FOLDERS))
            {
                PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);

                viewer.View(options);
            }

            GetViewInfoForRar();
            RenderSpecificArchiveFolder();

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
示例#13
0
        public ActionResult ViewHelpDoc()
        {
            try
            {
                var path          = Server.MapPath("~/Content/help/HELP_DOCUMENT.pdf");
                var AccesFilePath = Server.MapPath("~/Content/uploads/HELP_DOCUMENT.pdf");
                using (Viewer viewerObject = new Viewer(path))
                {
                    PdfViewOptions options = new PdfViewOptions(AccesFilePath);
                    viewerObject.View(options);
                }

                var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
                var fsResult   = new FileStreamResult(fileStream, "application/pdf");
                return(fsResult);
            }catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }

            //if we got here something went wrong
            return(View());
        }
        public IActionResult Index()
        {
            License lic = new License();

            lic.SetLicense(@"D:/GroupDocs.Total.NET.lic");

            string outputDirectory = ("Output/");
            string outputFilePath  = Path.Combine(outputDirectory, "output.pdf");

            using (Viewer viewer = new Viewer("SourceDocuments/sample.docx"))
            {
                PdfViewOptions options = new PdfViewOptions(outputFilePath);
                viewer.View(options);
            }
            var fileStream = new FileStream("Output/" + "output.pdf",
                                            FileMode.Open,
                                            FileAccess.Read
                                            );
            var fsResult = new FileStreamResult(fileStream, "application/pdf");

            ViewBag.filePath = "Output/output.pdf";
            return(View());
        }
        public static void Run()
        {
            string outputDirectory = Utils.GetOutputDirectoryPath();
            string filePath        = Path.Combine(outputDirectory, "output.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_DOCX))
            {
                Security security = new Security
                {
                    DocumentOpenPassword = "******",
                    PermissionsPassword  = "******",
                    Permissions          = Permissions.AllowAll ^ Permissions.DenyPrinting
                };

                PdfViewOptions options = new PdfViewOptions(filePath)
                {
                    Security = security
                };

                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "hpg_result.html");

            // TO HTML
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HPG))
            {
                HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
                //options.CadOptions = CadOptions.ForRenderingByScaleFactor(0.7f); // Render image and reduce it by 30%
                //options.CadOptions = CadOptions.ForRenderingByWidthAndHeight(400,400); // Render image and set output size to 400x400
                //options.CadOptions = CadOptions.ForRenderingByWidth(500); // Render image, fix width by 500 px and recalculate height
                //options.CadOptions = CadOptions.ForRenderingByHeight(500); // Render image, fix height by 500 px and recalculate width

                viewer.View(options);
            }

            // TO JPG
            pageFilePathFormat = Path.Combine(outputDirectory, "hpg_result.jpg");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HPG))
            {
                JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);
                //options.CadOptions = CadOptions.ForRenderingByScaleFactor(0.7f); // Render image and reduce it by 30%
                //options.CadOptions = CadOptions.ForRenderingByWidthAndHeight(400,400); // Render image and set output size to 400x400
                //options.CadOptions = CadOptions.ForRenderingByWidth(500); // Render image, fix width by 500 px and recalculate height
                //options.CadOptions = CadOptions.ForRenderingByHeight(500); // Render image, fix height by 500 px and recalculate width

                viewer.View(options);
            }

            // TO PNG
            pageFilePathFormat = Path.Combine(outputDirectory, "hpg_result.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HPG))
            {
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);
                //options.CadOptions = CadOptions.ForRenderingByScaleFactor(0.7f); // Render image and reduce it by 30%
                //options.CadOptions = CadOptions.ForRenderingByWidthAndHeight(400,400); // Render image and set output size to 400x400
                //options.CadOptions = CadOptions.ForRenderingByWidth(500); // Render image, fix width by 500 px and recalculate height
                //options.CadOptions = CadOptions.ForRenderingByHeight(500); // Render image, fix height by 500 px and recalculate width

                viewer.View(options);
            }

            // TO PDF
            pageFilePathFormat = Path.Combine(outputDirectory, "hpg_result.pdf");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HPG))
            {
                PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);
                //options.CadOptions = CadOptions.ForRenderingByScaleFactor(0.7f); // Render image and reduce it by 30%
                //options.CadOptions = CadOptions.ForRenderingByWidthAndHeight(400,400); // Render image and set output size to 400x400
                //options.CadOptions = CadOptions.ForRenderingByWidth(500); // Render image, fix width by 500 px and recalculate height
                //options.CadOptions = CadOptions.ForRenderingByHeight(500); // Render image, fix height by 500 px and recalculate width

                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "html_render_margins_page_{0}.jpg");

            /*
             * You can adjust margins (top,bottom,left,right) of final document by setting following properties in
             * options.WordProcessingOptions:
             *
             * LeftMargin
             * RightMargin
             * TopMargin
             * BottomMargin
             *
             * Default values in points are:
             * LeftMargin = RightMargin = 5
             * TopMargin = BottomMargin = 72
             */

            // TO JPG
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HTML))
            {
                JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);
                options.WordProcessingOptions.LeftMargin   = 40;
                options.WordProcessingOptions.RightMargin  = 40;
                options.WordProcessingOptions.TopMargin    = 40;
                options.WordProcessingOptions.BottomMargin = 40;

                viewer.View(options);
            }

            pageFilePathFormat = Path.Combine(outputDirectory, "html_render_margins_page_{0}.png");

            // TO PNG
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HTML))
            {
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);
                options.WordProcessingOptions.LeftMargin   = 40;
                options.WordProcessingOptions.RightMargin  = 40;
                options.WordProcessingOptions.TopMargin    = 40;
                options.WordProcessingOptions.BottomMargin = 40;

                viewer.View(options);
            }

            pageFilePathFormat = Path.Combine(outputDirectory, "html_render_margins.pdf");

            // TO PDF
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HTML))
            {
                PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);
                options.WordProcessingOptions.LeftMargin   = 40;
                options.WordProcessingOptions.RightMargin  = 40;
                options.WordProcessingOptions.TopMargin    = 40;
                options.WordProcessingOptions.BottomMargin = 40;

                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }