Example #1
0
        /// <summary>
        /// Devuelve una imagen con la marca de agua.
        /// </summary>
        public static Image GetMarcaDeAgua()
        {
            Image  imagen = null;
            string ruta   = App.Global.Configuracion.RutaMarcaAgua;

            if (File.Exists(ruta))
            {
                string x = Path.GetExtension(ruta).ToLower();
                switch (Path.GetExtension(ruta).ToLower())
                {
                case ".jpg":
                    imagen = new Image(ImageDataFactory.CreateJpeg(new Uri(ruta)));
                    break;

                case ".png":
                    imagen = new Image(ImageDataFactory.CreatePng(new Uri(ruta)));
                    break;
                }
            }
            return(imagen);
        }
Example #2
0
        private static Table CreateInterests(IEnumerable <Interest> interests)
        {
            var table = new Table(1);

            table.SetWidth(UnitValue.CreatePercentValue(100));
            table.SetMarginTop(Spacing);

            table.AddHeaderCell(new Cell(1, 1).SetBorder(Border.NO_BORDER).SetBorderBottom(new SolidBorder(1)).Add(new Paragraph("Interesses")).SetFontSize(11));
            table.AddCell(new Cell(1, 2).SetBorder(Border.NO_BORDER).SetHeight(Spacing));

            var list = new List().SetListSymbol(new Image(ImageDataFactory.CreatePng(File.ReadAllBytes("images\\square-png-30.png"))).ScaleToFit(5, 5).SetMargins(1, 1, 1, 1));

            foreach (var interest in interests)
            {
                list.Add(new ListItem(interest.Name)).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA));
            }

            table.AddCell(new Cell(1, 1).Add(list).SetBorder(Border.NO_BORDER));

            return(table);
        }
Example #3
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);
            }
        }
Example #4
0
        public static void GenerateConfirmationOfServicesForm(
            Stream destinationStream,
            byte[] signBytes,
            string contractorRus,
            string contractorEnd,
            double amount,
            DateTime?date = null)
        {
            date ??= DateTime.UtcNow;

            using var sourceStream = H.Resources.Confirmation_of_Services_Form;
            using var document     = new PdfDocument(
                      new PdfReader(sourceStream),
                      new PdfWriter(destinationStream));
            var fontBytes = H.Resources.Times_New_Roman_Cyrillic;
            var font      = PdfFontFactory.CreateFont(fontBytes, "Cp1251", PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED);

            {
                var canvas = new PdfCanvas(document.GetFirstPage());
                canvas
                .BeginText()
                .SetFontAndSize(font, 11)
                .MoveText(100, 659)
                .ShowText($"{date.Value.ToString("dd MMMM yyyy", CultureInfo.GetCultureInfo("ru-RU"))}")
                .MoveText(-30, -100)
                .ShowText(contractorRus)
                .MoveText(316, -222)
                .ShowText($"{amount:N}")
                .MoveText(-317, -140)
                .ShowText(contractorRus)
                .EndText();

                canvas
                .AddImageFittedIntoRectangle(
                    ImageDataFactory.CreatePng(signBytes),
                    new Rectangle(65, 210, 50, 50),
                    true);
            }

            {
                var canvas = new PdfCanvas(document.GetLastPage());
                canvas
                .BeginText()
                .SetFontAndSize(font, 11)
                .MoveText(100, 672)
                .ShowText(date.Value.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture))
                .MoveText(-30, -90)
                .ShowText(contractorEnd)
                .MoveText(270, -177)
                .ShowText(amount.ToString("N", CultureInfo.InvariantCulture))
                .MoveText(-270, -185)
                .ShowText(contractorEnd)
                .EndText();

                canvas
                .AddImageFittedIntoRectangle(
                    ImageDataFactory.CreatePng(signBytes),
                    new Rectangle(65, 245, 50, 50),
                    true);
            }
        }
        // GET: Todos/Delete/5
        public ActionResult GetPDF(int?id)
        {
            Trace.WriteLine("GET /Todos/GetPDF/" + id);
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Todo todo = db.Todoes.Find(id);

            if (todo == null)
            {
                return(HttpNotFound());
            }

            //string filePath = HttpRuntime.AppDomainAppPath + "/PDF/NewEmployeeDetails.pdf";
            //string filePathFilled = HttpRuntime.AppDomainAppPath + "/PDF/NewEmployeeDetailsFilled.pdf";
            string filePath       = MapPath("~/PDF/NewEmployeeDetails.pdf");
            string filePathFilled = MapPath("~/PDF/NewEmployeeDetailsFilled.pdf");

            PdfDocument pdf  = new PdfDocument(new PdfReader(filePath), new PdfWriter(filePathFilled));
            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);

            PdfFont fontHELVETICA = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);

            string AsAboveAddressVaule = todo.AsAboveAddress ? "Yes" : ""; // empty string is false

            form.GetField("First Name").SetValue(todo.FirstName);
            form.GetField("Last Name").SetValue(todo.LastName);
            form.GetField("Full Address").SetValue(todo.FullAddress);
            if (todo.MailingAddress != null && AsAboveAddressVaule.Length <= 0)
            {
                PdfTextFormField mailingAddress = PdfFormField.CreateText(pdf, new Rectangle(227, 607, 310, 30), "mailingAddress", todo.MailingAddress, fontHELVETICA, 18);
                form.AddField(mailingAddress);
            }
            else
            {
                form.GetField("As Above").SetCheckType(PdfFormField.TYPE_CHECK).SetValue(AsAboveAddressVaule);
            }

            form.GetField("Email Address").SetValue(todo.EmailAddress).SetJustification(PdfFormField.ALIGN_LEFT);
            PdfTextFormField phoneNumber = PdfFormField.CreateText(pdf, new Rectangle(145, 538, 392, 30), "phoneNumber", "0" + todo.PhoneNumber.ToString(), fontHELVETICA, 18);

            form.AddField(phoneNumber);
            form.GetField("Citizenship Statas").SetValue(todo.CitizenStatus).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Employment Start Date").SetValue(todo.EmploymentStartDate.ToString()).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Employment Type").SetValue(todo.EmploymentType).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Position Title").SetValue(todo.PositionTitle).SetJustification(PdfFormField.ALIGN_LEFT);
            form.GetField("Name").SetValue(todo.EmergencyContactName);
            form.GetField("Relationship").SetValue(todo.EmergencyContactRelationship);
            PdfTextFormField emergencyContactPhoneNumber = PdfFormField.CreateText(pdf, new Rectangle(145, 275, 392, 30), "emergencyPhoneNumber", "0" + todo.EmergencyContactPhoneNumber.ToString(), fontHELVETICA, 18);

            form.AddField(emergencyContactPhoneNumber);

            if (todo.EmployeeSignature != null)
            {
                ImageData imageData = ImageDataFactory.CreatePng(todo.EmployeeSignature);
                Image     image     = new Image(imageData).ScaleAbsolute(200, 50).SetFixedPosition(1, 190, 180);
                Document  document  = new Document(pdf);
                document.Add(image);
            }

            form.FlattenFields();
            pdf.Close();

            return(File(filePathFilled, "application/pdf"));;
        }