test

 


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="robots" content="noindex, nofollow">

  <title>Sidebar navigation with Scrollspy - Bootsnipp.com</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
  <style type="text/css">
    #wrapper {
      padding-left: 250px;
      transition: all 0.4s ease 0s;
    }

    #sidebar-wrapper {
      margin-left: -250px;
      left: 250px;
      width: 250px;
      background: #000;
      position: fixed;
      height: 100%;
      overflow-y: auto;
      z-index: 1000;
      transition: all 0.4s ease 0s;
    }

    #wrapper.active {
      padding-left: 0;
    }

      #wrapper.active #sidebar-wrapper {
        left: 0;
      }

    #page-content-wrapper {
      width: 100%;
    }



    .sidebar-nav {
      position: absolute;
      top: 0;
      width: 250px;
      list-style: none;
      margin: 0;
      padding: 0;
    }

      .sidebar-nav li {
        line-height: 40px;
        text-indent: 20px;
      }

        .sidebar-nav li a {
          color: #999999;
          display: block;
          text-decoration: none;
          padding-left: 60px;
        }

          .sidebar-nav li a span:before {
            position: absolute;
            left: 0;
            color: #41484c;
            text-align: center;
            width: 20px;
            line-height: 18px;
          }

          .sidebar-nav li a:hover,
          .sidebar-nav li.active {
            color: #fff;
            background: rgba(255,255,255,0.2);
            text-decoration: none;
          }

          .sidebar-nav li a:active,
          .sidebar-nav li a:focus {
            text-decoration: none;
          }

      .sidebar-nav > .sidebar-brand {
        height: 65px;
        line-height: 60px;
        font-size: 18px;
      }

        .sidebar-nav > .sidebar-brand a {
          color: #999999;
        }

          .sidebar-nav > .sidebar-brand a:hover {
            color: #fff;
            background: none;
          }



    .content-header {
      height: 65px;
      line-height: 65px;
    }

      .content-header h1 {
        margin: 0;
        margin-left: 20px;
        line-height: 65px;
        display: inline-block;
      }

    #menu-toggle {
      text-decoration: none;
    }

    .btn-menu {
      color: #000;
    }

    .inset {
      padding: 20px;
    }

    @media (max-width:992px) {

      #wrapper {
        padding-left: 0;
      }

      #sidebar-wrapper {
        left: 0;
      }

      #wrapper.active {
        position: relative;
        left: 250px;
      }

        #wrapper.active #sidebar-wrapper {
          left: 250px;
          width: 250px;
          transition: all 0.4s ease 0s;
        }

      #menu-toggle {
        display: inline-block;
      }

      .inset {
        padding: 15px;
      }
    }

    .carousel-caption {
      position: relative;
      left: 0%;
      right: 0%;
      bottom: 0px;
      z-index: 10;
      padding-top: 0px;
      padding-bottom: 0px;
      color: #000;
      text-shadow: none;
    }

    .carousel {
      position: relative;
    }

    .controllers {
      position: absolute;
      top: 0px;
    }

    .carousel-control.left,
    .carousel-control.right {
      background-image: none;
    }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
  <script type="text/javascript">
    window.alert = function () { };
    var defaultCSS = document.getElementById('bootstrap-css');
    function changeCSS(css) {
      if (css) $('head > link').filter(':first').replaceWith('<link rel="stylesheet" href="' + css + '" type="text/css" />');
      else $('head > link').filter(':first').replaceWith(defaultCSS);
    }
    $(document).ready(function () {
      var iframe_height = parseInt($('html').height());
      window.parent.postMessage(iframe_height, 'https://bootsnipp.com');
    });
  </script>
