コード例 #1
0
        // GET: Documentos


        public FileResult GerarRelatorio()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte = PdfSharpCore.Drawing.XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganzacao        = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var titulodetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 7);

                var logo = @"C:\Users\Rafael\source\repos\Igreja.Com\Igreja.Com.Web\wwwroot\Imagens\logo.jpg";

                var qtdPaginas = doc.PageCount;
                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));

                // Impressão do LogoTipo
                XImage imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 20, 10, 100, 50);

                textFormatter.DrawString("Igreja Evangelica Assembleia de Deus", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(225, 15, 150, 150));
                textFormatter.DrawString("Avenida Leopoldo de Matos", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(250, 35, 150, 150));
                textFormatter.DrawString("Guajará-Mirim RO", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(265, 55, 150, 150));

                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhes.DrawString("Ficha Cadastro de Membro ", titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 90, page.Width, page.Height));

                textFormatter.DrawString("O senhor é meu pastor e nada me faltará", new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(225, 825, page.Width, page.Height));

                int posicao = 130;
                var membro  = new MembroPDF();

                foreach (var propertyInfo in membro.GetType().GetProperties())
                {
                    textFormatter.DrawString(propertyInfo.Name, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, posicao, page.Width, page.Height));
                    textFormatter.DrawString("___________________________________", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(85, posicao, page.Width, page.Height));

                    posicao = posicao + 25;
                }


                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);

                    var nomeArquivo = "RelatorioValdir.pdf";

                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #2
0
        public async Task <FileResult> GerarRelatorio()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte = PdfSharpCore.Drawing.XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganzacao        = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var titulodetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 7);

                var logo = @"wwwroot\imagens\logo.jpg";



                var qtdPaginas = doc.PageCount;

                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(575, 825, page.Width, page.Height));

                // Impressão do LogoTipo
                XImage imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 50, 10, 500, 100);

                // Titulo Exibição
                textFormatter.DrawString(" Nome : ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 130, page.Width, page.Height));
                textFormatter.DrawString(" Agência de Advocacia ", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 130, page.Width, page.Height));

                textFormatter.DrawString(" Cliente : ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 150, page.Width, page.Height));
                textFormatter.DrawString(" Unibrasil2020 ", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 150, page.Width, page.Height));

                textFormatter.DrawString(" Processo : ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 170, page.Width, page.Height));
                textFormatter.DrawString(DateTime.Now.ToString(), fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 170, page.Width, page.Height));


                // Titulo maior
                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhes.DrawString(" Detalhes ", titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 200, page.Width, page.Height));


                // titulo das colunas
                var alturaTituloDetalhesY = 240;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Nome", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(67, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("CPF", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(200, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Telefone", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(325, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("E-mail", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(470, alturaTituloDetalhesY, page.Width, page.Height));



                //dados do relatório
                var alturaDetalhesItens = 260;
                var clientes            = await _context.Cliente.ToListAsync();

                foreach (var a in clientes)
                {
                    textFormatter.DrawString(a.Nome_Cliente, fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(60, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(a.CPF_Cliente, fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(190, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(a.Telefone_Cliente.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(325, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(a.Email_Cliente, fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(460, alturaDetalhesItens, page.Width, page.Height));
                    alturaDetalhesItens += 20;
                }


                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);

                    var nomeArquivo = "RelatorioAdvocaciaPPFinal.pdf";

                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #3
0
        public async Task <FileResult> Download()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics               = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte               = PdfSharpCore.Drawing.XBrushes.Black;
                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganizacao       = new PdfSharpCore.Drawing.XFont("Ariel", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Ariel", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var tituloDetalhes         = new PdfSharpCore.Drawing.XFont("Ariel", 8, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Ariel", 7);
                var qtdPaginas             = doc.PageCount;

                //imagem logotipo
                var logo = @"C:\Users\dionn\Desktop\Ferman19.05.2020\PROJETO_FUP_Brasil\wwwroot\img\logo.jpg";
                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(575, 825, page.Width, page.Height));
                XImage imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 20, 5, 100, 50);


                //Titulo Maior
                var descricaoFinanceira = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                descricaoFinanceira.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                descricaoFinanceira.DrawString("Detalhamento Financeiro", tituloDetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 120, page.Width, page.Height));

                //titulo das Colunas
                var alturaTituloFinanceiroY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Saida", fonteDescricao, PdfSharpCore.Drawing.XBrushes.Red, new PdfSharpCore.Drawing.XRect(20, alturaTituloFinanceiroY, page.Width, page.Height));
                detalhes.DrawString("Entrada", fonteDescricao, PdfSharpCore.Drawing.XBrushes.Green, new PdfSharpCore.Drawing.XRect(220, alturaTituloFinanceiroY, page.Width, page.Height));
                detalhes.DrawString("Total Liquido", fonteDescricao, PdfSharpCore.Drawing.XBrushes.DodgerBlue, new PdfSharpCore.Drawing.XRect(340, alturaTituloFinanceiroY, page.Width, page.Height));


                //gerar dados do relátorio

                FinanceiroViewModel model = new FinanceiroViewModel();
                var alturaItens           = 160;
                var alturaItens2          = 160;
                var conteudoAluno         = await _context.Aluno.Include(d => d.Cursos).ToListAsync();

                var conteudoFuncionario = await _context.Funcionario.ToListAsync();

                model.Funcionarios = conteudoFuncionario;
                model.Alunos       = conteudoAluno;
                decimal somaDespesas = 0;
                decimal somaLucros   = 0;
                decimal totalLiquido = 0;


                foreach (var item in model.Funcionarios)
                {
                    textFormatter.DrawString("Saida: " + item.SalarioFuncionario, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaItens, page.Width, page.Height));
                    somaDespesas += item.SalarioFuncionario;
                    alturaItens  += 20;
                }


                foreach (var item in model.Alunos)
                {
                    textFormatter.DrawString("Entrada: " + item.Cursos.ValorCurso, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaItens2, page.Width, page.Height));
                    somaLucros   += item.Cursos.ValorCurso;
                    alturaItens2 += 20;
                }
                totalLiquido = somaLucros - somaDespesas;
                textFormatter.DrawString("Total Saida: " + somaDespesas, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaItens, page.Width, page.Height));
                textFormatter.DrawString("Total Entrada: " + somaLucros, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaItens2, page.Width, page.Height));
                textFormatter.DrawString("Total Liquido: " + totalLiquido, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(340, alturaItens2, page.Width, page.Height));



                //cabeçalho inicio statico
                textFormatter.DrawString("Instituição: ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 95, page.Width, page.Height));
                textFormatter.DrawString("Faculdade Universitaria de Programação", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(80, 95, page.Width, page.Height));
                //cabeçalho das colunas



                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);
                    var nomeArquivo = "relatorioFinancerio.pdf";
                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #4
