Пример #1
0
        private byte[] PutOverlayIcon(byte[] previewContent, string mimeType)
        {
            //decimal ratio = 640.0M / (decimal)img.Width;

            //Image zoomed = new Bitmap((int)(ratio * img.Width), (int)(ratio * img.Height));
            //using (Graphics g = Graphics.FromImage(zoomed))
            //{
            //    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            //    g.DrawImage(img, new Rectangle(Point.Empty, zoomed.Size), new Rectangle(Point.Empty, img.Size), GraphicsUnit.Pixel);
            //}
            using (MemoryStream ms = new MemoryStream(previewContent))
            {
                Image overlayed    = Image.FromStream(ms);
                bool  isHorizontal = overlayed.Width > overlayed.Height;

                string overlayPath = "~/Content/images/";


                ScanTypeInfo sti = ScansHelper.GetTypeInfo(mimeType);

                if (sti.IsPdfDocument)
                {
                    overlayPath = string.Format("{0}{1}_{2}.png", overlayPath, "pdf", isHorizontal ? "h" : "v");
                }
                else if (sti.IsImage)
                {
                    overlayPath = string.Format("{0}{1}_{2}.png", overlayPath, "img", isHorizontal ? "h" : "v");
                }
                else if (sti.IsWordDocument)
                {
                    overlayPath = string.Format("{0}{1}_{2}.png", overlayPath, "doc", isHorizontal ? "h" : "v");
                }
                else
                {
                    overlayPath = string.Format("{0}{1}_{2}.png", overlayPath, "inne", isHorizontal ? "h" : "v");
                }

                Image overlay = Image.FromFile(Server.MapPath(overlayPath));

                using (Graphics g = Graphics.FromImage(overlayed))
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.DrawImage(overlay, new Rectangle(0, 0, overlayed.Width, overlayed.Height));
                }
                using (MemoryStream mso = new MemoryStream())
                {
                    overlayed.Save(mso, ImageFormat.Png);
                    return(mso.ToArray());
                }
            }
        }
Пример #2
0
        public ActionResult UploadScan()
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i];
                if (file != null)
                {
                    ScanBrowser browser = ScanBrowserFactory.Create();
                    byte[]      content = new byte[file.ContentLength];
                    file.InputStream.Read(content, 0, file.ContentLength);
                    ScanInfo info = browser.GetScanFromFile(content, file.FileName);

                    Guid scanId = ScansHelper.AddScan(info);
                }
            }
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult UploadScan(Guid documentID, HttpPostedFileBase file)
        {
            if (file != null)
            {
                ScanBrowser browser = ScanBrowserFactory.Create();
                byte[]      content = new byte[file.ContentLength];
                file.InputStream.Read(content, 0, file.ContentLength);
                ScanInfo info = browser.GetScanFromFile(content, file.FileName);

                Guid scanId = ScansHelper.AddScan(info);

                _repository.SetDocumentScan(scanId, documentID);
                _repository.SubmitChanges();
            }

            return(RedirectToAction("Edit", new { documentID = documentID }));// (result);
        }
Пример #4
0
        public ActionResult SplitFile(Guid?scanGuid)
        {
            if (scanGuid.HasValue)
            {
                ScanBrowser     browser        = ScanBrowserFactory.Create();
                ScansRepository scanRepository = new ScansRepository();
                Scan            scan           = scanRepository.GetScan(scanGuid.Value);

                byte[]   fileContent = scan.ScanContent.ToArray();
                string[] fileName    = scan.FileName.Split('.');
                string   mimeType    = scan.MimeType;

                MemoryStream stream = new MemoryStream();
                stream.Write(fileContent, 0, fileContent.Length);


                LicensingManager.LicenseKey = "lL+mtKWhtKOnrbSjuqS0p6W6paa6ra2trQ==";

                Winnovative.PdfCreator.Document sourcedoc = new Winnovative.PdfCreator.Document(stream);
                stream.Close();

                using (TransactionScope transaction = new TransactionScope())
                {
                    if (sourcedoc != null && sourcedoc.Pages.Count > 1)
                    {
                        for (int i = 0; i < sourcedoc.Pages.Count; i++)
                        {
                            Winnovative.PdfCreator.Document newdoc = SplitPdf.ExtractPages(sourcedoc, i, 1);

                            string   newFileName = string.Join(string.Format("_{0}.", (i + 1)), fileName);
                            ScanInfo newscan     = browser.GetScanFromFile(newdoc.Save(), newFileName);
                            ScansHelper.AddScan(newscan);
                        }

                        scanRepository.DeleteScanFromRecycleBin(scan.ScanID);
                    }

                    transaction.Complete();
                }
            }


            return(RedirectToAction("Index"));
        }