</head>
<body>
  <div id="wrapper">

    <!-- Sidebar -->
    <div id="sidebar-wrapper">
      <nav id="spy">
        <ul class="sidebar-nav nav">
          <li class="sidebar-brand">
            <a href="#home"><span class="fa fa-home solo">Home</span></a>
          </li>
          <li>
            <a href="#anch1" data-scroll>
              <span class="fa fa-anchor solo">Anchor 1</span>
            </a>
          </li>
          <li>
            <a href="#anch2" data-scroll>
              <span class="fa fa-anchor solo">Anchor 2</span>
            </a>
          </li>
          <li>
            <a href="#anch3" data-scroll>
              <span class="fa fa-anchor solo">Anchor 3</span>
            </a>
          </li>
          <li>
            <a href="#anch4" data-scroll>
              <span class="fa fa-anchor solo">Anchor 4</span>
            </a>
          </li>
        </ul>
      </nav>
    </div>

    <!-- Page content -->
    <div id="page-content-wrapper">
      <div class="content-header">
        <h1 id="home">
          <a id="menu-toggle" href="#" class="glyphicon glyphicon-align-justify btn-menu toggle">
            <i class="fa fa-bars"></i>
          </a>
          Sidebar Navigation Template
        </h1>
      </div>

      <div class="page-content inset" data-spy="scroll" data-target="#spy">
        <div class="row">

          <div class="jumbotron text-center">
            <h1>Hello Beautiful!</h1>
            <p>This is a sidebar navigation responsive template built off of Bootstrap 3.0 and simple sidebar template. It includes anchors, scroll spy, smooth scroll, and Awesome icon fonts.</p>
            <p>
              <a class="btn btn-default">Click On Me!</a>
              <a class="btn btn-info">Tweet Me!</a>
            </p>
          </div>

        </div>
        <div class="row">
          <div class="col-md-12 well">
            <legend id="anch1">Anchor 1</legend>

            <!-- Wrapper for slides -->
            <div class="carousel-inner">
              <div class="item active">
                <div class="holder col-sm-8">
                  <img class="img-responsive" src="http://placehold.it/1000x400" alt="...">
                </div>
                <div class="col-sm-4">
                  <div class="carousel-caption">
                    <h2>Slide 1</h2>
                    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.</p>

                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="col-md-12 well">
            <legend id="anch2">Anchor 2</legend>
            <!-- Wrapper for slides -->
            <div class="carousel-inner">
              <div class="item active">
                <div class="holder col-sm-8">
                  <img class="img-responsive" src="http://placehold.it/1000x400" alt="...">
                </div>
                <div class="col-sm-4">
                  <div class="carousel-caption">
                    <h2>Slide 1</h2>
                    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.</p>

                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="col-md-12 well">
            <legend id="anch3">Anchor 3</legend>
            <!-- Wrapper for slides -->
            <div class="carousel-inner">
              <div class="item active">
                <div class="holder col-sm-8">
                  <img class="img-responsive" src="http://placehold.it/1000x400" alt="...">
                </div>
                <div class="col-sm-4">
                  <div class="carousel-caption">
                    <h2>Slide 1</h2>
                    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.</p>

                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="col-md-12 well">
            <legend id="anch4">Anchor 4</legend>
            <!-- Wrapper for slides -->
            <div class="carousel-inner">
              <div class="item active">
                <div class="holder col-sm-8">
                  <img class="img-responsive" src="http://placehold.it/1000x400" alt="...">
                </div>
                <div class="col-sm-4">
                  <div class="carousel-caption">
                    <h2>Slide 1</h2>
                    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.</p>

                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>



      </div>

    </div>
    <script type="text/javascript">

      /*Menu-toggle*/
      $("#menu-toggle").click(function (e) {
        e.preventDefault();
        $("#wrapper").toggleClass("active");
      });

      /*Scroll Spy*/
      $('body').scrollspy({ target: '#spy', offset: 80 });

      /*Smooth link animation*/
      $('a[href*=#]:not([href=#])').click(function () {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) {

          var target = $(this.hash);
          target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
          if (target.length) {
            $('html,body').animate({
              scrollTop: target.offset().top
            }, 1000);
            return false;
          }
        }
      });
    </script>
</body>
</html>

 

namespace GenerateThumbnails.Conversion
{
    public interface ITypeConversion
    {
        bool WordToPdf(string _sourcePath, out string _targetTempPath);

        bool ExcelToPdf(string _sourcePath, out string _outputTempFilePath);
    }
}

 

 

using System;
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
using System.IO;
using System.Net;

namespace GenerateThumbnails.Conversion
{
    public class TypeConversion 
    {
        private string _tempLocation = Path.GetPathRoot(Environment.SystemDirectory) + "WBTemp";

        Word.Application wordApp = null;
        Word.Documents wdDocuments = null;
        Word.Document wdDocument = null;

        Excel.Application excelApp = null;
        Excel.Workbooks xlBooks = null;
        Excel.Workbook xlBook = null;

        public bool WordToPdf(string _sourcePath, out string _outputTempFilePath)
        {
            wordApp = new Word.Application();
            wdDocuments = wordApp.Documents;

            try
            {
                //Read word document file
                wdDocument = wdDocuments.Open(_sourcePath);

                _outputTempFilePath = string.Empty;

                if (wdDocument != null)
                {
                    _outputTempFilePath = GetTempTargetFilePath(_tempLocation);

                    //Export word document file to pdf format
                    wdDocument.ExportAsFixedFormat(_outputTempFilePath, Word.WdExportFormat.wdExportFormatPDF);                  

                    return true;
                }
            }
            catch (Exception ex)
            {
                _outputTempFilePath = string.Empty;

                return false;
            }
            finally
            {
                // Cleanup
                GC.Collect();
                GC.WaitForPendingFinalizers();

                wdDocument.Close(false);
                NAR(wdDocument);
                NAR(wdDocuments);
                wordApp.Quit();
                NAR(wordApp);
            }

            return false;
        }

