Esempio n. 1
0
        private void DrawOneBadge(XGraphics graph, int x, int y, string nev, string poszt, double wp, double hp)
        {
            const int BadgeWidth  = 255; // 90mm
            const int BadgeHeight = 156; // 55mm

            graph.DrawRectangle(new Pen(Color.FromArgb(10, 0, 0, 0), 1), new XRect(x, y, BadgeWidth, BadgeHeight));
            XPdfFontOptions pdfFondOptions = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            XFont fontName = new XFont("Garamond", 16, XFontStyle.Bold, pdfFondOptions);
            XFont fontPos  = new XFont("Garamond", 16, XFontStyle.Italic, pdfFondOptions);

            XImage logo = null;

            if (this.logoLocation != null)
            {
                logo = XImage.FromFile(this.logoLocation);
            }
            else
            {
                logo = XImage.FromGdiPlusImage(Properties.Resources.logo);
            }

            double logoRatio           = (double)logo.PixelWidth / (double)logo.PixelHeight; // ~0.5
            int    logoHeight          = (int)((double)BadgeHeight * 0.8);
            int    logoWidth           = (int)Math.Floor(logoHeight * logoRatio);
            int    badgeVerticalMargin = 10;

            int logoStartX = x + BadgeWidth - badgeVerticalMargin - logoWidth;
            int logoStartY = y + (int)Math.Floor((double)BadgeHeight - (double)logoHeight) / 2;

            double linePercentage = 0.8;
            int    lineStartX     = x + BadgeWidth - logoWidth - (2 * badgeVerticalMargin);
            int    lineStartY     = y + (int)(((1 - linePercentage) * BadgeHeight) / 2);
            int    lineEndX       = lineStartX;
            int    lineEndY       = lineStartY + (int)(linePercentage * BadgeHeight);

            int textStartX = x + badgeVerticalMargin;
            int textStartY = y + badgeVerticalMargin + fontName.Height;
            int textWidth  = BadgeWidth - 4 * badgeVerticalMargin - logoWidth;
            int textHeight = logoWidth;

            PdfSharp.Drawing.Layout.XTextFormatter textFormatter = new XTextFormatter(graph);
            textFormatter.Alignment       = XParagraphAlignment.Center;
            textFormatter.LayoutRectangle = new XRect(textStartX, textStartY, textWidth, textHeight);

            XSize firstStrSize = graph.MeasureString(nev, fontName);
            int   lineNum      = (int)(Math.Ceiling(firstStrSize.Width / Convert.ToDouble(textWidth)));

            textFormatter.DrawString(nev, fontName, XBrushes.Black, new XRect(textStartX, textStartY, textWidth, textHeight));
            textFormatter.DrawString(poszt, fontPos, XBrushes.Black, new XRect(textStartX, textStartY + (lineNum * fontName.Height), textWidth, textHeight));
            graph.DrawImage(logo, logoStartX, logoStartY, logoWidth, logoHeight);
            graph.DrawLine(new Pen(Color.Black, 1), lineStartX, lineStartY, lineEndX, lineEndY);
        }
Esempio n. 2
0
        public static void WriteText(XTextFormatter textFormatter, Point columnLocation, ExportText exportColumn)
        {
            var font = PdfHelper.CreatePdfFont(exportColumn);
            var rect = new Rectangle(columnLocation, exportColumn.DesiredSize).ToXRect();

            textFormatter.Alignment = XParagraphAlignment(exportColumn);

            textFormatter.DrawString(exportColumn.Text,
                                     font,
                                     CreateBrush(exportColumn.ForeColor),
                                     rect, XStringFormats.TopLeft);
        }
Esempio n. 3
0
        static void Main()
        {
            const string filename = "TextLayout_tempfile.pdf";

            const string text =
                "Facin exeraessisit la consenim iureet dignibh eu facilluptat vercil dunt autpat. " +
                "Ecte magna faccum dolor sequisc iliquat, quat, quipiss equipit accummy niate magna " +
                "facil iure eraesequis am velit, quat atis dolore dolent luptat nulla adio odipissectet " +
                "lan venis do essequatio conulla facillandrem zzriusci bla ad minim inis nim velit eugait " +
                "aut aut lor at ilit ut nulla ate te eugait alit augiamet ad magnim iurem il eu feuissi.\n" +
                "Guer sequis duis eu feugait luptat lum adiamet, si tate dolore mod eu facidunt adignisl in " +
                "henim dolorem nulla faccum vel inis dolutpatum iusto od min ex euis adio exer sed del " +
                "dolor ing enit veniamcon vullutat praestrud molenis ciduisim doloborem ipit nulla consequisi.\n" +
                "Nos adit pratetu eriurem delestie del ut lumsandreet nis exerilisit wis nos alit venit praestrud " +
                "dolor sum volore facidui blaor erillaortis ad ea augue corem dunt nis  iustinciduis euisi.\n" +
                "Ut ulputate volore min ut nulpute dolobor sequism olorperilit autatie modit wisl illuptat dolore " +
                "min ut in ute doloboreet ip ex et am dunt at.";

            PdfDocument document = new PdfDocument();

            PdfPage        page = document.AddPage();
            XGraphics      gfx  = XGraphics.FromPdfPage(page);
            XFont          font = new XFont("Times New Roman", 10, XFontStyle.Bold);
            XTextFormatter tf   = new XTextFormatter(gfx);

            XRect rect = new XRect(40, 100, 200, 232);

            gfx.DrawRectangle(XBrushes.SeaShell, rect);
            //tf.Alignment = ParagraphAlignment.Left;
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

            rect = new XRect(310, 100, 250, 232);
            gfx.DrawRectangle(XBrushes.SeaShell, rect);
            tf.Alignment = XParagraphAlignment.Right;
            tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

            rect = new XRect(40, 400, 250, 232);
            gfx.DrawRectangle(XBrushes.SeaShell, rect);
            tf.Alignment = XParagraphAlignment.Center;
            tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

            rect = new XRect(310, 400, 250, 232);
            gfx.DrawRectangle(XBrushes.SeaShell, rect);
            tf.Alignment = XParagraphAlignment.Justify;
            tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

            // Save the document...
            document.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
        }
