Пример #1
0
        public ActionResult GetDocumentThumbnail(int id)
        {
            string doctype   = "image/jpg";
            var    imageData = DMLObj.GetDocDataById(id, out doctype);

            if (doctype.ToLower() == "application/pdf")
            {
                Spire.Pdf.PdfDocument document = new Spire.Pdf.PdfDocument();
                document.LoadFromStream(new MemoryStream(imageData));
                Image ImgDoc = document.SaveAsImage(0, Spire.Pdf.Graphics.PdfImageType.Bitmap, 120, 120);
                return(File(imageToByteArray(ImgDoc.ScaleImage(150, 150)), "image/jpeg"));
            }

            //if (doctype.ToLower() == "application/msword")
            //{
            //    Spire.Doc.Document document = new Spire.Doc.Document();
            //    document.LoadFromStream(new MemoryStream(imageData),Spire.Doc.FileFormat.Doc);
            //    Image ImgDoc = document.SaveToImages(0, Spire.Doc.Documents.ImageType.Metafile);
            //    return File(imageToByteArray(ImgDoc.ScaleImage(150, 150)), "image/jpeg");
            //}

            //if (doctype.ToLower() == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
            //{
            //    Spire.Doc.Document document = new Spire.Doc.Document();
            //    document.LoadFromStream(new MemoryStream(imageData), Spire.Doc.FileFormat.Docx2010);
            //    Image ImgDoc = document.SaveToImages(0, Spire.Doc.Documents.ImageType.Metafile);
            //    return File(imageToByteArray(ImgDoc.ScaleImage(150, 150)), "image/jpeg");
            //}
            return(File(imageData, doctype));
        }
Пример #2
0
        public ActionResult GetDocument(string DocId, string PageNumber)
        {
            int AmDocId = 0;
            int AmPn    = 0;

            Int32.TryParse(DocId, out AmDocId);
            Int32.TryParse(PageNumber, out AmPn);
            string doctype   = "image/jpg";
            var    imageData = DMLObj.GetDocDataById(AmDocId, out doctype);

            if (imageData == null)
            {
                return(null);
            }
            if (doctype.ToLower() == "application/pdf")
            {
                Spire.Pdf.PdfDocument document = new Spire.Pdf.PdfDocument();
                document.LoadFromStream(new MemoryStream(imageData));
                Image ImgDoc = document.SaveAsImage(AmPn, Spire.Pdf.Graphics.PdfImageType.Bitmap, 400, 400);
                ImgDoc = ImgDoc.cropImage(new Rectangle(0, 57, ImgDoc.Width, ImgDoc.Height - 57));
                return(File(imageToByteArray(ImgDoc), "image/jpeg"));
            }
            return(File(imageData, doctype));
        }