        public bool ExcelToPdf(string _sourcePath, out string _outputTempFilePath)
        {
            excelApp = new Excel.Application();

            try
            {
                //Read word document file
                xlBooks = excelApp.Workbooks;
                xlBook = xlBooks.Open(_sourcePath);

                _outputTempFilePath = string.Empty;

                if (xlBook != null)
                {
                    _outputTempFilePath = GetTempTargetFilePath(_tempLocation);

                    //Export word document file to pdf format
                    xlBook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, _outputTempFilePath);

                    return true;
                }
            }
            catch (Exception ex)
            {
                _outputTempFilePath = string.Empty;

                return false;
            }
            finally
            {
                // Cleanup
                GC.Collect();
                GC.WaitForPendingFinalizers();

                xlBook.Close(false);
                NAR(xlBook);
                NAR(xlBooks);
                excelApp.Quit();
                NAR(excelApp);                
            }

            return false;
        }

        public bool PdfURLToPdf(string _sourcePath, out string _outputTempFilePath)
        {
            using(var client = new WebClient())
            {
                _outputTempFilePath = GetTempTargetFilePath(_tempLocation);
                client.DownloadFile(_sourcePath, _outputTempFilePath);
                return true;
            }
        }

        private void NAR(object o)
        {
            try
            {
                while (System.Runtime.InteropServices.Marshal.ReleaseComObject(o) > 0) ;
            }
            catch { }
            finally
            {
                o = null;
            }
        }

        public static string GetTempTargetFilePath(string _targetTempPath)
        {
            string _tempFilePath = string.Empty;

            //Check temp directory exists or not
            if (!Directory.Exists(_targetTempPath))
            {
                //Create new temp directory 
                Directory.CreateDirectory(_targetTempPath);
            }

            var _fileName = "temp.pdf";
            _tempFilePath = _targetTempPath + "/" + _fileName;

            if (File.Exists(_tempFilePath))
            {
                File.Delete(_tempFilePath);
            }
            return _tempFilePath;
        }
    }
}

 

 

using Microsoft.WindowsAPICodePack.Shell;
using System;
using System.IO;
using System.Drawing;

namespace GenerateThumbnails.Conversion
{
    public class Thumbnails
    {       

        public Bitmap GetThumbnail(string _sourcePath)
        {
            const int bmpW = 150;
            const int bmpH = 180;
            Bitmap upBmp = null;

            if (!string.IsNullOrEmpty(_sourcePath))
            {
                if (Path.GetExtension(_sourcePath).ToLower() == ".pdf")
                {
                    ShellFile shellFile = ShellFile.FromFilePath(_sourcePath);
                    upBmp = shellFile.Thumbnail.ExtraLargeBitmap;
                }
            }

            if (upBmp != null)
            {
                Int32 newWidth = bmpW;
                Int32 newHeight = bmpH;

                Bitmap newBmp = new Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                newBmp.SetResolution(72, 72);
                Double upWidth = upBmp.Width;
                Double upHeight = upBmp.Height;

                int newX = 0;
                int newY = 0;
                Double reDuce;
                if (upWidth > upHeight)
                {
                    reDuce = newWidth / upWidth;
                    newHeight = ((Int32)(upHeight * reDuce));
                    newY = ((Int32)((bmpH - newHeight) / 2));
                    newX = 0;
                }
                else if (upWidth < upHeight)
                {
                    reDuce = newHeight / upHeight;
                    newWidth = ((Int32)(upWidth * reDuce));
                    newX = ((Int32)((bmpW - newWidth) / 2));
                    newY = 0;
                }
                else if (upWidth == upHeight)
                {
                    reDuce = newHeight / upHeight;
                    newWidth = ((Int32)(upWidth * reDuce));
                    newX = ((Int32)((bmpW - newWidth) / 2));
                    newY = ((Int32)((bmpH - newHeight) / 2));
                }
                Graphics newGraphic = Graphics.FromImage(newBmp);
                try
                {
                    newGraphic.Clear(Color.White);
                    newGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    newGraphic.DrawImage(upBmp, newX, newY, newWidth, newHeight);
                    return newBmp;
                }
                catch (Exception ex)
                {
                    string newError = ex.Message;
                    // lblError.Text = newError;
                }
                finally
                {
                    upBmp.Dispose();
                   // newBmp.Dispose();
                    newGraphic.Dispose();
                }

              
            }

            return upBmp;
        }

