예제 #1
0
        private void btnPdf_Click(object sender, System.EventArgs e)
        {
            if (flexCelImgExport1.Workbook == null)
            {
                MessageBox.Show("There is no open file");
                return;
            }
            if (PdfSaveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (FlexCelPdfExport PdfExport = new FlexCelPdfExport(flexCelImgExport1.Workbook, true))
            {
                if (!DoExportToPdf(PdfExport))
                {
                    return;
                }
            }

            if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            Process.Start(PdfSaveFileDialog.FileName);
        }
예제 #2
0
        private async void CreateButton_Click(object sender, EventArgs e)
        {
            if (!_selectedFiles.Any())
            {
                MessageBox.Show(this, "No files selected. Please add the video files first.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var ffmegFile = new FileInfo("./ffmpeg.exe");

            if (!ffmegFile.Exists)
            {
                MessageBox.Show(this,
                                "Please make sure that ffmpeg.exe is in the working directory of this software. Maybe download again.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            var utils        = new FfmpegUtils(ffmegFile.FullName);
            var tmpDirectory =
                new DirectoryInfo(Path.Combine(Path.GetTempPath(), "VideoToPdf_" + Guid.NewGuid().ToString("N")));

            tmpDirectory.Create();

            StatusProgressBar.Style        = ProgressBarStyle.Marquee;
            StatusLabel.Text               = "Loading...";
            FilesListControlsPanel.Enabled = false;
            CreateButton.Enabled           = false;
            SensitivityTrackBar.Enabled    = false;

            var sensitivity = (SensitivityTrackBar.Value / 10f).ToString(CultureInfo.InvariantCulture);

            try
            {
                var globalCount = 0;
                foreach (var selectedFile in _selectedFiles)
                {
                    var file = new FileInfo(selectedFile);
                    if (!file.Exists)
                    {
                        MessageBox.Show(this, $"The file {file.FullName} was not found.", "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }

                    StatusLabel.Text = $"Reading {file.Name}...";

                    var information = await utils.Execute(
                        $"-i \"{selectedFile}\" -filter:v \"select=\'gt(scene,{sensitivity})\',showinfo\" -f null null.dump");

                    var timestamps = DumpExtractor.GetTimestamps(information).ToList();
                    timestamps.Insert(0, TimeSpan.Zero);

                    for (var i = 0; i < timestamps.Count; i++)
                    {
                        var timestamp = timestamps[i];
                        timestamp = timestamp.Add(TimeSpan.FromSeconds(1));

                        StatusLabel.Text =
                            $"Extracting slides from {file.Name} ({i + 1} of {timestamps.Count})";

                        var arguments =
                            $"-y -ss {timestamp:c} -i \"{file.FullName}\" -vframes 1 \"{Path.Combine(tmpDirectory.FullName, $"slide{globalCount + i:0000}.png")}\"";
                        await utils.Execute(arguments);
                    }

                    globalCount += timestamps.Count;
                }

                if (SelectSlidesCheckBox.Checked)
                {
                    Process.Start(new ProcessStartInfo {
                        FileName = tmpDirectory.FullName, UseShellExecute = true
                    });

                    MessageBox.Show(this,
                                    "Your file explorer just opened with all extracted slides. You may now delete slides (e.g. duplicates) or rename them for reordering (the pdf will be constructed from the slides in this folder, sorted by name ascending). Please click on OK if you are done.",
                                    "Select slides", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                var images = tmpDirectory.GetFiles("*.png", SearchOption.TopDirectoryOnly).OrderBy(x => x.Name);
                if (!images.Any())
                {
                    MessageBox.Show(this, "No slides were found.", "Warning", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return;
                }

                Size imgSize;
                using (var img = Image.FromFile(images.First().FullName))
                {
                    imgSize = img.Size;
                }

                if (PdfSaveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    var path = PdfSaveFileDialog.FileName;
                    using (var writer = new PdfWriter(path))
                    {
                        var pdfDocument = new PdfDocument(writer);

                        var doc = new Document(pdfDocument, new PageSize(imgSize.Width, imgSize.Height));

                        foreach (var imgFile in images)
                        {
                            var imgData = ImageDataFactory.CreatePng(new Uri("file://" + imgFile.FullName));
                            doc.Add(new iText.Layout.Element.Image(imgData));
                        }

                        doc.Close();
                    }

                    Process.Start("explorer.exe", $"/select, \"{path}\"");
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show($"An error occurred:\r\n{exception}", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            finally
            {
                StatusProgressBar.Style        = ProgressBarStyle.Blocks;
                StatusLabel.Text               = "Ready";
                CreateButton.Enabled           = true;
                FilesListControlsPanel.Enabled = true;
                SensitivityTrackBar.Enabled    = true;

                tmpDirectory.Delete(true);
            }
        }