Esempio n. 4
0
        public static void WriteCaption(string text, int offsetLeft, int offsetTop, XRect rectangle, XBrush brush, double fontsize = 8.5)
        {
            var tf = new XTextFormatter(gfx);

            var font    = new XFont("Open Sans", fontsize, XFontStyle.Bold);
            var textbox = new XRect(rectangle.Left + offsetLeft, rectangle.Top + offsetTop, 150, 400);

            var state = gfx.Save();

            gfx.RotateAtTransform(-90, new XPoint(rectangle.Left + offsetLeft, rectangle.Top + offsetTop));
            tf.DrawString(text, font, brush, textbox, XStringFormats.TopLeft);
            gfx.Restore(state);
        }
Esempio n. 5
0
        public void PostaviSaTackomDatum(DateTime datum, PdfPage stranica)
        {
            XGraphics      gfx  = XGraphics.FromPdfPage(stranica);
            XFont          font = new XFont("Times New Roman", 12, XFontStyle.Regular);
            XTextFormatter tf   = new XTextFormatter(gfx);

            XRect xRect = new XRect(60, 660, 350, 220);

            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString("U Beogradu, " + datum.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) + ". godine",
                          font, XBrushes.Black, xRect, XStringFormats.TopLeft);
            gfx.Dispose();
        }
Esempio n. 6
0
        public void PostaviManjiNaslov(string naslov, PdfPage stranica)
        {
            XGraphics      gfx  = XGraphics.FromPdfPage(stranica);
            XFont          font = new XFont("Times New Roman", 14, XFontStyle.Italic);
            XTextFormatter tf   = new XTextFormatter(gfx);

            XRect xRect = new XRect(40, 120, 350, 220);

            tf.Alignment = XParagraphAlignment.Center;
            tf.DrawString(naslov, font, XBrushes.Black, xRect, XStringFormats.TopLeft);

            gfx.Dispose();
        }
Esempio n. 7
0
        public void PostaviOpisJustify(string opis, PdfPage stranica)
        {
            XGraphics      gfx  = XGraphics.FromPdfPage(stranica);
            XFont          font = new XFont("Times New Roman", 13, XFontStyle.Regular);
            XTextFormatter tf   = new XTextFormatter(gfx);

            XRect xRect = new XRect(60, 160, 490, 220);

            tf.Alignment = XParagraphAlignment.Justify;
            tf.DrawString(opis, font, XBrushes.Black, xRect, XStringFormats.TopLeft);

            gfx.Dispose();
        }
