Exemplo n.º 1
0
        private void Imprimir_Click(object sender, RoutedEventArgs e)
        {
            var doc = new Document(PageSize.LETTER);

            using (var fbd = new FolderBrowserDialog()) {
                var result = fbd.ShowDialog();
                if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                {
                    var path         = fbd.SelectedPath;
                    var nombre       = _service.SearchCompetitionById(competition).Name;
                    var filename     = $"Adjudicación de plazas de {nombre}.pdf";
                    var absolutePath = Path.Combine(path, filename);
                    for (var count = 1; File.Exists(absolutePath); count++)
                    {
                        filename     = $"Adjudicación de plazas de {nombre} (Copia {count}).pdf";
                        absolutePath = Path.Combine(path, filename);
                    }

                    var writer = PdfWriter.GetInstance(doc,
                                                       new FileStream(absolutePath, FileMode.CreateNew));

                    doc.Open();
                    var _standardFont = new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL, BaseColor.BLACK);


                    doc.Add(new Paragraph($"Adjudicación de plazas de {nombre}"));
                    doc.Add(Chunk.NEWLINE);

                    foreach (var d in Resultados.Items)
                    {
                        doc.Add(new Paragraph(d.ToString()));
                    }

                    doc.Close();
                    writer.Close();
                    Process.Start(absolutePath);
                    _service.ChangeToClosed(competition.ID);
                    Resultados.Items.Clear();
                }
            }
        }