Пример #5
0
        //QUOTA [Quota(QuotaType = QuotaTypes.ScansTotalSize)]
        public ActionResult FlashUpload(string token, HttpPostedFileBase FileData)
        {
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token);

            if (ticket != null)
            {
                var identity = new FormsIdentity(ticket);
                if (identity.IsAuthenticated)
                {
                    HttpPostedFileBase file = FileData;
                    if (file != null)
                    {
                        ScanBrowser browser = ScanBrowserFactory.Create();
                        byte[]      content = new byte[file.ContentLength];
                        file.InputStream.Read(content, 0, file.ContentLength);
                        ScanInfo info = browser.GetScanFromFile(content, file.FileName);

                        Guid scanId = ScansHelper.AddScan(info);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Пример #6
0
 public bool HasVersions(Guid scanId)
 {
     return(ScansHelper.HasVersions(scanId));
 }
Пример #7
0
        public ActionResult SaveRotated(Guid scanGuid, int?rotation)
        {
            if (rotation.HasValue && rotation % 4 == 0)
            {
                return(new EmptyResult());
            }
            var sp = Context.Scans.Where(s => s.ScanID == scanGuid).FirstOrDefault();

            if (sp == null)
            {
                return(new EmptyResult());
            }

            ScanTypeInfo si = ScansHelper.GetTypeInfo(sp.MimeType);

            if (!(si.IsImage || si.IsPdfDocument))
            {
                return(new EmptyResult());
            }

            int            rotationType = rotation.Value % 4;
            RotateFlipType rft          = RotateFlipType.RotateNoneFlipNone;

            switch (rotationType)
            {
            case 0:
                rft = RotateFlipType.RotateNoneFlipNone;
                break;

            case 1:
                rft = RotateFlipType.Rotate90FlipNone;
                break;

            case 2:
                rft = RotateFlipType.Rotate180FlipNone;
                break;

            case 3:
                rft = RotateFlipType.Rotate270FlipNone;
                break;
            }


            using (MemoryStream ms = new MemoryStream(sp.ScanZoom.ToArray()))
            {
                Image img = Image.FromStream(ms);
                img.RotateFlip(rft);
                using (MemoryStream oms = new MemoryStream())
                {
                    img.Save(oms, si.Format);
                    sp.ScanZoom = oms.ToArray();
                }
            }

            var scanPreview = sp.ScanPreviews.FirstOrDefault();

            if (scanPreview != null)
            {
                using (MemoryStream ms = new MemoryStream(scanPreview.ScanPreviewContent.ToArray()))
                {
                    Image img = Image.FromStream(ms);
                    img.RotateFlip(rft);
                    using (MemoryStream oms = new MemoryStream())
                    {
                        img.Save(oms, ImageFormat.Png);
                        scanPreview.ScanPreviewContent = oms.ToArray();
                    }
                }
            }
            Context.SubmitChanges();
            return(new EmptyResult());
        }
Пример #8
0
        public ActionResult GetScansFromFolder()
        {
            ScansHelper.GetScansFromFolder();

            return(Json(true, "text/plain", JsonRequestBehavior.AllowGet));
        }
Пример #9
0
        public ActionResult GetScans()
        {
            ScansHelper.GetScansFromFolder();

            return(RedirectToAction("Index"));
        }
Пример #10
0
        public ActionResult GetScans(Guid documentID)
        {
            ScansHelper.GetScansFromFolder();

            return(RedirectToAction("Edit", "Documents", new { documentID = documentID, d = 1 }));
        }