Esempio n. 8
0
        private void getTitlePage()
        {
            try
            {
                JsonReader        reader     = new JsonTextReader(new StringReader(WebRequestHelper.getData("http://mbbsweb.azurewebsites.net/api/Module/GetModuleInfo?moduleID=" + data.ModuleName, data.Token)));
                string            text       = WebRequestHelper.getData("http://mbbsweb.azurewebsites.net/api/Module/GetModuleInfo?moduleID=" + data.ModuleName, data.Token);
                ModuleInformation moduleInfo = JsonConvert.DeserializeObject <ModuleInformation>(text);
                XFont             titleFont  = new XFont("Verdana", 15, XFontStyle.Bold);

                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1)))
                {
                    SizeF  size      = graphics.MeasureString(moduleInfo.ModuleName, new Font("Verdana", 15, FontStyle.Bold, GraphicsUnit.Point));
                    Double textWidth = (double)size.Width / 2;
                    XRect  titleRect = new XRect((pdfPage.Width / 2) - textWidth / 1.4, 100, someWidth, 200);
                    tf.DrawString(moduleInfo.ModuleName, titleFont, XBrushes.Black, titleRect, XStringFormats.TopLeft);
                    size      = graphics.MeasureString(data.ModuleName, new Font("Verdana", 15, FontStyle.Bold, GraphicsUnit.Point));
                    textWidth = (double)size.Width / 2;
                    titleRect = new XRect(pdfPage.Width / 2 - textWidth / 1.4, 120, someWidth, 200);
                    tf.DrawString(data.ModuleName, titleFont, XBrushes.Black, titleRect, XStringFormats.TopLeft);
                }



                XFont infoText = new XFont("Verdana", 10, XFontStyle.Regular);
                XRect infoRect = new XRect(myX, pdfPage.Height - 200, someWidth, 200);
                tf.DrawString(moduleInfo.LocationName, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 190, someWidth, 200);
                tf.DrawString(moduleInfo.Sector, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 180, someWidth, 200);
                tf.DrawString(moduleInfo.POBox, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 170, someWidth, 200);
                tf.DrawString(moduleInfo.PostalCode, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 160, someWidth, 200);
                tf.DrawString(moduleInfo.Phone, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                infoRect = new XRect(myX, pdfPage.Height - 150, someWidth, 200);
                tf.DrawString(moduleInfo.Website, infoText, XBrushes.Black, infoRect, XStringFormats.TopLeft);

                pdfPage = pdf.AddPage();
                graph   = XGraphics.FromPdfPage(pdfPage);
                tf      = new XTextFormatter(graph);
            }
            catch
            {
                getTitlePage();
            }
        }
Esempio n. 9
0
        public override void Print(ref XGraphics graphics, ref int y)
        {
            //792
            var tf = new XTextFormatter(graphics);

            tf.Alignment = XParagraphAlignment.Justify;
            var brush = XBrushes.Gray;

            y = 750;
            var   rect = new XRect(180, y, 420, 40);
            XFont font = new XFont("Verdana", 8, XFontStyle.Regular);

            tf.DrawString(Value, font, brush, rect, XStringFormats.TopLeft);
        }
Esempio n. 10
0
        private void AddAPage(PdfDocument document, XFont font)
        {
            const int x        = 40;
            const int y        = 50;
            var       page     = document.AddPage();
            var       renderer = XGraphics.FromPdfPage(page);
            var       tf       = new XTextFormatter(renderer);
            var       width    = page.Width.Value - 50 - x;
            var       height   = page.Height.Value - 50 - y;
            var       rect     = new XRect(40, 50, width, height);

            renderer.DrawRectangle(XBrushes.SeaShell, rect);
            tf.DrawString(TestData.LoremIpsumText, font, XBrushes.Black, rect, XStringFormats.TopLeft);
        }
Esempio n. 11
0
 private void AddNewHousePage()
 {
     _currentY = _initialY;
     _page     = _document.AddPage();
     _pageNumber++;
     _gfx = XGraphics.FromPdfPage(_page);
     AddFooter();
     _gfx.DrawString(_pageNumber.ToString(), _medBoldFont, XBrushes.Black, 535, 775);
     _tf = new XTextFormatter(_gfx);
     WriteLine("A", _medBoldFont, _initialX + 420);
     WriteLine("B", _medBoldFont, _initialX + 450);
     WriteLine("C", _medBoldFont, _initialX + 480);
     NewLine();
 }
Esempio n. 12
0
        private static XGraphics NewPage(PdfDocument document, out PdfPage page, XGraphics gfx, out XTextFormatter tf, out int YPointer, XImage logo)
        {
            gfx.Dispose();
            page = document.AddPage();
            XGraphics g = XGraphics.FromPdfPage(page);

            tf       = new XTextFormatter(g);
            YPointer = 40;

            //put logo on page before returning
            gfx.DrawImage(logo, new XPoint(595 - 191 - 30, 20));

            return(g);
        }
Esempio n. 13
0
        private static void PaintPdfCellText(XGraphics graphicsDc, string text, PdfCell cell)
        {
            XRect rc = new XRect(cell.Left + cell.LeftMargin, cell.Top + cell.TopMargin, cell.Width - cell.LeftMargin, cell.Height);

            XStringFormat xfmt = new XStringFormat();

            xfmt.Alignment = XStringAlignment.Near;
            XTextFormatter textFmt = new XTextFormatter(graphicsDc);

            textFmt.LayoutRectangle = rc;
            textFmt.Alignment       = XParagraphAlignment.Left;
            textFmt.Font            = cell.XFont;
            XSize textSz = graphicsDc.MeasureString(text, cell.XFont, xfmt);

            if (textSz.Width > rc.Width ||
                textSz.Height > rc.Height ||
                text.Contains("\r") ||
                text.Contains("\n"))
            {
                try
                {
                    textFmt.DrawString(text ?? string.Empty,
                                       cell.XFont,
                                       XBrushes.Black,
                                       rc,
                                       xfmt);
                }
                catch
                {
                    try
                    {
                        graphicsDc.DrawString(text ?? string.Empty,
                                              cell.XFont,
                                              XBrushes.Black,
                                              rc,
                                              xfmt);
                    }
                    catch { }
                }
            }
            else
            {
                graphicsDc.DrawString(text ?? string.Empty,
                                      cell.XFont,
                                      XBrushes.Black,
                                      rc,
                                      xfmt);
            }
        }
