Beispiel #1
0
        private void ExportarPDF()
        {
            try
            {
                XmlSerializer xmlSerial = new XmlSerializer(typeof(List <Post>));
                ServiceReference1.SvcPostClient svcCliente = new ServiceReference1.SvcPostClient();
                string xmlResp = svcCliente.ListarTodo();

                StringReader xmlRead = new StringReader(xmlResp);

                List <Post> lPost = (List <Post>)xmlSerial.Deserialize(xmlRead);


                ///CREACION DE PAGINA PDF
                var    pdfDoc = new Document(PageSize.LETTER, 40f, 40f, 60f, 60f);
                string path   = $"C://PDFs//report{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf";
                PdfWriter.GetInstance(pdfDoc, new FileStream(path, FileMode.OpenOrCreate));
                pdfDoc.Open();

                var columnas = 3;
                var colWidth = new[] { 1f, 2f, 4f };

                var tabla = new PdfPTable(colWidth)
                {
                    WidthPercentage     = 100,
                    DefaultCell         = { MinimumHeight = 22f },
                    HorizontalAlignment = 0
                };

                var celda = new PdfPCell(new Phrase("REPORTE DE POSTS"))
                {
                    Colspan             = columnas,
                    HorizontalAlignment = 1,
                    MinimumHeight       = 30f
                };

                tabla.AddCell(celda);

                tabla.AddCell("ID");
                tabla.AddCell("Título");
                tabla.AddCell("Post");

                foreach (Post p in lPost)
                {
                    tabla.AddCell(p.id_post.ToString());
                    tabla.AddCell(p.titulo_post);
                    tabla.AddCell(p.texto_post);
                }

                pdfDoc.Add(tabla);
                pdfDoc.Close();

                MessageBox.Show("Reporte Generado");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Beispiel #2
0
        private void LlenarGrilla()
        {
            XmlSerializer xmlSerial = new XmlSerializer(typeof(List <Post>));

            ServiceReference1.SvcPostClient svcCliente = new ServiceReference1.SvcPostClient();
            string xmlResp = svcCliente.ListarTodo();

            StringReader xmlRead = new StringReader(xmlResp);

            List <Post> lPost = (List <Post>)xmlSerial.Deserialize(xmlRead);

            dgListPost.ItemsSource = lPost;
        }