0
        static void OldSimpleMain(string[] args)
        {
            PdfSharpCore.Fonts.GlobalFontSettings.FontResolver = new FontResolver();

            MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes
            .ImageSource.ImageSourceImpl = new PdfSharpCore.ImageSharp.ImageSharpImageSource <SixLabors.ImageSharp.PixelFormats.Rgba32>();


            using (PdfSharpCore.Pdf.PdfDocument document = new PdfSharpCore.Pdf.PdfDocument())
            {
                document.Info.Title    = "Family Tree";
                document.Info.Author   = "FamilyTree Ltd. - Stefan Steiger";
                document.Info.Subject  = "Family Tree";
                document.Info.Keywords = "Family Tree, Genealogical Tree, Genealogy, Bloodline, Pedigree";


                document.ViewerPreferences.Direction = PdfSharpCore.Pdf.PdfReadingDirection.LeftToRight;

                PdfSharpCore.Pdf.PdfPage page = document.AddPage();

                // page.Width = PdfSettings.PaperFormatSettings.Width
                // page.Height = PdfSettings.PaperFormatSettings.Height

                page.Width  = 500;
                page.Height = 1000;

                page.Orientation = PdfSharpCore.PageOrientation.Landscape;


                double mid              = page.Width / 2;
                double textBoxWidth     = 200;
                double halfTextBoxWidth = textBoxWidth / 2;


                using (PdfSharpCore.Drawing.XGraphics gfx = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page))
                {
                    gfx.MUH = PdfSharpCore.Pdf.PdfFontEncoding.Unicode;

                    PdfSharpCore.Drawing.Layout.XTextFormatter tf = new PdfSharpCore.Drawing.Layout.XTextFormatter(gfx);
                    tf.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Left;

                    PdfSharpCore.Drawing.Layout.XTextFormatterEx2 etf = new PdfSharpCore.Drawing.Layout.XTextFormatterEx2(gfx);


                    string fn = @"C:\Users\username\Pictures\4_Warning_Signs_Of_Instability_In_Russia1.png";
                    // fn = @"C:\Users\username\Pictures\62e867ba-9bb7-40d0-b01f-57f7cc951929.jpg";
                    // DrawImg(fn, gfx, 10, 10);



                    double dblWidth     = 1.0;
                    string strHtmlColor = "#FF00FF";
                    PdfSharpCore.Drawing.XColor LineColor = XColorHelper.FromHtml(strHtmlColor);
                    PdfSharpCore.Drawing.XPen   pen       = new PdfSharpCore.Drawing.XPen(LineColor, dblWidth);


                    double dblX1 = 100;
                    double dblY1 = 100;

                    double dblX2 = 200;
                    double dblY2 = 200;
                    gfx.DrawLine(pen, dblX1, dblY1, dblX2, dblY2);



                    double rectX      = 100;
                    double rectY      = 100;
                    double rectWidth  = 200;
                    double rectHeight = 100;

                    PdfSharpCore.Drawing.XRect rect = new PdfSharpCore.Drawing.XRect(rectX, rectY
                                                                                     , rectWidth, rectHeight
                                                                                     );

                    PdfSharpCore.Drawing.XFont font = new PdfSharpCore.Drawing.XFont("Arial"
                                                                                     , 12.0, PdfSharpCore.Drawing.XFontStyle.Bold
                                                                                     );

                    int    lastFittingChar = 0;
                    double neededHeight    = 0.0;


                    string text = @"I bi dr Gummiboum
U schtah eifach so chli da
So wie jedä Gummiboum 
'sch im Fau aues, woni cha

U i nime d Tage so wie si sii
U si chömed u gö wider verbii
U aues wird anders oder blibt wies isch gsii

Ja i nime d Tage so we si sii
U si chömed u gö wider verbii
Aues wird anders oder blibt wies isch gsii

Ja aues wird anders oder blibt wies isch gsii

I bi dr Gummiboum
U verstoube fängs ä chli
Oh Gummiboum

I bin ä geile huere Gummiboum
öppert mues ne schliesslich sii";

                    etf.PrepareDrawString(text, font, rect, out lastFittingChar, out neededHeight);
                    System.Console.WriteLine(lastFittingChar);
                    System.Console.WriteLine(neededHeight);

                    string foo = text.Substring(0, lastFittingChar);
                    System.Console.WriteLine(foo);


                    tf.DrawString(text
                                  , font
                                  , PdfSharpCore.Drawing.XBrushes.Black
                                  , rect
                                  , PdfSharpCore.Drawing.XStringFormats.TopLeft
                                  );

                    //gfx.DrawRectangle(PdfSharpCore.Drawing.XBrushes.HotPink, rect);
                    gfx.DrawRectangle(pen, rect);
                } // End Using gfx


                byte[] baPdfDocument;

                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    document.Save(ms, false);
                    ms.Flush();

                    // baPdfDocument = new byte[ms.Length];
                    // ms.Seek(0, System.IO.SeekOrigin.Begin);
                    // ms.Read(baPdfDocument, 0, (int)ms.Length);

                    baPdfDocument = ms.ToArray();
                } // End Using ms


                System.IO.File.WriteAllBytes("FamilyTree.pdf", baPdfDocument);
                //document.Save(filename);
            } // End Using document

            System.Console.WriteLine(System.Environment.NewLine);
            System.Console.WriteLine(" --- Press any key to continue --- ");
            System.Console.ReadKey();
        } // End Sub Main