Esempio n. 14
0
        public void drawSomething(double myY, XUnit Height, double newHeight, string title, string content)
        {
            XRect rect  = new XRect(myX, myY, someWidth, someHeight);
            XRect rect2 = new XRect(myX, myY + 50, someWidth, newHeight);

            tf.DrawString(title, font, XBrushes.Black, rect, XStringFormats.TopLeft);
            double contentSpaceLength = content.Count(Char.IsWhiteSpace);
            double contentHeight      = (contentSpaceLength / 12) * 11 + 50;

            if (myY + contentHeight < Height)
            {
                tf.DrawString(content, font2, XBrushes.Black, rect2, XStringFormats.TopLeft);
            }
            else
            {
                string   totalString    = "";
                string   removedPart    = "";
                string[] splittedString = content.Split('.');
                for (int i = splittedString.Length - 1; i > 0; i--)
                {
                    totalString = "";
                    for (int x = 0; x < i; x++)
                    {
                        totalString += splittedString[x];
                    }
                    removedPart = splittedString[i] + removedPart;
                    if (myX + ((totalString.Count(char.IsWhiteSpace) / 12) * 11 + 50) < Height)
                    {
                        rect2 = new XRect(myX, myY + 50, someWidth, ((totalString.Count(char.IsWhiteSpace) / 12) * 11 + 50));
                        tf.DrawString(totalString, font2, XBrushes.Black, rect2, XStringFormats.TopLeft);

                        pdfPage = pdf.AddPage();
                        graph   = XGraphics.FromPdfPage(pdfPage);
                        tf      = new XTextFormatter(graph);
                        myY     = 50;

                        rect2 = new XRect(myX, myY, someWidth, ((removedPart.Count(char.IsWhiteSpace) / 12) * 11 + 50));
                        tf.DrawString(removedPart, font2, XBrushes.Black, rect2, XStringFormats.TopLeft);
                        Console.WriteLine(removedPart);
                        this.myY += ((removedPart.Count(char.IsWhiteSpace) / 12) * 11 + 50);
                        Console.WriteLine(myY.ToString());
                        totalString     = "";
                        removedPart     = "";
                        heightIsUpdated = true;
                        i = -1;
                    }
                }
            }
        }
Esempio n. 15
0
        private void EscreverCampo(DTOCampo campo, XGraphics gfx, XFont font, PdfPage page, int alturaLinha,
                                   XTextFormatter textFormatter, int padding, int posicaoInicialEtapa, int qtdCampos, int tamanhoTituloEtapa, bool possuiEspacoAntes)
        {
            textFormatter.Alignment = XParagraphAlignment.Left;

            var alturaCampo = CalcularAlturaCampo(gfx.MeasureString(campo.ObterTexto(), font).Width, (int)page.Width,
                                                  alturaLinha);

            var rect = new XRect(padding,
                                 ((possuiEspacoAntes ? posicaoInicialEtapa : 40) +
                                  (alturaLinha * qtdCampos) +
                                  (possuiEspacoAntes ? tamanhoTituloEtapa : 0)), page.Width - 60, alturaCampo);

            textFormatter.DrawString(campo.ObterTexto(), font, XBrushes.Black, rect);
        }
Esempio n. 16
0
        public override void Print(ref XGraphics graphics, ref int y)
        {
            XTextFormatter tf = new XTextFormatter(graphics);

            tf.Alignment = XParagraphAlignment.Center;
            var   brush  = XBrushes.DarkBlue;
            var   brush2 = XBrushes.Black;
            XFont font   = new XFont("Verdana", 15, XFontStyle.Bold);
            var   font2  = new XFont("Verdana", 13, XFontStyle.Bold);

            y = 175;
            XRect  rect  = new XRect(15, y, 150, 20);
            string value = Name + " " + Surrname;// + "\n" + DateofBirth + "\n" + Adress + "\ne-mail: " + Email + "\ntelefon: " + PhoneNumber;

            tf.DrawString(value, font, brush2, rect, XStringFormats.TopLeft);
            value = "\nData ur.\n" + DateofBirth + "\n" + Adress + "\ne-mail: " + Email + "\ntelefon: " + PhoneNumber;
            font  = new XFont("Verdana", 12, XFontStyle.Regular);
            y    += 20;
            rect  = new XRect(15, y, 150, 40);
            //data
            tf.DrawString("\nData ur.\n", font2, brush, rect, XStringFormats.TopLeft);
            y   += 40;
            rect = new XRect(15, y, 150, 20);
            y   += 20;
            tf.DrawString(DateofBirth, font, brush2, rect, XStringFormats.TopLeft);
            rect = new XRect(15, y, 150, 40);
            //adres
            tf.DrawString("\nAdres\n", font2, brush, rect, XStringFormats.TopLeft);
            y   += 40;
            rect = new XRect(15, y, 150, 55);
            y   += 25;
            tf.DrawString(Adress, font, brush2, rect, XStringFormats.TopLeft);
            rect = new XRect(15, y, 150, 40);
            //mail
            tf.DrawString("\ne-mail\n", font2, brush, rect, XStringFormats.TopLeft);
            y   += 40;
            rect = new XRect(15, y, 150, 15);
            y   += 15;
            tf.DrawString(Email, font, brush2, rect, XStringFormats.TopLeft);
            rect = new XRect(15, y, 150, 40);
            //telefon
            tf.DrawString("\ntelefon\n", font2, brush, rect, XStringFormats.TopLeft);
            y   += 40;
            rect = new XRect(15, y, 150, 20);
            y   += 20;
            tf.DrawString(PhoneNumber, font, brush2, rect, XStringFormats.TopLeft);
            graphics.DrawLine(new XPen(XColors.Aqua, 0.3), 15, y, 165, y);
        }
