Esempio n. 1
0
        public void EscreverParcelaPagasTags()
        {
            var corFonte  = PdfSharpCore.Drawing.XBrushes.Black;
            var fonteTag  = new PdfSharpCore.Drawing.XFont("Arial", 10, PdfSharpCore.Drawing.XFontStyle.Bold);
            var fonteTipo = new PdfSharpCore.Drawing.XFont("Arial", 12, PdfSharpCore.Drawing.XFontStyle.Bold);


            textFormatter.DrawString("Pagos", fonteTipo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, 150, Page.Width, Page.Height));

            textFormatter.DrawString("Id", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, 180, Page.Width, Page.Height));

            textFormatter.DrawString("Valor Da Parcela", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         100, 180, Page.Width, Page.Height));

            textFormatter.DrawString("Vencimento", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         200, 180, Page.Width, Page.Height));

            textFormatter.DrawString("Cliente", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         300, 180, Page.Width, Page.Height));

            textFormatter.DrawString("Nota", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         400, 180, Page.Width, Page.Height));
        }
        public void EscreverSaldo(double Saldo, int Altura)
        {
            var fonteConteudo = new PdfSharpCore.Drawing.XFont("Arial", 10);
            var corFonte      = PdfSharpCore.Drawing.XBrushes.Black;
            var fonteTipo     = new PdfSharpCore.Drawing.XFont("Arial", 12, PdfSharpCore.Drawing.XFontStyle.Bold);

            textFormatter.DrawString("Saldo: ", fonteTipo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, Altura + 90, Page.Width, Page.Height));
            textFormatter.DrawString(Saldo.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         80, Altura + 90, Page.Width, Page.Height));
        }
        public void EscreverHead(DateTime DataInicial, DateTime DataFinal)
        {
            var corFonte       = PdfSharpCore.Drawing.XBrushes.Black;
            var fonteConteudo  = new PdfSharpCore.Drawing.XFont("Arial", 10);
            var tituloDetalhes = new PdfSharpCore.Drawing.XFont("Arial", 14, PdfSharpCore.Drawing.XFontStyle.Bold);

            textFormatter.DrawString("Fluxo de Caixa - JNX", tituloDetalhes, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, 75, Page.Width, Page.Height));
            textFormatter.DrawString("Periodo: " + DataInicial.Date.ToString("d") + " até " + DataFinal.Date.ToString("d")
                                     , fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, 100, Page.Width, Page.Height));
        }
        public void EscreverDespesaCorpo(Despesa item, int Altura)
        {
            var fonteConteudo = new PdfSharpCore.Drawing.XFont("Arial", 10);
            var corFonte      = PdfSharpCore.Drawing.XBrushes.Black;

            textFormatter.DrawString(item.ID.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, Altura + 70, Page.Width, Page.Height));
            textFormatter.DrawString("R$ " + item.Valor.ToString() + ",00", fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         100, Altura + 70, Page.Width, Page.Height));
            textFormatter.DrawString(item.Data.Date.ToString("d"), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         200, Altura + 70, Page.Width, Page.Height));
            textFormatter.DrawString(item.TipoCusto.Nome.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         300, Altura + 70, Page.Width, Page.Height));
            if (item.Observacao != null)
            {
                textFormatter.DrawString(item.Observacao.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                             400, Altura + 70, Page.Width, Page.Height));
            }
        }
Esempio n. 5
0
        public void EscreverParcelaVencidaCorpo(Parcela item, int Altura)
        {
            var fonteConteudo = new PdfSharpCore.Drawing.XFont("Arial", 10);
            var corFonte      = PdfSharpCore.Drawing.XBrushes.Black;

            textFormatter.DrawString(item.ID.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, Altura + 140, Page.Width, Page.Height));
            textFormatter.DrawString("R$ " + item.ValorParcela.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         100, Altura + 140, Page.Width, Page.Height));
            textFormatter.DrawString(item.Vencimento.Date.ToString("d"), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         200, Altura + 140, Page.Width, Page.Height));
            textFormatter.DrawString(item.Fatura.Cliente.Nome.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         300, Altura + 140, Page.Width, Page.Height));
            if (item.Fatura.Numero != null)
            {
                textFormatter.DrawString(item.Fatura.Numero.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                             400, Altura + 140, Page.Width, Page.Height));
            }
        }
        public void EscreverDespesaTags(int Altura)
        {
            var corFonte  = PdfSharpCore.Drawing.XBrushes.Black;
            var fonteTag  = new PdfSharpCore.Drawing.XFont("Arial", 10, PdfSharpCore.Drawing.XFontStyle.Bold);
            var fonteTipo = new PdfSharpCore.Drawing.XFont("Arial", 12, PdfSharpCore.Drawing.XFontStyle.Bold);


            textFormatter.DrawString("Despesas", fonteTipo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, Altura + 20, Page.Width, Page.Height));
            textFormatter.DrawString("ID", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, Altura + 50, Page.Width, Page.Height));
            textFormatter.DrawString("Valor", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         100, Altura + 50, Page.Width, Page.Height));
            textFormatter.DrawString("Data", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         200, Altura + 50, Page.Width, Page.Height));
            textFormatter.DrawString("Tipo", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         300, Altura + 50, Page.Width, Page.Height));
            textFormatter.DrawString("Obs", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         400, Altura + 50, Page.Width, Page.Height));
        }
        public void EscreverFaturamentoTags()
        {
            var corFonte  = PdfSharpCore.Drawing.XBrushes.Black;
            var fonteTag  = new PdfSharpCore.Drawing.XFont("Arial", 10, PdfSharpCore.Drawing.XFontStyle.Bold);
            var fonteTipo = new PdfSharpCore.Drawing.XFont("Arial", 12, PdfSharpCore.Drawing.XFontStyle.Bold);


            textFormatter.DrawString("Faturamento", fonteTipo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, 150, Page.Width, Page.Height));
            textFormatter.DrawString("Numero", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         30, 180, Page.Width, Page.Height));
            textFormatter.DrawString("Valor", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         100, 180, Page.Width, Page.Height));
            textFormatter.DrawString("Data", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         200, 180, Page.Width, Page.Height));
            textFormatter.DrawString("Cliente", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         300, 180, Page.Width, Page.Height));
            textFormatter.DrawString("Obs", fonteTag, corFonte, new PdfSharpCore.Drawing.XRect(
                                         400, 180, Page.Width, Page.Height));
        }
        public void EscreverFaturamentoCorpo(Fatura item, int Altura)
        {
            var fonteConteudo = new PdfSharpCore.Drawing.XFont("Arial", 10);
            var corFonte      = PdfSharpCore.Drawing.XBrushes.Black;

            if (item.Numero != null)
            {
                textFormatter.DrawString(item.Numero.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                             30, Altura, Page.Width, Page.Height));
            }

            textFormatter.DrawString("R$ " + item.ValorFatura.ToString() + ",00", fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         100, Altura, Page.Width, Page.Height));
            textFormatter.DrawString(item.DataEmissao.Date.ToString("d"), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         200, Altura, Page.Width, Page.Height));
            textFormatter.DrawString(item.Cliente.Nome.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                         300, Altura, Page.Width, Page.Height));
            if (item.Observacao != null)
            {
                textFormatter.DrawString(item.Observacao.ToString(), fonteConteudo, corFonte, new PdfSharpCore.Drawing.XRect(
                                             400, Altura, Page.Width, Page.Height));
            }
        }
Esempio n. 9
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
Esempio n. 10
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
Esempio n. 11
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));
                }
            }
        }