Exemple #1
0
 public PdfViewerPage()
 {
     this.InitializeComponent();
     this.NavigationCacheMode = NavigationCacheMode.Enabled;
     ViewerPageViewModel      = new PdfViewerViewModel();
     PdfViewerViewType        = PdfViewerViewType.Normal;
 }
Exemple #2
0
        public PdfViewerControl(StorageFile file, PdfFileModel pdfFile, bool isMain)
        {
            this.InitializeComponent();

            ViewerPageViewModel = new PdfViewerViewModel();
            PdfViewerViewType   = PdfViewerViewType.Normal;

            File          = file;
            PdfFile       = pdfFile;
            IsMainPdfFile = isMain;
        }
Exemple #3
0
        // GET: /<controller>/
        public IActionResult Index(string readOnlyPath, string downloadPath)
        {
            var pdfPaths = new PdfViewerViewModel
            {
                ReadOnlyPath = _hostingEnv.WebRootPath + readOnlyPath.Replace(@"\\", @"\"),
                DownloadPath = downloadPath
            };

            // var fullPath = _hostingEnv.WebRootPath + fileName;

            // fullPath = WebUtility.UrlEncode(fullPath);
            return(View(pdfPaths));
        }
Exemple #4
0
        public async Task <IActionResult> SetPdfExpiration(int id)
        {
            var      invalidChars = Path.GetInvalidFileNameChars();
            Document doc          = await _unitOfWork.Documents.GetDocumentByIdAsync(id);

            var expDate = DateTime.Now.AddDays(2);

            doc.ExpiryDate = expDate;
            PdfJavaScriptAction scriptAction = BuildExpireJSFunc(doc);
            string saveAs = await GetFullPath(doc.FolderId, doc.DocumentName + "." + doc.MimeType);

            //this key is what the new pdf with the expiration function attached to it will be renamed with
            var expKey = SystemConstants.ExpiryKey;

            //03.23.2020 network path
            string userPath = _networkDocPath + _userSession.FirstName + _userSession.LastName + _userSession.Id + "\\";

            //string userPath = _hostingEnv.WebRootPath + "\\UploadFiles\\" + _userSession.FirstName + _userSession.LastName + _userSession.Id + "\\";


            if (!Directory.Exists(userPath))
            {
                Directory.CreateDirectory(userPath);
            }
            else
            {
                DeleteOldDirectoryFiles(userPath);
            }
            string expPath = "";

            try
            {
                //03.23.2020 network path _hostingEnv.WebRootPath + "\\"
                using (FileStream fs = new FileStream(doc.Path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    if (doc.MimeType == "pdf")
                    {
                        PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fs);

                        PdfDocument document = new PdfDocument();
                        PdfDocument.Merge(document, loadedDocument);
                        string validFileName = new string(doc.DocumentName
                                                          .Where(x => !invalidChars.Contains(x))
                                                          .ToArray());

                        if (doc.DocId > 0)
                        {
                            document.Actions.AfterOpen = scriptAction;
                        }

                        doc.Path = await GetRelativePath(doc.FolderId, validFileName + "." + doc.MimeType);

                        expPath = userPath + validFileName + "." + doc.MimeType;

                        if (System.IO.File.Exists(expPath))
                        {
                            System.IO.File.Delete(expPath);
                        }
                        //  FileStream outputStream = new FileStream(expPath, FileMode.CreateNew);
                        using (FileStream outputStream = new FileStream(expPath, FileMode.CreateNew))
                        {
                            document.Save(outputStream);
                            document.Close(true);
                            loadedDocument.Close(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            var pdfPaths = new PdfViewerViewModel
            {
                ReadOnlyPath = doc.Path,
                DownloadPath = expPath
            };
            var        userAgent = Request.Headers["User-Agent"];
            string     uaString  = Convert.ToString(userAgent[0]);
            var        uaParser  = Parser.GetDefault();
            ClientInfo c         = uaParser.Parse(uaString);
            //if (c.UserAgent.Family == "IE")
            //{
            //    return RedirectToAction("Download", "Documents", new { docPath = pdfPaths.DownloadPath, ieDownload = true });
            //}
            //else
            //{
            //    return RedirectToAction("Index", "PdfViewer", pdfPaths);
            //}

            var stream = new FileStream(pdfPaths.ReadOnlyPath, FileMode.Open);


            ////return File(stream, "application/pdf","test.pdf");

            //return new FileStreamResult(stream, "application/pdf");

            //ProcessStartInfo info = new ProcessStartInfo();
            //info.Verb = "Open";
            //info.FileName = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
            ////info.FileName = @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
            ////info.Arguments = String.Format(@"/p /h {0}", pdfPaths.DownloadPath);
            //info.CreateNoWindow = false;
            //info.WindowStyle = ProcessWindowStyle.Hidden;
            //info.UseShellExecute = true;

            //info.Arguments = String.Format(pdfPaths.DownloadPath);
            //Process p = Process.Start(info);
            //pdfPaths.DownloadPath = @"D:\test.pdf";

            //return RedirectToAction("Index", "PdfViewer", pdfPaths);
            return(new FileStreamResult(stream, "application/pdf"));
        }
 public PdfViewerPage()
 {
     InitializeComponent();
     BindingContext = new PdfViewerViewModel();
 }