Esempio n. 17
0
        private static void Create(string fileName)
        {
            var pdf = new PdfDocument();

            pdf.Info.Title = "Test PDF";
            var pdfPage = pdf.AddPage();
            var graph   = XGraphics.FromPdfPage(pdfPage);
            var font    = new XFont("Verdana", 12, XFontStyle.Regular);

            var formatter       = new XTextFormatter(graph);
            var layoutRectangle = new XRect(10, 10, pdfPage.Width.Point, pdfPage.Height.Point);

            formatter.DrawString(RandomString(), font, XBrushes.Black, layoutRectangle);

            pdf.Save(fileName);
        }
Esempio n. 18
0
        public static void DrawParagraphOffset(PagingSetup pagingSetup, PdfPage page,
                                               XFont font, XParagraphAlignment paragraphAlignment, double offsetTop,
                                               double lineHeight, string textDisplay)
        {
            using (XGraphics gfx = XGraphics.FromPdfPage(page))
            {
                double lineWidth = page.Width - pagingSetup.MarginLeft - pagingSetup.MarginRight;

                var tf = new XTextFormatter(gfx)
                {
                    Alignment = paragraphAlignment
                };
                tf.DrawString(textDisplay, font, XBrushes.Black,
                              new XRect(pagingSetup.MarginLeft, offsetTop, lineWidth, pagingSetup.RegularLineHeight));
            }
        }
Esempio n. 19
0
        public IActionResult GenTable()
        {
            const string text =
                "Facin exeraessisit la consenim iureet dignibh eu facilluptat vercil dunt autpat. " +
                "Ecte magna faccum dolor sequisc iliquat, quat, quipiss equipit accummy niate magna " +
                "facil iure eraesequis am velit, quat atis dolore dolent luptat nulla adio odipissectet " +
                "lan venis do essequatio conulla facillandrem zzriusci bla ad minim inis nim velit eugait " +
                "aut aut lor at ilit ut nulla ate te eugait alit augiamet ad magnim iurem il eu feuissi.\n" +
                "Guer sequis duis eu feugait luptat lum adiamet, si tate dolore mod eu facidunt adignisl in " +
                "henim dolorem nulla faccum vel inis dolutpatum iusto od min ex euis adio exer sed del " +
                "dolor ing enit veniamcon vullutat praestrud molenis ciduisim doloborem ipit nulla consequisi.\n" +
                "Nos adit pratetu eriurem delestie del ut lumsandreet nis exerilisit wis nos alit venit praestrud " +
                "dolor sum volore facidui blaor erillaortis ad ea augue corem dunt nis  iustinciduis euisi.\n" +
                "Ut ulputate volore min ut nulpute dolobor sequism olorperilit autatie modit wisl illuptat dolore " +
                "min ut in ute doloboreet ip ex et am dunt at.";

            PdfDocument document = new PdfDocument();

            document.Info.Title   = "A simple invoce";
            document.Info.Subject = "Demonstrate how to create an invoce.";
            document.Info.Author  = "Luka Radovanovic";

            PdfPage page = document.AddPage();

            page.Size = PdfSharp.PageSize.A4;
            XGraphics      gfx = XGraphics.FromPdfPage(page);
            XTextFormatter tf  = new XTextFormatter(gfx);

            XFont font = new XFont("Times New Roman", 20, XFontStyle.Bold);
            XRect rect = new XRect(40, 50, 50, 50);

            tf.Alignment = XParagraphAlignment.Center;
            tf.DrawString("Naslov", font, XBrushes.Black, rect, XStringFormats.TopLeft);

            font = new XFont("Times New Roman", 14, XFontStyle.Regular);
            rect = new XRect(40, 100, 500, 500);
            gfx.DrawRectangle(XBrushes.SeaShell, rect);
            tf.Alignment = XParagraphAlignment.Left;
            tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

            MemoryStream stream = new MemoryStream();


            document.Save(stream, false);
            stream.Position = 0;
            return(File(stream, "application/pdf", "table.pdf"));
        }
