public static bool BuildPreview(string temporaryDirectory, string sourceFile, string mimetype, int width, int height, out string previewMimetype, out string previewPath, out string error)
        {
            IPreview preview = null;
            bool     success = false;

            previewMimetype = null;
            previewPath     = null;
            error           = null;

            if (mimetype.StartsWith("image/", System.StringComparison.InvariantCulture) ||
                mimetype.StartsWith("video/", System.StringComparison.InvariantCulture) ||
                mimetype.StartsWith("audio/", System.StringComparison.InvariantCulture))
            {
                preview = new ImageVideoPreview(temporaryDirectory);
            }
            else if (mimetype == "application/pdf")
            {
                preview = new PdfPreview(temporaryDirectory);
            }
            else if (mimetype == "text/uri-list")
            {
                preview = new UrlPreview(temporaryDirectory);
            }
            //else if (mimetype == "application/x-laclasse-pad")
            //    preview = new HtmlPreview(temporaryDirectory);

            if (preview != null)
            {
                previewPath = preview.Process(sourceFile, mimetype, width, height, out PreviewFormat format, out error);
                if (previewPath != null)
                {
                    if (format == PreviewFormat.PNG)
                    {
                        previewMimetype = "image/png";
                    }
                    else
                    {
                        previewMimetype = "image/jpeg";
                    }
                    success = true;
                }
                else
                {
                    success = false;
                }
            }
            return(success);
        }
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                PdfPreview.OpenFile(previewPath);

                System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
                dispatcherTimer.Tick    += dispatcherTimer_Tick;
                TextEntry.TextChanged   += dispatcherTimer_Tick;
                dispatcherTimer.Interval = new TimeSpan(0, 0, 120);
                dispatcherTimer.Start();
            }
            catch
            {
            }
        }
Beispiel #3
0
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            try
            {
                if (ddlSection.SelectedIndex != -1)
                {
                    DulyDBDataContext dc = new DulyDBDataContext();

                    //get the extension
                    string extension = System.IO.Path.GetExtension(FileUpload1.FileName);

                    //generate RandomName
                    string random      = randomName();
                    string newFileName = random + extension;

                    FileUpload1.SaveAs(HttpContext.Current.Server.MapPath("~") + "/Uploads/" +
                                       newFileName);


                    //THIS IS WHERE THE PREVIEW IMG IS CREATED
                    //open the document
                    PdfManager  objPdf = new PdfManager();
                    PdfDocument objDoc = objPdf.OpenDocument(HttpContext.Current.Server.MapPath("~") + "/Uploads/" + newFileName);

                    //get the first page
                    PdfPage firstPage = objDoc.Pages[1];

                    //convert to img
                    PdfPreview objPreview = firstPage.ToImage("ResolutionX=100; ResolutionY=100");

                    //save
                    objPreview.Save(HttpContext.Current.Server.MapPath("~") + "/Preview/" + random + ".png", true);
                    //END OF PREVIEW


                    //test link
                    hyperlink.NavigateUrl = "http://dulynoted-001-site1.smarterasp.net/Uploads/" + newFileName;
                    hyperlink.Visible     = true;

                    var newNote = new Note
                    {
                        sId                = int.Parse(ddlSection.SelectedValue),
                        userId             = int.Parse(Session["dulyNoted"].ToString()),
                        numberTimesFlagged = 0,
                        upVoteCounter      = 0,
                        downVoteCounter    = 0,
                        source             = "http://dulynoted-001-site1.smarterasp.net/Uploads/" + newFileName,
                        preview            = "http://dulynoted-001-site1.smarterasp.net/Preview/" + random + ".png",
                        title              = NoteTitle.Text,
                        description        = NoteDescription.Text,
                        noteDate           = Calendar_NoteDate.SelectedDate,
                        uploadDate         = DateTime.Now
                    };
                    dc.Notes.InsertOnSubmit(newNote);
                    dc.SubmitChanges();

                    //AFTER THE FILE IS UPLOADED HERE

                    NoteTitle.Text       = "";
                    NoteDescription.Text = "";
                }
                else
                {
                    UploadLabel1.Text = "You must select a section.";
                }
            }
            catch (Exception ex)
            {
                UploadLabel1.Text = "ERROR: " + ex.Message.ToString();
            }
        }
        else
        {
            UploadLabel1.Text = "You have not specified a file.";
        }
    }
 private void dispatcherTimer_Tick(object sender, EventArgs e)
 {
     // formatting to PDF and save result to file
     MarkdownPdf.Transform(TextEntry.Text, previewPath);
     PdfPreview.OpenFile(previewPath);
 }