コード例 #5
0
        public async Task <FileResult> DownloadAluno()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics               = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte               = PdfSharpCore.Drawing.XBrushes.Black;
                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganizacao       = new PdfSharpCore.Drawing.XFont("Ariel", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Ariel", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var tituloDetalhes         = new PdfSharpCore.Drawing.XFont("Ariel", 8, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Ariel", 7);
                var logo       = @"D:\3Periodo\Ferman26.05 ultima versao\PROJETO_FUP_Brasil\wwwroot\img\logo.jpg";
                var qtdPaginas = doc.PageCount;

                //imagem logotipo
                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(575, 825, page.Width, page.Height));
                XImage imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 20, 5, 100, 50);


                //Titulo Maior
                var descricaoFinanceira = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                descricaoFinanceira.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                descricaoFinanceira.DrawString("Alunos do Curso", tituloDetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 120, page.Width, page.Height));

                //titulo das Colunas
                var alturaTituloFinanceiroY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Aluno", fonteDescricao, PdfSharpCore.Drawing.XBrushes.Red, new PdfSharpCore.Drawing.XRect(20, alturaTituloFinanceiroY, page.Width, page.Height));
                detalhes.DrawString("Curso", fonteDescricao, PdfSharpCore.Drawing.XBrushes.Green, new PdfSharpCore.Drawing.XRect(220, alturaTituloFinanceiroY, page.Width, page.Height));

                //gerar dados do relátorio

                Cursos model         = new Cursos();
                var    alturaItens   = 160;
                var    alturaItens2  = 160;
                var    conteudoAluno = await _context.Aluno.Include(d => d.Cursos).ToListAsync();

                model.Aluno = conteudoAluno;

                if (model.Aluno != null)
                {
                    foreach (var item in model.Aluno)
                    {
                        textFormatter.DrawString("Aluno: " + item.Nome, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaItens, page.Width, page.Height));
                        alturaItens += 20;
                    }


                    foreach (var item in model.Aluno)
                    {
                        textFormatter.DrawString("Curso: " + item.Cursos.NomeCurso, fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaItens2, page.Width, page.Height));
                        alturaItens2 += 20;
                    }
                }

                //cabeçalho inicio statico
                textFormatter.DrawString("Instituição: ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 95, page.Width, page.Height));
                textFormatter.DrawString("Faculdade Universitaria de Programação", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(80, 95, page.Width, page.Height));



                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);
                    var nomeArquivo = "relatorioFinancerio.pdf";
                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            // TfsRemover.RemoveTFS();
            TreeInfo ti = GetAncestors();

            int maxNumPeople = (int)System.Math.Pow(2.0, (double)ti.MaxGeneration);

            System.Console.WriteLine(maxNumPeople);

            System.Collections.Generic.Dictionary <int, System.Collections.Generic.Dictionary <int
                                                                                               , DataPoint> > dict
                = new System.Collections.Generic.Dictionary <int
                                                             , System.Collections.Generic.Dictionary <int, DataPoint> >();

            PdfSharpCore.Fonts.GlobalFontSettings.FontResolver = new FontResolver();

            MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes
            .ImageSource.ImageSourceImpl = new PdfSharpCore.ImageSharp.ImageSharpImageSource <Rgba32>();


            using (PdfSharpCore.Pdf.PdfDocument document = new PdfSharpCore.Pdf.PdfDocument())
            {
                document.Info.Title    = "Family Tree";
                document.Info.Author   = "FamilyTree Ltd. - Stefan Steiger";
                document.Info.Subject  = "Family Tree";
                document.Info.Keywords = "Family Tree, Genealogical Tree, Genealogy, Bloodline, Pedigree";



                document.ViewerPreferences.Direction = PdfSharpCore.Pdf.PdfReadingDirection.LeftToRight;

                PdfSharpCore.Pdf.PdfPage page = document.AddPage();

                // page.Width = PdfSettings.PaperFormatSettings.Width
                // page.Height = PdfSettings.PaperFormatSettings.Height

                const double GOLDEN_RATIO = 1.61803398875;

                // https://en.wikipedia.org/wiki/Golden_ratio
                double marginLeft    = 125;
                double marginTop     = marginLeft;
                double textBoxWidth  = 200;
                double textBoxHeight = textBoxWidth / GOLDEN_RATIO;

                double textBoxVdistance      = textBoxHeight / (GOLDEN_RATIO / (GOLDEN_RATIO * GOLDEN_RATIO));
                double textBoxLargeHdistance = textBoxWidth / (GOLDEN_RATIO * GOLDEN_RATIO);
                double textBoxSmallHdistance = textBoxLargeHdistance / (GOLDEN_RATIO * GOLDEN_RATIO);



                int numGenerationsToList = 5;
                int maxGenerationIndex   = numGenerationsToList - 1;
                int numItems             = (int)System.Math.Pow(2, maxGenerationIndex);


                page.Orientation = PdfSharpCore.PageOrientation.Landscape;

                page.Width = marginLeft * 2
                             + numItems * textBoxWidth
                             + (numItems / 2) * textBoxSmallHdistance
                             + (numItems / 2 - 1) * textBoxLargeHdistance
                ;

                page.Height = marginTop * 2
                              + numGenerationsToList * textBoxHeight
                              + (numGenerationsToList - 1) * textBoxVdistance
                ;



                double dblLineWidth = 1.0;
                string strHtmlColor = "#FF00FF";
                PdfSharpCore.Drawing.XColor lineColor = XColorHelper.FromHtml(strHtmlColor);
                PdfSharpCore.Drawing.XPen   pen       = new PdfSharpCore.Drawing.XPen(lineColor, dblLineWidth);

                PdfSharpCore.Drawing.XFont font = new PdfSharpCore.Drawing.XFont("Arial"
                                                                                 , 12.0, PdfSharpCore.Drawing.XFontStyle.Bold
                                                                                 );


                using (PdfSharpCore.Drawing.XGraphics gfx = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page))
                {
                    gfx.MUH = PdfSharpCore.Pdf.PdfFontEncoding.Unicode;

                    PdfSharpCore.Drawing.Layout.XTextFormatter tf = new PdfSharpCore.Drawing.Layout.XTextFormatter(gfx);
                    tf.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Left;

                    PdfSharpCore.Drawing.Layout.XTextFormatterEx2 etf = new PdfSharpCore.Drawing.Layout.XTextFormatterEx2(gfx);


                    for (int generationNumber = maxGenerationIndex; generationNumber > -1; --generationNumber)
                    {
                        dict[generationNumber] = new System.Collections.Generic.Dictionary <int, DataPoint>();

                        int num = (int)System.Math.Pow(2.0, generationNumber);

                        for (int i = 0; i < num; ++i)
                        {
                            if (generationNumber != maxGenerationIndex)
                            {
                                var dp1 = dict[generationNumber + 1][i * 2];
                                var dp2 = dict[generationNumber + 1][i * 2 + 1];

                                var rect1 = dp1.rect;
                                var rect2 = dp2.rect;


                                double xNew = (rect1.TopLeft.X + rect2.TopRight.X) / 2.0;
                                double yNew = marginTop
                                              + generationNumber * textBoxHeight
                                              + generationNumber * textBoxVdistance;

                                gfx.DrawLine(pen, xNew, yNew + rect1.Height, rect1.X + rect1.Width / 2.0, rect1.Y);
                                gfx.DrawLine(pen, xNew, yNew + rect1.Height, rect2.X + rect2.Width / 2.0, rect2.Y);

                                xNew = xNew - rect1.Width / 2.0;

                                dict[generationNumber][i] = new DataPoint()
                                {
                                    Person = (
                                        from itemList in ti.ls[generationNumber]
                                        where itemList.Id == dp1.Person.Child
                                        select itemList
                                        ).FirstOrDefault(),
                                    rect = new DataStructures.Rectangle(xNew, yNew, rect1.Width, rect1.Height)
                                };
                            }
                            else
                            {
                                System.Console.WriteLine($"i: {i}");
                                int numSmallSpaces = (i + 1) / 2;
                                System.Console.WriteLine($"numSmallSpaces: {numSmallSpaces}");
                                int numPairs = i / 2;
                                System.Console.WriteLine($"numPairs: {numPairs}");


                                double rectX = marginLeft
                                               + i * textBoxWidth
                                               + numSmallSpaces * textBoxSmallHdistance
                                               + numPairs * textBoxLargeHdistance
                                ;

                                double rectY = marginTop
                                               + generationNumber * textBoxHeight
                                               + generationNumber * textBoxVdistance
                                ;


                                dict[generationNumber][i] = new DataPoint()
                                {
                                    Person = ti.ls[generationNumber][i],
                                    rect   = new DataStructures.Rectangle(rectX, rectY, textBoxWidth, textBoxHeight)
                                };
                            }

                            gfx.DrawRectangle(pen, dict[generationNumber][i].rect.ToXRect());


                            string text = $@"Generation {generationNumber} Person {i}";
                            text = dict[generationNumber][i].Person.composite_name;


                            tf.DrawString(text
                                          , font
                                          , PdfSharpCore.Drawing.XBrushes.Black
                                          , dict[generationNumber][i].rect.ToXRect()
                                          , PdfSharpCore.Drawing.XStringFormats.TopLeft
                                          );
                        } // Next i
                    }     // Next generationNumber
                }         // End Using gfx


                byte[] baPdfDocument;

                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    document.Save(ms, false);
                    ms.Flush();

                    // baPdfDocument = new byte[ms.Length];
                    // ms.Seek(0, System.IO.SeekOrigin.Begin);
                    // ms.Read(baPdfDocument, 0, (int)ms.Length);

                    baPdfDocument = ms.ToArray();
                } // End Using ms


                System.IO.File.WriteAllBytes("FamilyTree.pdf", baPdfDocument);
                //document.Save(filename);
            } // End Using document

            System.Console.WriteLine(System.Environment.NewLine);
            System.Console.WriteLine(" --- Press any key to continue --- ");
            System.Console.ReadKey();
        } // End Sub Main
