public static void Run()
        {
            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_DOCX))
            {
                ViewInfoOptions options  = ViewInfoOptions.ForPngView(true);
                ViewInfo        viewInfo = viewer.GetViewInfo(options);

                foreach (Page page in viewInfo.Pages)
                {
                    Console.WriteLine($"Page: {page.Number}");
                    Console.WriteLine("Text lines/words/characters:");

                    foreach (Line line in page.Lines)
                    {
                        Console.WriteLine(line);
                        foreach (Word word in line.Words)
                        {
                            Console.WriteLine("\t" + word);
                            foreach (Character character in word.Characters)
                            {
                                Console.WriteLine("\t\t" + character);
                            }
                        }
                    }
                }
            }

            Console.WriteLine("\nDocument text extracted successfully.\n");
        }
示例#2
0
 private void GetDocumentInfo()
 {
     try
     {
         using (Viewer viewer = new Viewer(Path.Combine(StorageFolder, DocumentName), settings))
         {
             ViewInfo info = viewer.GetViewInfo(ViewInfoOptions.ForPngView(false));
             lblTotalPages.Text = info.Pages.Count.ToString();
         }
     }
     catch
     {
         // Do something
     }
 }
示例#3
0
        private List <string> GetDocumentPages(string file, string folderName, string userEmail, int currentPage)
        {
            List <string> lstOutput   = new List <string>();
            string        outfileName = "page_{0}";
            string        outPath     = AppSettings.OutputDirectory + folderName + "/" + outfileName;

            outPath = Path.GetFullPath(outPath).Replace('\\', '/');

            //currentPage = currentPage - 1;

            string imagePath = string.Format(outPath, currentPage) + ".png";

            if (!Directory.Exists(AppSettings.OutputDirectory + folderName))
            {
                Directory.CreateDirectory(AppSettings.OutputDirectory + folderName);
            }

            if (System.IO.File.Exists(imagePath) && currentPage > 1)
            {
                lstOutput.Add(imagePath);
                return(lstOutput);
            }

            int i = currentPage;

            // check Words product family
            try
            {
                //GroupDocs.Apps.API.Models.License.SetGroupDocsViewerLicense();

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

                if (currentPage <= 1)
                {
                    lstOutput.Add(viewer.GetViewInfo(ViewInfoOptions.ForPngView(false)).Pages.Count.ToString());
                }

                viewer.View(options, new int[] { currentPage });
                lstOutput.Add(imagePath);

                return(lstOutput);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#4
0
        public static void Run()
        {
            string outputDirectory    = Utils.GetOutputDirectoryPath();
            string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.png");

            using (Viewer viewer = new Viewer(TestFiles.SAMPLE_DWG_WITH_LAYOUTS_AND_LAYERS))
            {
                ViewInfoOptions infoOptions = ViewInfoOptions.ForPngView(false);
                var             viewInfo    = viewer.GetViewInfo(infoOptions);

                // Get width and height
                int width  = viewInfo.Pages[0].Width;
                int height = viewInfo.Pages[0].Height;

                // Set tile width and height as a half of image total width
                int tileWidth  = width / 2;
                int tileHeight = height / 2;

                int pointX = 0;
                int pointY = 0;

                //Create image options and add four tiles, one for each quarter
                PngViewOptions options = new PngViewOptions(pageFilePathFormat);

                Tile tile = new Tile(pointX, pointY, tileWidth, tileHeight);
                options.CadOptions.Tiles.Add(tile);

                pointX += tileWidth;
                tile    = new Tile(pointX, pointY, tileWidth, tileHeight);
                options.CadOptions.Tiles.Add(tile);

                pointX  = 0;
                pointY += tileHeight;
                tile    = new Tile(pointX, pointY, tileWidth, tileHeight);
                options.CadOptions.Tiles.Add(tile);

                pointX += tileWidth;
                tile    = new Tile(pointX, pointY, tileWidth, tileHeight);
                options.CadOptions.Tiles.Add(tile);

                viewer.View(options);
            }

            Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
        }
        public IActionResult OnPost(string FileName)
        {
            int    pageCount        = 0;
            string imageFilesFolder = Path.Combine(outputPath, Path.GetFileName(FileName).Replace(".", "_"));

            if (!Directory.Exists(imageFilesFolder))
            {
                Directory.CreateDirectory(imageFilesFolder);
            }
            string imageFilesPath = Path.Combine(imageFilesFolder, "page-{0}.png");

            using (Viewer viewer = new Viewer(Path.Combine(storagePath, FileName)))
            {
                ViewInfo info = viewer.GetViewInfo(ViewInfoOptions.ForPngView(false));
                pageCount = info.Pages.Count;

                PngViewOptions options = new PngViewOptions(imageFilesPath);
                viewer.View(options);
            }
            return(new JsonResult(pageCount));
        }