Esempio n. 20
0
        public static void GenerateReport(string type)
        {
            if (type == "CSV")
            {
                using (FileStream fs = new FileStream("report.csv", FileMode.Create))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        var dbContext = ConnectionFactory.GetDbContext("Pharmacy") as PharmacyDbContext;

                        sw.WriteLine(String.Join(",", "Id", "Name", "Manufacturer", "Ingredients", "Price",
                                                 "Last sold date"));

                        foreach (var medication in dbContext.Medications.Where(x => x.Stock == 0))
                        {
                            sw.WriteLine(MedicationToCsvRow(medication));
                        }
                    }
                }
            }
            else if (type == "PDF")
            {
                using (FileStream fs = new FileStream("report.pdf", FileMode.Create))
                {
                    PdfDocument doc = new PdfDocument(fs);

                    XFont font = new XFont("Verdana", 20);

                    var           dbContext = ConnectionFactory.GetDbContext("Pharmacy") as PharmacyDbContext;
                    StringBuilder sb        = new StringBuilder(String.Join(" - ", "Id", "Name", "Manufacturer", "Ingredients",
                                                                            "Price", "Last sold date") + Environment.NewLine);

                    foreach (var medication in dbContext.Medications.Where(x => x.Stock == 0))
                    {
                        sb.AppendLine(MedicationToCsvRow(medication, " - "));
                    }

                    PdfPage        page      = doc.AddPage();
                    XGraphics      graph     = XGraphics.FromPdfPage(page);
                    XTextFormatter formatter = new XTextFormatter(graph);
                    formatter.DrawString(sb.ToString(), font, XBrushes.Black,
                                         new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                    doc.Close();
                }
            }
        }
Esempio n. 21
0
        void IDrawingCanvas.DrawString(string value, FontInfo font, BrushEx brush, RectangleF rect, StringFormatEx format)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            XGraphicsContainer clipState = _graphics.BeginContainer();
            var xRect = PdfConverter.Convert(rect);
            var xFont = _fonts.GetPdfFont(font);

            _graphics.IntersectClip(xRect);
            var resultRect = _graphics.MeasureString(value, xFont, GetFormat(format));

            if ((format.WrapMode == WrapMode.NoWrap && !value.Contains('\n')) ||
                (resultRect.Width * PdfConverter.TwipsPerPoint <= rect.Width))
            {
                _graphics.DrawString(value, xFont, (BrushBase)brush, xRect, GetFormat(format));
                _graphics.EndContainer(clipState);
                return;
            }

            if (format.WrapMode == WrapMode.NoWrap && value.Contains('\n'))
            {
                var lines = value.Split('\n');
                var y     = xRect.Y;
                for (var i = 0; i < lines.Length; i++)
                {
                    var line = lines[i].Trim('\r');
                    _graphics.DrawString(line, xFont, (BrushBase)brush, new XRect(xRect.X, y, xRect.Width, resultRect.Height), GetFormat(format));
                    y += resultRect.Height;
                }
                _graphics.EndContainer(clipState);
                return;
            }

            // http://developer.th-soft.com/developer/2015/07/17/pdfsharp-improving-the-xtextformatter-class-measuring-the-height-of-the-text/
            // http://developer.th-soft.com/developer/2015/09/21/xtextformatter-revisited-xtextformatterex2-for-pdfsharp-1-50-beta-2/
            var tf = new XTextFormatter(_graphics)
            {
                Alignment = GetAlignment(format)
            };

            tf.DrawString(value, xFont, (BrushBase)brush, xRect);

            _graphics.EndContainer(clipState);
        }
Esempio n. 22
0
        void AddList(XGraphics gfx, PdfData pdfData)
        {
            int startingHeight = 200;
            int listItemHeight = 30;

            for (int i = 0; i < pdfData.DisplayListItems.Count; i++)
            {
                var            font = new XFont("OpenSans", 14, XFontStyle.Regular);
                XTextFormatter tf   = new XTextFormatter(gfx);
                XRect          rect = new XRect(60, startingHeight, 500, listItemHeight);
                gfx.DrawRectangle(XBrushes.White, rect);
                var data = $"{i}. {pdfData.DisplayListItems[i].Id} | {pdfData.DisplayListItems[i].Data1} | {pdfData.DisplayListItems[i].Data2}";
                tf.DrawString(data, font, XBrushes.Black, rect, XStringFormats.TopLeft);

                startingHeight = startingHeight + listItemHeight;
            }
        }