コード例 #7
0
 public void AddPagina()
 {
     Page          = _document.AddPage();
     Gfx           = PdfSharpCore.Drawing.XGraphics.FromPdfPage(Page);
     textFormatter = new PdfSharpCore.Drawing.Layout.XTextFormatter(Gfx);
 }
コード例 #8
0
        public FileResult GerarRelatorio()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument()) {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;

                List <Malote> lst = new List <Malote>();
                lst.Add(new Malote()
                {
                    Remetente = "Teste", Cidade = "Teste"
                });

                var grafics          = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte         = PdfSharpCore.Drawing.XBrushes.Black;
                var textFormatter    = new PdfSharpCore.Drawing.Layout.XTextFormatter(grafics);
                var fonteOrganizacao = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteTitulo      = new PdfSharpCore.Drawing.XFont("Arial", 10, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDesc        = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.Bold);
                var titulo           = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhes    = new PdfSharpCore.Drawing.XFont("Arial", 7);
                var logo             = @"C:\Logo.png";

                var qtdpaginas = doc.PageCount;

                textFormatter.DrawString(qtdpaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 7), corFonte,
                                         new PdfSharpCore.Drawing.XRect(575, 825, page.Width, page.Height));

                XImage imagem = XImage.FromFile(logo);
                grafics.DrawImage(imagem, 160, 15, 280, 150);

                textFormatter.DrawString("Protocolo de Envio de Malote", titulo, corFonte, new PdfSharpCore.Drawing.XRect(200, 160, page.Width, page.Height));

                textFormatter.DrawString("REMETENTE", fonteTitulo, corFonte, new PdfSharpCore.Drawing.XRect(70, 210, page.Width, page.Height));
                textFormatter.DrawString("DESTINO", fonteTitulo, corFonte, new PdfSharpCore.Drawing.XRect(170, 210, page.Width, page.Height));
                textFormatter.DrawString("N. LACRE ", fonteTitulo, corFonte, new PdfSharpCore.Drawing.XRect(270, 210, page.Width, page.Height));
                textFormatter.DrawString("PERCURSO", fonteTitulo, corFonte, new PdfSharpCore.Drawing.XRect(370, 210, page.Width, page.Height));
                textFormatter.DrawString("N. MALOTE", fonteTitulo, corFonte, new PdfSharpCore.Drawing.XRect(470, 210, page.Width, page.Height));


                List <Malote> alunos = new List <Malote>();

                MySqlConnection con = new MySqlConnection();
                con.ConnectionString = c.ConexaoDados();
                con.Open();
                string data = DateTime.Now.ToShortDateString();
                //Npgsql.NpgsqlCommand command = new Npgsql.NpgsqlCommand("SELECT" + '"' + "Remetente" + '"' + " , " + '"' + "Cidade" + "FROM" + '"' + "MaloteModel" + '"', con);
                MySqlCommand    command = new MySqlCommand("SELECT * FROM Malote  WHERE  DataEnvio = '" + DateTime.Today.ToString("yyyy/MM/dd") + "'", con);
                MySqlDataReader reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        alunos.Add(new Malote()
                        {
                            CidadeSaida = reader.GetString("CidadeSaida"),
                            Cidade      = reader.GetString("Cidade"),
                            Lacre       = reader.GetInt32("Lacre"),
                            Percurso    = reader.GetInt32("Percurso"),
                            Numero      = reader.GetInt32("Numero")
                        });
                    }
                    Console.WriteLine(data);
                }

                var alturaItens = 230;
                for (int i = 0; i < alunos.Count; i++)
                {
                    textFormatter.DrawString(alunos[i].CidadeSaida, fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(70, alturaItens, page.Width, page.Height));
                    textFormatter.DrawString(alunos[i].Cidade, fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(170, alturaItens, page.Width, page.Height));
                    textFormatter.DrawString(alunos[i].Lacre.ToString(), fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(270, alturaItens, page.Width, page.Height));
                    textFormatter.DrawString(alunos[i].Percurso.ToString(), fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(370, alturaItens, page.Width, page.Height));
                    textFormatter.DrawString(alunos[i].Numero.ToString(), fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(470, alturaItens, page.Width, page.Height));

                    alturaItens += 20;
                }

                textFormatter.DrawString("________________________________", fonteOrganizacao, corFonte,
                                         new PdfSharpCore.Drawing.XRect(50, 750, page.Width, page.Height));

                textFormatter.DrawString("________________________________", fonteOrganizacao, corFonte,
                                         new PdfSharpCore.Drawing.XRect(360, 750, page.Width, page.Height));

                textFormatter.DrawString("Correios", fonteOrganizacao, corFonte,
                                         new PdfSharpCore.Drawing.XRect(50, 770, page.Width, page.Height));

                textFormatter.DrawString("Grupo Bellinati", fonteOrganizacao, corFonte,
                                         new PdfSharpCore.Drawing.XRect(360, 770, page.Width, page.Height));


                using (MemoryStream stream = new MemoryStream()) {
                    var contentType = "application/pdf";
                    doc.Save(stream, false);
                    var nomeArquivo = "Protocolo do Malote: " + DateTime.Today.ToString("dd/MM/yyyy") + ".pdf";

                    return(File(stream.ToArray(), contentType, nomeArquivo));
                }
            }
        }
