Esempio n. 1
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);
            }
        }
Esempio n. 2
0
 public PngViewer(string filePath, IViewerCache cache, LoadOptions loadOptions, int pageNumber = -1, int newAngle = 0)
 {
     this.cache           = cache;
     this.filePath        = filePath;
     this.viewer          = new GroupDocs.Viewer.Viewer(filePath, loadOptions);
     this.pngViewOptions  = this.CreatePngViewOptions(pageNumber, newAngle);
     this.viewInfoOptions = ViewInfoOptions.FromPngViewOptions(this.pngViewOptions);
 }
Esempio n. 3
0
        public String PrintableHtml(string file, string folderName)
        {
            string outPath = AppSettings.WorkingDirectory + folderName + "/" + file;

            //GroupDocs.Apps.API.Models.License.SetGroupDocsViewerLicense();
            HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources("page_{0}.html");

            options.Minify = true;

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

            return("".Replace(".doc-page { position: absolute; }", ".doc-page { position: relative; }"));
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Open file button click event.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void openFileBtn_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "c:\\";

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    CurrentFilePath     = openFileDialog.FileName;
                    openFileBtn.Enabled = false;
                }
            }

            // If file set - process it.
            if (!string.IsNullOrEmpty(CurrentFilePath))
            {
                if (Viewer != null)
                {
                    Viewer.Dispose();
                    ViewInfo    = null;
                    CurrentPage = 1;
                    DisplayViewInfo();
                }

                new Thread(() =>
                {
                    try
                    {
                        SetPagesInfoText($"Loading {Path.GetFileName(CurrentFilePath)}");

                        Viewer = new GroupDocs.Viewer.Viewer(CurrentFilePath);
                        GroupDocs.Viewer.Options.ViewInfoOptions viewInfo = GroupDocs.Viewer.Options.ViewInfoOptions.ForHtmlView();

                        try
                        {
                            ViewInfo = Viewer.GetViewInfo(viewInfo);
                        }
                        catch (PasswordRequiredException)
                        {
                            // Ask for password
                            EnterPasswordBox enterPasswordbox = new EnterPasswordBox();
                            DialogResult res = enterPasswordbox.ShowDialog();

                            if (res == DialogResult.OK)
                            {
                                Viewer.Dispose();
                                ViewInfo = null;

                                LoadOptions loadOptions = new LoadOptions();
                                loadOptions.Password    = enterPasswordbox.ResultValue;

                                Viewer   = new GroupDocs.Viewer.Viewer(CurrentFilePath, loadOptions);
                                ViewInfo = Viewer.GetViewInfo(viewInfo);
                            }
                            else
                            {
                                ViewInfo                   = null;
                                CurrentFilePath            = null;
                                webBrowerMain.DocumentText = string.Empty;
                                DisplayViewInfo();

                                throw;
                            }
                        }

                        ViewFile(Viewer);
                        openFileBtn.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Error occured! {ex.Message}");
                        ViewInfo = null;
                        DisplayViewInfo();
                        openFileBtn.Enabled = true;
                    }
                }).Start();
            }
        }