Esempio n. 23
0
        private void makePdf(TreeNodeCollection nodes, string filename)
        {
            List <string> s              = new List <string>();
            string        spaces         = "";
            int           indentLevel    = 0;
            int           maxIndentLevel = 5;

            var includeTransactions = this.includeTransactions.Checked;

            if (!includeTransactions)
            {
                maxIndentLevel = 2;
            }

            walkTree(nodes, spaces, ref s, indentLevel, maxIndentLevel);

            var pagesize      = 70;
            var numberOfPages = (int)(s.Count / pagesize) + 1;

            PdfDocument document     = new PdfDocument();
            XFont       categoryfont = new XFont("Arial", 8, XFontStyle.Bold);
            XFont       yearfont     = new XFont("Arial", 8, XFontStyle.Underline);
            XFont       font         = new XFont("Arial", 8, XFontStyle.Regular);

            for (var pageNum = 0; pageNum < numberOfPages; pageNum++)
            {
                var numberOfRows = pagesize;
                if (((pageNum * pagesize) + pagesize) > s.Count)
                {
                    numberOfRows = s.Count % pagesize;
                }
                string text = String.Join("\r\n", s.GetRange(pageNum * pagesize, numberOfRows));

                PdfPage        page = document.AddPage();
                XGraphics      gfx  = XGraphics.FromPdfPage(page);
                XTextFormatter tf   = new XTextFormatter(gfx);

                XRect rect = new XRect(20, 50, 550, 850);
                gfx.DrawRectangle(XBrushes.White, rect);
                tf.Alignment = XParagraphAlignment.Left;
                tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
            }

            document.Save(filename);
            Process.Start(filename);
        }
Esempio n. 24
0
        public void DrawAppearance(XGraphics gfx, XRect rect)
        {
            var backColor   = XColor.Empty;
            var defaultText = string.Format("Signed by: {0}\nLocation: {1}\nReason: {2}\nDate: {3}", Signer, Location, Reason, DateTime.Now);

            XFont font = new XFont("Verdana", 7, XFontStyle.Regular);

            XTextFormatter txtFormat = new XTextFormatter(gfx);

            var currentPosition = new XPoint(0, 0);

            txtFormat.DrawString(defaultText,
                                 font,
                                 new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black)),
                                 new XRect(currentPosition.X, currentPosition.Y, rect.Width - currentPosition.X, rect.Height),
                                 XStringFormats.TopLeft);
        }
Esempio n. 25
0
        public void GeneratePDF(string title, string content)
        {
            //PDF-et generál
            PdfDocument pdf = new PdfDocument();

            pdf.Info.Title = title;
            PdfPage        pdfPage = pdf.AddPage();
            XGraphics      graph   = XGraphics.FromPdfPage(pdfPage);
            XFont          font    = new XFont("Verdana", 13, XFontStyle.Bold);
            XTextFormatter tf      = new XTextFormatter(graph);

            tf.DrawString(content, font, XBrushes.Black, new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
            string pdfFilename = "firstpage.pdf";

            pdf.Save(pdfFilename);
            Process.Start(pdfFilename);
        }
Esempio n. 26
0
        private void CreateTable(PdfPage page, DataTable dt, XGraphics gfx, XStringFormat format, double lineHeight, int marginLeft, int marginTop, int el_height, int el_width)
        {
            //how the printed output would looklike/ gui design for table
            XFont font = new XFont("Verdana", 10, XFontStyle.Bold);

            var tf = new XTextFormatter(gfx);

            int rect_height = 13;

            double gridwidth = page.Width - (marginLeft * 2);

            XSolidBrush rect_style1 = new XSolidBrush(XColors.MidnightBlue);
            XSolidBrush rect_style2 = new XSolidBrush(XColors.LightGray);
            XSolidBrush rect_style3 = new XSolidBrush(XColors.DarkGray);

            //creating the rows and columns
            for (int i = 0; i <= dt.Rows.Count; i++)
            {
                if (i == 0)
                {
                    gfx.DrawRectangle(rect_style1, marginLeft, marginTop, gridwidth, rect_height);
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        tf.DrawString(dt.Columns[j].ColumnName, font, XBrushes.White, new XRect(((gridwidth / dt.Columns.Count) * (j + 1)) - el_width, marginTop, (gridwidth / dt.Columns.Count), el_height), format);
                    }
                }
                else
                {
                    var row = dt.Rows[i - 1] as DataRow;

                    if ((i - 1) % 2 == 1)
                    {
                        gfx.DrawRectangle(rect_style2, marginLeft, marginTop + (rect_height * i) + (i - 1), gridwidth, rect_height);
                    }
                    else
                    {
                        gfx.DrawRectangle(rect_style3, marginLeft, marginTop + (rect_height * i) + (i - 1), gridwidth, rect_height);
                    }

                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        tf.DrawString(row[dt.Columns[j].ColumnName].ToString(), font, XBrushes.White, new XRect(((gridwidth / dt.Columns.Count) * (j + 1)) - el_width, marginTop + (rect_height * i + 1) + i, (gridwidth / dt.Columns.Count), el_height), format);
                    }
                }
            }
        }