コード例 #9
0
        public IActionResult ImprimirMovimentacoes(RequisicaoModel entity)
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.Crown;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics = XGraphics.FromPdfPage(page);
                var corFonte = XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganzacao        = new XFont("Arial", 16);
                var fonteDescricao         = new XFont("Arial", 16, XFontStyle.BoldItalic);
                var titulodetalhes         = new XFont("Arial", 28, XFontStyle.Bold);
                var fonteDetalhesDescricao = new XFont("Arial", 14);

                var qtdPaginas = doc.PageCount;
                textFormatter.DrawString(qtdPaginas.ToString(), new XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));


                var fonteTitulo = new XFont("Arial", 20, XFontStyle.Bold);

                // CABEÇALHO
                textFormatter.DrawString("MOVIMENTAÇÕES DE REQUISIÇÕES", fonteTitulo, corFonte, new XRect(20, 30, page.Width, page.Height));

                textFormatter.DrawString("Status: ", fonteDescricao, corFonte, new XRect(20, 70, page.Width, page.Height));
                textFormatter.DrawString(entity.Status, fonteOrganzacao, corFonte, new XRect(85, 69, page.Width, page.Height));

                textFormatter.DrawString("Período: ", fonteDescricao, corFonte, new XRect(20, 90, page.Width, page.Height));
                textFormatter.DrawString(entity.Data + " até " + entity.DataFinal, fonteOrganzacao, corFonte, new XRect(105, 89, page.Width, page.Height));

                // DETALHE
                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;

                // COLUNAS
                var alturaTituloDetalhesY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Número", fonteDescricao, corFonte, new XRect(20, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Descrição", fonteDescricao, corFonte, new XRect(100, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Tipo", fonteDescricao, corFonte, new XRect(630, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Origem", fonteDescricao, corFonte, new XRect(710, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Destino", fonteDescricao, corFonte, new XRect(850, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Status", fonteDescricao, corFonte, new XRect(1020, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Usuário", fonteDescricao, corFonte, new XRect(1200, alturaTituloDetalhesY, page.Width, page.Height));

                var dados = entity.ListaRequisicao();

                // DADOS
                var alturaDetalhesItens = 160;
                foreach (var item in dados)
                {
                    textFormatter.DrawString(item.Id.ToString(), fonteDetalhesDescricao, corFonte, new XRect(21, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.Descricao, fonteDetalhesDescricao, corFonte, new XRect(101, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.Tipo == "T" ? "Transbordo" : "Backload", fonteDetalhesDescricao, corFonte, new XRect(631, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.NomeEstacaoOrigem, fonteDetalhesDescricao, corFonte, new XRect(710, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.NomeEstacaoDestino, fonteDetalhesDescricao, corFonte, new XRect(850, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.Status, fonteDetalhesDescricao, corFonte, new XRect(1021, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.NomeUsuarioAtual, fonteDetalhesDescricao, corFonte, new XRect(1200, alturaDetalhesItens, page.Width, page.Height));

                    alturaDetalhesItens += 20;
                }

                //DOWNLOAD
                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);

                    var nomeArquivo = "Movimentacoes.pdf";

                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #10
0
        public IActionResult ImprimirHistorico(RequisicaoModel entity)
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics = XGraphics.FromPdfPage(page);
                var corFonte = XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganzacao        = new XFont("Arial", 10);
                var fonteDescricao         = new XFont("Arial", 8, XFontStyle.BoldItalic);
                var titulodetalhes         = new XFont("Arial", 14, XFontStyle.Bold);
                var fonteDetalhesDescricao = new XFont("Arial", 7);

                var qtdPaginas = doc.PageCount;
                textFormatter.DrawString(qtdPaginas.ToString(), new XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));


                var cabecalho = entity.CarregarRegistro(entity.Id);

                var fonteTitulo = new XFont("Arial", 20, XFontStyle.Bold);

                // CABEÇALHO
                textFormatter.DrawString("HISTÓRICO DE REQUISIÇÃO", fonteTitulo, corFonte, new XRect(20, 30, page.Width, page.Height));
                // horizontal, vertical
                textFormatter.DrawString("Código requisição: ", fonteDescricao, corFonte, new XRect(20, 70, page.Width, page.Height));
                textFormatter.DrawString(cabecalho.Id.ToString(), fonteOrganzacao, corFonte, new XRect(95, 69, page.Width, page.Height));

                textFormatter.DrawString("Usuário requisitante: ", fonteDescricao, corFonte, new XRect(20, 90, page.Width, page.Height));
                textFormatter.DrawString(cabecalho.NomeUsuarioResponsavel, fonteOrganzacao, corFonte, new XRect(105, 89, page.Width, page.Height));

                textFormatter.DrawString("Data de abertura: ", fonteDescricao, corFonte, new XRect(20, 110, page.Width, page.Height));
                textFormatter.DrawString(cabecalho.Data.ToString(), fonteOrganzacao, corFonte, new XRect(95, 109, page.Width, page.Height));

                // DETALHE
                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;

                // COLUNAS
                var alturaTituloDetalhesY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Data de alteração", fonteDescricao, corFonte, new XRect(20, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Descrição", fonteDescricao, corFonte, new XRect(200, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Usuário", fonteDescricao, corFonte, new XRect(500, alturaTituloDetalhesY, page.Width, page.Height));

                var dados = entity.ObterHistorico(entity.Id);

                //DADOS
                var alturaDetalhesItens = 160;
                foreach (var item in dados)
                {
                    textFormatter.DrawString(item.DataAlteracao.ToString(), fonteDetalhesDescricao, corFonte, new XRect(21, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.Descricao, fonteDetalhesDescricao, corFonte, new XRect(201, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.NomeUsuario, fonteDetalhesDescricao, corFonte, new XRect(501, alturaDetalhesItens, page.Width, page.Height));

                    alturaDetalhesItens += 20;
                }

                //DOWNLOAD
                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);

                    var nomeArquivo = "Historico.pdf";

                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #11
0
        public FileResult GerarRelatorio()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphic  = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte = PdfSharpCore.Drawing.XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphic);
                var fonteOrganizacao       = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var tituloDetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 7);

                var logo = @"C:\Users\Alexander\source\repos\PDFSharpAspNetCore\PDFSharpAspNetCore\wwwroot\images\transferir.jpg";

                var qtdPaginas = doc.PageCount;
                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));

                //Impressão do Logo
                var imagem = XImage.FromFile(logo);
                graphic.DrawImage(imagem, 20, 5, 300, 50);

                // Titulo Exibição
                textFormatter.DrawString("Nome: ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 75, page.Width, page.Height));
                textFormatter.DrawString("Alexander Silva ", fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 75, page.Width, page.Height));

                textFormatter.DrawString("Profissão :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 95, page.Width, page.Height));
                textFormatter.DrawString("Desenvolvedor de Software", fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 95, page.Width, page.Height));

                textFormatter.DrawString("Tempo :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 115, page.Width, page.Height));
                textFormatter.DrawString("01 ano", fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 115, page.Width, page.Height));

                // Titulo Maior
                var tituloDetalhesMaior = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphic);
                tituloDetalhesMaior.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhesMaior.DrawString("RELATÓRIO ", tituloDetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 120, page.Width, page.Height));

                // Titulo Colunas
                var alturaTituloDetalhesY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphic);

                detalhes.DrawString("Descrição ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Atendimento", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(144, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Operação", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Quantidade", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Status", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(337, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Data", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(400, alturaTituloDetalhesY, page.Width, page.Height));

                // Dados Relatório
                var alturaDetalhesItens = 160;
                for (int i = 1; i < 30; i++)
                {
                    textFormatter.DrawString("Descrição" + ": " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(21, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Atendimento" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(145, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Operação" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(215, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Quantidade" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Status" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(332, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(DateTime.Now.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(400, alturaDetalhesItens, page.Width, page.Height));

                    alturaDetalhesItens += 20;
                }

                using (var stream = new MemoryStream())
                {
                    var contentType = "application/pdf";
                    doc.Save(stream, false);
                    var nomeArquivo = "Relatorio.pdf";
                    return(File(stream.ToArray(), contentType, nomeArquivo));
                }
            }
        }
コード例 #12
0
        public FileResult GerarPdf()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;

                var graphics              = XGraphics.FromPdfPage(page);
                var corFonte              = XBrushes.Black;
                var textFormatter         = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganizacao      = new XFont("Arial", 10);
                var fonteDescricao        = new XFont("Arial", 12, XFontStyle.BoldItalic);
                var titulodetalhes        = new XFont("Arial", 14, XFontStyle.Bold);
                var fonteDetalheDescricao = new XFont("Arial", 7);

                //var logo = @"C:\Users\pedri\Desktop\CineManager\CineManager\CineManager\CineManager\wwwroot\logo-cm-ps.png";

                var qtdPaginas = doc.PageCount;

                textFormatter.DrawString(qtdPaginas.ToString(), new XFont("Arial", 10), corFonte,
                                         new XRect(578, 825, page.Width, page.Height));

                //XImage imagem = XImage.FromFile(logo);
                //graphics.DrawImage(imagem, 20, 5, 300, 50);

                textFormatter.DrawString("Filmes que ja estiveram disponiveis e estarão futuramente", fonteDescricao, corFonte,
                                         new XRect(20, 75, page.Width, page.Height));

                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhes.DrawString("Detalhes", titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 120, page.Width, page.Height));


                var alturaTituloDetalhesY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                //titulo
                detalhes.DrawString("Filme", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaTituloDetalhesY, page.Width, page.Height));

                //duração
                detalhes.DrawString("Duração", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaTituloDetalhesY, page.Width, page.Height));


                //lançamento
                detalhes.DrawString("Lançamento", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaTituloDetalhesY, page.Width, page.Height));

                //em cartaz
                detalhes.DrawString("Em cartaz até", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(430, alturaTituloDetalhesY, page.Width, page.Height));

                List <Filme> listaFilmes = _context.Filme.Include(x => x.Generos).Include(x => x.TiposFilme).ToList();


                var alturarDatalhesItens = 160;

                foreach (Filme f in listaFilmes)
                {
                    textFormatter.DrawString(f.Titulo.ToString(), fonteDetalheDescricao, corFonte,
                                             new XRect(15, alturarDatalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(f.Duracao.ToString(), fonteDetalheDescricao, corFonte,
                                             new XRect(220, alturarDatalhesItens, page.Width, page.Height));

                    textFormatter.DrawString(f.Lancamento.ToString().Substring(0, 10), fonteDetalheDescricao, corFonte,
                                             new XRect(290, alturarDatalhesItens, page.Width, page.Height));

                    textFormatter.DrawString(f.EmCartazAte.ToString().Substring(0, 10), fonteDetalheDescricao, corFonte,
                                             new XRect(430, alturarDatalhesItens, page.Width, page.Height));

                    alturarDatalhesItens += 20;
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    var contentType = "application/pdf";

                    doc.Save(stream, false);

                    var nomeArquivo = "relatorioFilmes.pdf";

                    return(File(stream.ToArray(), contentType, nomeArquivo));
                }
            }
        }
コード例 #13
0
        //DateTime searchDtIni, DateTime searchDtFim
        public FileResult GerarRelatorio(String searchDtIni, String searchDtFim)
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte = PdfSharpCore.Drawing.XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganzacao        = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var titulodetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 7);

                var logo = @"Imgs\logo_questorQ.png";

                var qtdPaginas = doc.PageCount;
                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));

                // Impressão do LogoTipo
                XImage imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 20, 5, 300, 50);

                // Titulo Exibição
                textFormatter.DrawString("Nome :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 75, page.Width, page.Height));
                textFormatter.DrawString("João", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 75, page.Width, page.Height));

                textFormatter.DrawString("Loja :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 95, page.Width, page.Height));
                textFormatter.DrawString("Garagem do João", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 95, page.Width, page.Height));

                // Titulo maior
                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhes.DrawString("Anuncios ", titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 120, page.Width, page.Height));

                // titulo das colunas
                var alturaTituloDetalhesY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Marca", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Modelo", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(80, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Ano Veiculo", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(120, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Valor de Venda", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(180, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Lucro", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(250, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Data Venda", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(350, alturaTituloDetalhesY, page.Width, page.Height));

                //dados do relatório
                var alturaDetalhesItens = 160;

                DateTime dateIni = DateTime.ParseExact(searchDtIni, "dd/MM/yyyy", null);
                DateTime dateFim = DateTime.ParseExact(searchDtFim, "dd/MM/yyyy", null);

                var anuncioss = from AN in _context.Anuncio
                                join MA in _context.Marca on AN.IdMarca equals MA.ID
                                where AN.DataVenda >= dateIni && AN.DataVenda <= dateFim
                                select AN;

                var webGaragemContext = anuncioss.Include(a => a.Marca).Include(a => a.Modelo);

                foreach (var item in webGaragemContext)
                {
                    textFormatter.DrawString(item.Marca.NomeMarca, fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(21, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.Modelo.NomeModelo, fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(80, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.AnoVeiculo, fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(120, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.ValorVenda.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(180, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString((item.ValorVenda - item.ValorCompra).ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(250, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.DataVenda.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(350, alturaDetalhesItens, page.Width, page.Height));

                    alturaDetalhesItens += 20;
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);

                    var nomeArquivo = "RelatorioJoao.pdf";

                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #14
0
        public FileResult GerarRelatorio()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics               = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte               = PdfSharpCore.Drawing.XBrushes.Black;
                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganizacao       = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var titulodetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 7);

                var logo = @"C:\TestesDev\PdfSharp\PdfSharp\PdfSharp\wwwroot\imagens\transferir.jpg";

                var qtdPaginas = doc.PageCount;

                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));


                //Impressão do logo
                XImage imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 20, 5, 300, 50);

                textFormatter.DrawString("Nome :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 75, page.Width, page.Height));
                textFormatter.DrawString("Thiago Lanza", fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 75, page.Width, page.Height));

                textFormatter.DrawString("Profissão :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 95, page.Width, page.Height));
                textFormatter.DrawString("Programador", fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 95, page.Width, page.Height));

                textFormatter.DrawString("Tempo :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 115, page.Width, page.Height));
                textFormatter.DrawString("2 anos", fonteOrganizacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 115, page.Width, page.Height));

                // Título maior
                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhes.DrawString("Detalhes", titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 120, page.Width, page.Height));


                //Título das colunas
                var alturaTituloDetalhesY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Descrição", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Atendimento", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(144, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Operação", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Quantidade", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Status", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(360, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Data", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(420, alturaTituloDetalhesY, page.Width, page.Height));

                //dados do relatório
                var alturaDetalhesItens = 160;

                void gerarTexto(string texto, int largura)
                {
                    textFormatter.DrawString(texto, fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(largura, alturaDetalhesItens, page.Width, page.Height));
                }

                for (int i = 1; i < 30; i++)
                {
                    string IToString        = i.ToString();
                    string TextoDescricao   = "Descrição :" + IToString;
                    string TextoAtendimento = "Atendimento : " + IToString;
                    string TextoOperacao    = "Operação : " + IToString;
                    string TextoQuantidade  = "Quantidade : " + IToString;
                    string TextoStatus      = "Status : " + IToString;

                    gerarTexto(TextoDescricao, 15);
                    gerarTexto(TextoAtendimento, 145);
                    gerarTexto(TextoOperacao, 215);
                    gerarTexto(TextoQuantidade, 290);
                    gerarTexto(TextoStatus, 360);
                    gerarTexto(DateTime.Now.ToString(), 420);
                    alturaDetalhesItens += 20;
                }


                using (MemoryStream stream = new MemoryStream())
                {
                    var contentType = "application/pdf";

                    doc.Save(stream, false);

                    var nomeArquivo = "relatorioThiago.pdf";

                    return(File(stream.ToArray(), contentType, nomeArquivo));
                }
            }
        }