        public void SavethumbnailToImage(Bitmap _bitmapImage, string _imagePath, string _typeOfImage)
        {
            if (_typeOfImage == "JPEG")
                _bitmapImage.Save(_imagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            else
                _bitmapImage.Save(_imagePath, System.Drawing.Imaging.ImageFormat.Png);
        }
    }
}

 

 

using System;
using System.Web.Mvc;
using System.IO;
using System.Drawing.Imaging;
using GenerateThumbnails.Conversion;

namespace GenerateThumbnails.Controllers
{
    public class HomeController : Controller
    {
        public HomeController() { }
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            return View();
        }


        [HttpPost]
        public ActionResult Index(string fileUrl)
        {
            //var path = "https://ol.baker.edu/webapps/dur-browserCheck-bb_bb60/samples/sample.xlsx?";
            //var path = "https://calibre-ebook.com/downloads/demos/demo.docx";

            if (!string.IsNullOrEmpty(fileUrl))
            {
                var tempPath = string.Empty;

                TypeConversion typeConv = new TypeConversion();
                if (Path.GetExtension(fileUrl).ToLower() == ".doc" || Path.GetExtension(fileUrl).ToLower() == ".docx" || Path.GetExtension(fileUrl).ToLower().Contains(".docx") || Path.GetExtension(fileUrl).ToLower().Contains(".doc"))
                {
                    typeConv.WordToPdf(fileUrl.ToString(), out tempPath);
                }
                else if (Path.GetExtension(fileUrl).ToLower() == ".xlsx" || Path.GetExtension(fileUrl).ToLower().Contains(".xlsx"))
                {
                    typeConv.ExcelToPdf(fileUrl.ToString(), out tempPath);
                }
                else if (Path.GetExtension(fileUrl).ToLower() == ".pdf" || Path.GetExtension(fileUrl).ToLower().Contains(".pdf"))
                {
                    typeConv.PdfURLToPdf(fileUrl.ToString(), out tempPath);
                }
                else
                {
                    return View();
                }

                Thumbnails thumbnail = new Thumbnails();
                var bitmapThumb = thumbnail.GetThumbnail(tempPath);

                if (!string.IsNullOrEmpty(tempPath))
                {
                    if (bitmapThumb != null)
                    {
                        thumbnail.SavethumbnailToImage(bitmapThumb, Path.GetPathRoot(Environment.SystemDirectory) + "WBTemp/" + DateTime.Now.Date.Day.ToString() + DateTime.Now.Date.Month.ToString()+ DateTime.Now.Date.Year+ DateTime.Now.Date.Hour+ DateTime.Now.Date.Minute+ DateTime.Now.Date.Second + ".jpef", "JPEG");
                    }
                    if (System.IO.File.Exists(tempPath))
                    {
                        System.IO.File.Delete(tempPath);
                    }
                }

                MemoryStream ms = new MemoryStream();
                bitmapThumb.Save(ms, ImageFormat.Jpeg);
                byte[] bmpBytes = ms.ToArray();
                string base64String = Convert.ToBase64String(bmpBytes);

                ViewBag.Image = base64String;
                return View();

            }
            return View();
        }

    }
}

 

 



<div class="row">
  @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
  {

      <section id="contact">
        <div class="section-content">
          <h1 class="section-header">Generate <span class="content-header wow fadeIn " data-wow-delay="0.2s" data-wow-duration="2s"> Thumbnail</span></h1>
          <h3>Generate thumbnail using live url of docx, xlsx and pdf file</h3>
        </div>
        <div class="contact-section">
          <div class="container">
            <form>
              <div class="col-md-6 form-line">
                <div class="form-group">
                  <label for="exampleInputUsername">Enter File URL</label>
                  <input type="text" class="form-control" name="fileUrl" width="300" id="" placeholder="Enter URL Here">
                </div>               
                <div class="form-group" style="float:left;">                 
                  <button type="submit" class="btn btn-default submit"><i class="fa fa-paper-plane" aria-hidden="true"></i>  Generate Thumbnail</button>
                  <br />
                  
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label for="description"> Images</label>
                  <br />
                  <span>
                    # Default Thumbnail Width =150 and Height =180
                  </span>
                  <br />
                  @if (ViewBag.Image != null)
                  {
                      <img src="@String.Format("data:image/png;base64,{0}", ViewBag.Image)" />
                  }
                </div>
              </div>
            </form>
          </div>
        </div>
      </section>
  }

</div>