Esempio n. 27
0
            public void DrawAppearance(XGraphics gfx, XRect rect)
            {
                XColor         empty          = XColor.Empty;
                string         text           = "Signed by Napoleon \nLocation: Paris \nDate: " + DateTime.Now.ToString();
                XFont          font           = new XFont("Verdana", 7.0, XFontStyle.Regular);
                XTextFormatter xTextFormatter = new XTextFormatter(gfx);
                int            num            = this.Image.PixelWidth / this.Image.PixelHeight;
                XPoint         xPoint         = new XPoint(0.0, 0.0);
                bool           flag           = this.Image != null;

                if (flag)
                {
                    gfx.DrawImage(this.Image, xPoint.X, xPoint.Y, rect.Width / 4.0, rect.Width / 4.0 / (double)num);
                    xPoint = new XPoint(rect.Width / 4.0, 0.0);
                }
                xTextFormatter.DrawString(text, font, new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black)), new XRect(xPoint.X, xPoint.Y, rect.Width - xPoint.X, rect.Height), XStringFormats.TopLeft);
            }
Esempio n. 28
0
        static public string exportPDF(string filename)
        {
            List <UsuarioPropuesto> usuarios = obtener(new Sector()
            {
                id = 0
            }, 20, 1, puestoFijo: false);

            PdfDocument document = new PdfDocument();

            document.Info.Title = "aWords";

            XFont fontTitle   = new XFont("Verdana", 20, XFontStyle.Bold);
            XFont fontSubject = new XFont("Verdana", 12, XFontStyle.Italic);
            XFont fontBody    = new XFont("Verdana", 14, XFontStyle.Regular);

            foreach (UsuarioPropuesto user in usuarios)
            {
                PdfPage        page = document.AddPage();
                XGraphics      gfx  = XGraphics.FromPdfPage(page);
                XTextFormatter tf   = new XTextFormatter(gfx);
                XRect          rect = new XRect(40, 40, page.Width, page.Height);

                tf.DrawString($"{user.apellido}, {user.nombre} ", fontTitle, XBrushes.Black, rect, XStringFormats.TopLeft);
                tf.DrawString($"{SectorManager.obtener(user).nombre} - {PuestoManager.obtener(user).nombre}", fontSubject, XBrushes.Black,
                              new XRect(40, 65, page.Width, page.Height), XStringFormats.TopLeft);

                tf.DrawString($"Porcentaje objetivos cumplidos: {user.porcentajeObjetivosCumplidos} " +
                              $"\n" +
                              $"Promedio de nivel objetivos cumplidos: {user.promedioDeNivelObjetivosCumplidos}" +
                              $"\n" +
                              $"Cantidad objetivos no cumplidos: {user.cantidadObjetivosNoCumplidos}" +
                              $"\n" +
                              $"Promedio reconocimientos de superiores: {user.promedioReconocimientosDeSuperiores}" +
                              $"\n" +
                              $"Cantidad reconocimientos: {user.cantidadReconocimientos}" +
                              $"\n" +
                              $"Promedio nivel reconocimiento: {user.promedioNivelReconocimiento}" +
                              $"\n" +
                              $"Valor estadistico: {user.valorEstadistico}", fontBody, XBrushes.Black,
                              new XRect(40, 90, page.Width, page.Height), XStringFormats.TopLeft);
            }

            document.Save(filename);

            return(filename);
        }
Esempio n. 29
0
 private static void DrawOcrTextOnPage(PdfPage page, OcrResult ocrResult)
 {
     using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend))
     {
         var tf = new XTextFormatter(gfx);
         foreach (var element in ocrResult.Elements)
         {
             var adjustedBounds = AdjustBounds(element.Bounds, (float)page.Width / ocrResult.PageBounds.Width, (float)page.Height / ocrResult.PageBounds.Height);
             var adjustedFontSize = CalculateFontSize(element.Text, adjustedBounds, gfx);
             var font = new XFont("Times New Roman", adjustedFontSize, XFontStyle.Regular,
                 new XPdfFontOptions(PdfFontEncoding.Unicode));
             var adjustedHeight = gfx.MeasureString(element.Text, font).Height;
             var verticalOffset = (adjustedBounds.Height - adjustedHeight) / 2;
             adjustedBounds.Offset(0, (float)verticalOffset);
             tf.DrawString(ocrResult.RightToLeft ? ReverseText(element.Text) : element.Text, font, XBrushes.Transparent, adjustedBounds);
         }
     }
 }
Esempio n. 30
0
        /// <summary>
        /// Funkcja interfejsu renderująca obiekt
        /// </summary>
        /// <param name="page">obiekt aktualnej strony</param>
        /// <param name="gfx">kontekst graficzny</param>
        /// <param name="FlexCoords"></param>
        public void Render(PdfPage page, XGraphics gfx, XPoint?FlexCoords = null)
        {
            if (FlexCoords != null && !IsFixed)
            {
                _coords = (XPoint)FlexCoords;
            }

            XRect rect = new XRect(_coords, new XSize(width, height));

            X = rect.X;
            Y = rect.Y;
            XTextFormatter tf = new XTextFormatter(gfx)
            {
                Alignment = _align
            };

            tf.DrawString(_text, _font, (_brush ?? XBrushes.Black), rect, XStringFormats.TopLeft);
        }