コード例 #15
0
        public FileResult DownloadAsync(int id)
        {
            var compra = _context.Compras.Find(id);

            /*if (compra == null)
             * {
             *  return NotFound();
             * }*/

            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte = PdfSharpCore.Drawing.XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganzacao        = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 10, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var titulodetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 12, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 8);

                var tituloPrincipal = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloPrincipal.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloPrincipal.DrawString("Relatório Compra de Gado | Id Compra: " + compra.IdCompra, titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 40, page.Width, page.Height));


                // Titulo Exibição

                textFormatter.DrawString("Pecuarista: ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 75, page.Width, page.Height));
                textFormatter.DrawString(compra.Comprador, fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 75, page.Width, page.Height));

                textFormatter.DrawString("Id Pecuarista: ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 95, page.Width, page.Height));
                textFormatter.DrawString(compra.CompradorId.ToString(), fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(90, 95, page.Width, page.Height));

                textFormatter.DrawString("Data de entrega: ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 115, page.Width, page.Height));
                textFormatter.DrawString(compra.DataEntrega.ToString(), fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(100, 115, page.Width, page.Height));

                textFormatter.DrawString("Data da compra: ", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 135, page.Width, page.Height));
                textFormatter.DrawString(compra.DataCompra.ToString(), fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(100, 135, page.Width, page.Height));


                // Titulo maior
                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhes.DrawString("Detalhes/Itens da Compra ", titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 150, page.Width, page.Height));


                // titulo das colunas
                var alturaTituloDetalhesY = 170;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Animal", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Quantidade", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(144, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Preço", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Valor Total", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaTituloDetalhesY, page.Width, page.Height));


                //dados do relatório
                var alturaDetalhesItens = 190;
                var itens = _context.CompraGadoItems
                            .Include(x => x.Animal)
                            .Where(y => y.CompraGadoId == compra.IdCompra)
                            .ToList();
                var sum = 0.0;
                foreach (var item in itens)
                {
                    textFormatter.DrawString(item.Animal.Descricao.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(21, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(item.Quantidade.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(145, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("R$ " + double.Parse(item.Animal.Preco).ToString("C2"), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(215, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString((int.Parse(item.Quantidade) * double.Parse(item.Animal.Preco)).ToString("C2"), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaDetalhesItens, page.Width, page.Height));

                    sum += int.Parse(item.Quantidade) * double.Parse(item.Animal.Preco);
                    alturaDetalhesItens += 20;
                }

                textFormatter.DrawString("Total: R$", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(145, alturaDetalhesItens, page.Width, page.Height));
                textFormatter.DrawString(sum.ToString("C2"), fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(190, alturaDetalhesItens, page.Width, page.Height));
                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);

                    var nomeArquivo = "Relatorio_idpecuarista_" + compra.CompradorId
                                      + "_" + compra.Comprador + "CompraId" + compra.IdCompra + ".pdf";

                    return(File(stream.ToArray(), contantType, nomeArquivo));
                }
            }
        }
コード例 #16
0
        public async Task <IActionResult> Download(CompraUsuario compraUsuario, IWebHostEnvironment _environment)
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                #region Configuracoes da folha

                var page = doc.AddPage();

                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;

                var graphics = XGraphics.FromPdfPage(page);
                var corFonte = XBrushes.Black;

                #endregion

                #region Numeração das paginas

                int qtdPaginas = doc.PageCount;

                var numeracaoPagina = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                numeracaoPagina.DrawString(Convert.ToString(qtdPaginas), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(575, 825, page.Width, page.Height));

                #endregion

                #region Logo

                var    webRoot    = _environment.WebRootPath;
                var    logoFatura = string.Concat(webRoot, "/img/", "loja-virtual-1.png");
                XImage imagem     = XImage.FromFile(logoFatura);
                graphics.DrawImage(imagem, 20, 5, 300, 50);

                #endregion

                #region Informações 2

                var alturaTituloDetalhesY = 120;

                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                var tituloInfo_1 = new PdfSharpCore.Drawing.XFont("Arial", 8, XFontStyle.Regular);

                detalhes.DrawString("Dados do banco", tituloInfo_1, corFonte, new XRect(25, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("Banco Itau 004", tituloInfo_1, corFonte, new XRect(150, alturaTituloDetalhesY, page.Width, page.Height));

                alturaTituloDetalhesY += 9;
                detalhes.DrawString("Código Gerado", tituloInfo_1, corFonte, new XRect(25, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString("000000 000000 000000 000000", tituloInfo_1, corFonte, new XRect(150, alturaTituloDetalhesY, page.Width, page.Height));


                alturaTituloDetalhesY += 9;
                detalhes.DrawString("Quantidade:", tituloInfo_1, corFonte, new XRect(25, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString(compraUsuario.QuantidadeProdutos.ToString(), tituloInfo_1, corFonte, new XRect(150, alturaTituloDetalhesY, page.Width, page.Height));

                alturaTituloDetalhesY += 9;
                detalhes.DrawString("Valor Total:", tituloInfo_1, corFonte, new XRect(25, alturaTituloDetalhesY, page.Width, page.Height));
                detalhes.DrawString(compraUsuario.QuantidadeProdutos.ToString(), tituloInfo_1, corFonte, new XRect(150, alturaTituloDetalhesY, page.Width, page.Height));

                var tituloInfo_2 = new PdfSharpCore.Drawing.XFont("Arial", 8, XFontStyle.Bold);


                try
                {
                    var img = await GeraQrCode("Dados do banco aqui");

                    Stream streamImage = new MemoryStream(img);

                    XImage qrCode = XImage.FromStream(() => streamImage);

                    alturaTituloDetalhesY += 40;
                    graphics.DrawImage(qrCode, 140, alturaTituloDetalhesY, 310, 310);
                }
                catch (Exception erro)
                {
                }

                alturaTituloDetalhesY += 620;
                detalhes.DrawString("Canhoto com QrCode para pagamento online.", tituloInfo_2, corFonte, new XRect(20, alturaTituloDetalhesY, page.Width, page.Height));

                #endregion

                using (MemoryStream stream = new MemoryStream())
                {
                    var contentType = "application/pdf";

                    doc.Save(stream, false);
                    return(File(stream.ToArray(), contentType, "BoletoLojaOnline.pdf"));
                }
            }
        }
コード例 #17
0
        //Método Criado para o PDF
        public FileResult GerarRelatorio()
        {
            using (var doc = new PdfSharpCore.Pdf.PdfDocument())
            {
                var page = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                var graphics = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
                var corFonte = PdfSharpCore.Drawing.XBrushes.Black;

                var textFormatter          = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                var fonteOrganzacao        = new PdfSharpCore.Drawing.XFont("Arial", 10);
                var fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                var titulodetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                var fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 7);
                var webRoot    = _environment.WebRootPath;
                var logo       = string.Concat(webRoot, "/imagens/logo.jpg");
                var qtdPaginas = doc.PageCount;
                textFormatter.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));

                // Impressão do LogoTipo
                XImage imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 20, 5, 300, 50);


                // Titulo Exibição
                textFormatter.DrawString("Nome :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 75, page.Width, page.Height));
                textFormatter.DrawString("Valdir Ferreira ", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 75, page.Width, page.Height));

                textFormatter.DrawString("Profissão :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 95, page.Width, page.Height));
                textFormatter.DrawString("Programador", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 95, page.Width, page.Height));

                textFormatter.DrawString("Tempo :", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, 115, page.Width, page.Height));
                textFormatter.DrawString("10 anos", fonteOrganzacao, corFonte, new PdfSharpCore.Drawing.XRect(80, 115, page.Width, page.Height));


                // Titulo maior
                var tituloDetalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);
                tituloDetalhes.Alignment = PdfSharpCore.Drawing.Layout.XParagraphAlignment.Center;
                tituloDetalhes.DrawString("Detalhes ", titulodetalhes, corFonte, new PdfSharpCore.Drawing.XRect(0, 120, page.Width, page.Height));


                // titulo das colunas
                var alturaTituloDetalhesY = 140;
                var detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);

                detalhes.DrawString("Descrição", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(20, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Atendimento", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(144, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Operação", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(220, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Quantidade", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Status", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(337, alturaTituloDetalhesY, page.Width, page.Height));

                detalhes.DrawString("Data", fonteDescricao, corFonte, new PdfSharpCore.Drawing.XRect(400, alturaTituloDetalhesY, page.Width, page.Height));


                //dados do relatório
                var alturaDetalhesItens = 160;
                for (int i = 1; i < 30; i++)
                {
                    textFormatter.DrawString("Descrição" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(21, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Atendimento" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(145, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Operação" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(215, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Quantidade" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString("Status" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(332, alturaDetalhesItens, page.Width, page.Height));
                    textFormatter.DrawString(DateTime.Now.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(400, alturaDetalhesItens, page.Width, page.Height));

                    alturaDetalhesItens += 20;
                }



                #region //ADICIONAR NOVA PAGINA

                page             = doc.AddPage();
                page.Size        = PdfSharpCore.PageSize.A4;
                page.Orientation = PdfSharpCore.PageOrientation.Portrait;
                graphics         = XGraphics.FromPdfPage(page);
                corFonte         = XBrushes.Black;

                fonteOrganzacao        = new PdfSharpCore.Drawing.XFont("Arial", 10);
                fonteDescricao         = new PdfSharpCore.Drawing.XFont("Arial", 8, PdfSharpCore.Drawing.XFontStyle.BoldItalic);
                titulodetalhes         = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);
                fonteDetalhesDescricao = new PdfSharpCore.Drawing.XFont("Arial", 7);
                detalhes = new PdfSharpCore.Drawing.Layout.XTextFormatter(graphics);



                logo       = string.Concat(webRoot, "/imagens/logo.jpg");
                qtdPaginas = doc.PageCount;
                detalhes.DrawString(qtdPaginas.ToString(), new PdfSharpCore.Drawing.XFont("Arial", 10), corFonte, new PdfSharpCore.Drawing.XRect(578, 825, page.Width, page.Height));

                // Impressão do LogoTipo
                imagem = XImage.FromFile(logo);
                graphics.DrawImage(imagem, 20, 5, 300, 50);

                var alturaDetalhesItensPageNew = 160;
                for (int i = 1; i < 30; i++)
                {
                    detalhes.DrawString("Descrição" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(21, alturaDetalhesItensPageNew, page.Width, page.Height));
                    detalhes.DrawString("Atendimento" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(145, alturaDetalhesItensPageNew, page.Width, page.Height));
                    detalhes.DrawString("Operação" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(215, alturaDetalhesItensPageNew, page.Width, page.Height));
                    detalhes.DrawString("Quantidade" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(290, alturaDetalhesItensPageNew, page.Width, page.Height));
                    detalhes.DrawString("Status" + " : " + i.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(332, alturaDetalhesItensPageNew, page.Width, page.Height));
                    detalhes.DrawString(DateTime.Now.ToString(), fonteDetalhesDescricao, corFonte, new PdfSharpCore.Drawing.XRect(400, alturaDetalhesItensPageNew, page.Width, page.Height));

                    alturaDetalhesItensPageNew += 20;
                }
                #endregion


                using (MemoryStream stream = new MemoryStream())
                {
                    var contantType = "application/pdf";
                    doc.Save(stream, false);

                    var nomeArquivo = "RelPDF.pdf";

                    //return File(stream.ToArray(), contantType, nomeArquivo);

                    FileContentResult result = new FileContentResult(stream.ToArray(), "application/pdf");


                    return(result);
                }
            }

            //return View();
        }