Represents a drawing surface (or canvas) for a fixed size page.
Inheritance: IDisposable
示例#1
2
        public static bool Genereer(Deelnemer deelnemer, DeelnemerVerhuisd deelnemerVerhuisd)
        {
            _deelnemer = deelnemer;
            _event = deelnemerVerhuisd;

            // start pdf document
            _document = new PdfDocument();
            _document.Info.Title = "Verhuisbrief " + _deelnemer.Naam;
            _document.Info.Author = "Verhuisbrief Generator";

            // voeg pagina toe
            _page = _document.AddPage();
            _gfx = XGraphics.FromPdfPage(_page);

            // vul pagina
            PlaatsLogo();
            PlaatsTitel();
            PlaatsNAWGegevens();
            PlaatsInhoud();

            // sla document op
            SlaPdfOp();

            return true;
        }
示例#2
1
    /// <summary>
    /// Draws simple lines.
    /// </summary>
    void RenderLines(XGraphics gfx)
    {
      gfx.TranslateTransform(15, 20);

      gfx.DrawLine(XPens.Red, new XPoint(10, 10), new XPoint(300, 300));

      gfx.DrawLine(XPens.DarkGreen, 0, 0, 250, 0);

      gfx.DrawLine(XPens.Gold, 15, 7, 230, 15);

      XPen pen = new XPen(XColors.Navy, 4);
      gfx.DrawLine(pen, 0, 20, 250, 20);

      pen = new XPen(XColors.Firebrick, 6);
      pen.DashStyle = XDashStyle.Dash;
      gfx.DrawLine(pen, 0, 40, 250, 40);
      pen.Width = 7.3;
      pen.DashStyle = XDashStyle.DashDotDot;
      gfx.DrawLine(pen, 0, 60, 250, 60);

      pen = new XPen(XColors.Goldenrod, 10);
      pen.LineCap = XLineCap.Flat;
      gfx.DrawLine(pen, 10, 90, 240, 90);
      gfx.DrawLine(XPens.Black, 10, 90, 240, 90);

      pen = new XPen(XColors.Goldenrod, 10);
      pen.LineCap = XLineCap.Square;
      gfx.DrawLine(pen, 10, 110, 240, 110);
      gfx.DrawLine(XPens.Black, 10, 110, 240, 110);

      pen = new XPen(XColors.Goldenrod, 10);
      pen.LineCap = XLineCap.Round;
      gfx.DrawLine(pen, 10, 130, 240, 130);
      gfx.DrawLine(XPens.Black, 10, 130, 240, 130);
    }
示例#3
1
    /// <summary>
    /// Draws a clock on a square page.
    /// Inspired by Charles Petzold's AnalogClock sample in
    /// 'Programming Microsoft Windows with C#'.
    /// </summary>
    void RenderClock(XGraphics gfx)
    {
      // Clocks should always look happy on hardcopies...
      //this.time = new DateTime(2005, 1, 1, 11, 6, 22, 500);

      XColor strokeColor = XColors.DarkBlue;
      XColor fillColor = XColors.DarkOrange;

      XPen pen = new XPen(strokeColor, 5);
      XBrush brush = new XSolidBrush(fillColor);

      strokeColor.A = 0.8;
      fillColor.A = 0.8;
      XPen handPen = new XPen(strokeColor, 5);
      XBrush handBrush = new XSolidBrush(fillColor);

      DrawText(gfx, pen, brush);

      double width = gfx.PageSize.Width;
      double height = gfx.PageSize.Height;
      gfx.TranslateTransform(width / 2, height / 2);
      double scale = Math.Min(width, height);
      gfx.ScaleTransform(scale / 2000);

      DrawFace(gfx, pen, brush);
      DrawHourHand(gfx, handPen, handBrush);
      DrawMinuteHand(gfx, handPen, handBrush);
      DrawSecondHand(gfx, new XPen(XColors.Red, 7));
    }
    /// <summary>
    /// Draws simple lines.
    /// </summary>
    void DrawLine(XGraphics gfx, int number)
    {
      BeginBox(gfx, number, "DrawLine");

      gfx.DrawLine(XPens.DarkGreen, 0, 0, 250, 0);

      gfx.DrawLine(XPens.Gold, 15, 7, 230, 15);

      XPen pen = new XPen(XColors.Navy, 4);
      gfx.DrawLine(pen, 0, 20, 250, 20);

      pen = new XPen(XColors.Firebrick, 6);
      pen.DashStyle = XDashStyle.Dash;
      gfx.DrawLine(pen, 0, 40, 250, 40);
      pen.Width = 7.3;
      pen.DashStyle = XDashStyle.DashDotDot;
      gfx.DrawLine(pen, 0, 60, 250, 60);

      pen = new XPen(XColors.Goldenrod, 10);
      pen.LineCap = XLineCap.Flat;
      gfx.DrawLine(pen, 10, 90, 240, 90);
      gfx.DrawLine(XPens.Black, 10, 90, 240, 90);

      pen = new XPen(XColors.Goldenrod, 10);
      pen.LineCap = XLineCap.Square;
      gfx.DrawLine(pen, 10, 110, 240, 110);
      gfx.DrawLine(XPens.Black, 10, 110, 240, 110);

      pen = new XPen(XColors.Goldenrod, 10);
      pen.LineCap = XLineCap.Round;
      gfx.DrawLine(pen, 10, 130, 240, 130);
      gfx.DrawLine(XPens.Black, 10, 130, 240, 130);

      EndBox(gfx);
    }
 public Export_to_Pdf()
 {
     InitializeComponent();
     //Create object for pdf.
     document = new PdfDocument();
     page = document.AddPage();
     gfx = XGraphics.FromPdfPage(page);
     //Set by default values.
     font = new XFont("Arial", 12, XFontStyle.Regular);
     header_font = new XFont("Arial", 12, XFontStyle.Regular);
     page.Size = PageSize.A4;
     page.Orientation = PageOrientation.Portrait;
     //////////////////////////////////////////////////////////////////////
     //Create a fake questionanire to test the print process to pdf.
     if (questionaire != null)
     {
         List<Question> question_list = new List<Question>();
         List<Answer> answer_list = new List<Answer>();
         Answer ans = new Answer();
         ans.Answer_descr = "einai to dsfgdsfgsd";
         answer_list.Add(ans);
         answer_list.Add(ans);
         answer_list.Add(ans);
         Question quest = new Question() { AnswerList = answer_list };
         quest.Question_descr = "H ekfoonisi tis erotisis aytis einai blablbalbablbalblab";
         for (int i = 0; i < 10; i++)
         {
             question_list.Add(quest);
         }
     questionaire = new Quastionnaire.Model.Questionaire() { Questionaire_descr = "sdfsakdfjdflshsadflkjashflasdfkh", QuestionList = question_list };
     }
     //////////////////////////////////////////////////////////////////////
 }
示例#6
0
    void RenderMeasureText(XGraphics gfx)
    {
      gfx.TranslateTransform(15, 20);

      XFontStyle style = XFontStyle.Regular;
      XFont font = new XFont("Times New Roman", 95, style);

      string text = "Hello";
      double x = 20, y = 100;
      XSize size = gfx.MeasureString(text, font);

      double lineSpace = font.GetHeight(gfx);
      int cellSpace = font.FontFamily.GetLineSpacing(style);
      int cellAscent = font.FontFamily.GetCellAscent(style);
      int cellDescent = font.FontFamily.GetCellDescent(style);
      int cellLeading = cellSpace - cellAscent - cellDescent;

      // Get effective ascent
      double ascent = lineSpace * cellAscent / cellSpace;
      gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent);

      // Get effective descent
      double descent = lineSpace * cellDescent / cellSpace;
      gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent);

      // Get effective leading
      double leading = lineSpace * cellLeading / cellSpace;
      gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading);

      // Draw text half transparent
      XColor color = XColors.DarkSlateBlue;
      color.A = 0.6;
      gfx.DrawString(text, font, new XSolidBrush(color), x, y);
    }
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);
      DrawGridlines(gfx);

      // Create a new graphical path
      XGraphicsPath path = new XGraphicsPath();

      XSize size = new XSize(90, 140);
      double rotationAngle = 130;

      path.AddArc(new XPoint(100, 100), new XPoint(200, 200), size, rotationAngle, false, System.Windows.Media.SweepDirection.Clockwise);
      path.StartFigure();
      path.AddArc(new XPoint(400, 100), new XPoint(500, 200), size, rotationAngle, false, System.Windows.Media.SweepDirection.Counterclockwise);
      path.StartFigure();
      path.AddArc(new XPoint(100, 300), new XPoint(200, 400), size, rotationAngle, true, System.Windows.Media.SweepDirection.Clockwise);
      path.StartFigure();
      path.AddArc(new XPoint(400, 300), new XPoint(500, 400), size, rotationAngle, true, System.Windows.Media.SweepDirection.Counterclockwise);
      path.StartFigure();

#if DEBUG_
      gfx.WriteComment("PathArcSegment");
#endif
      gfx.DrawPath(XPens.Red, path);
    }
示例#8
0
        public static byte[] AppendImageToPdf(byte[] pdf, byte[] img, Point position, double scale)
        {
            using (System.IO.MemoryStream msPdf = new System.IO.MemoryStream(pdf))
            {
                using (System.IO.MemoryStream msImg = new System.IO.MemoryStream(img))
                {
                    System.Drawing.Image       image    = System.Drawing.Image.FromStream(msImg);
                    PdfSharp.Pdf.PdfDocument   document = PdfSharp.Pdf.IO.PdfReader.Open(msPdf);
                    PdfSharp.Pdf.PdfPage       page     = document.Pages[0];
                    PdfSharp.Drawing.XGraphics gfx      = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
                    PdfSharp.Drawing.XImage    ximg     = PdfSharp.Drawing.XImage.FromGdiPlusImage(image);

                    gfx.DrawImage(
                        ximg,
                        position.X,
                        position.Y,
                        ximg.Width * scale,
                        ximg.Height * scale
                        );

                    using (System.IO.MemoryStream msFinal = new System.IO.MemoryStream())
                    {
                        document.Save(msFinal);
                        return(msFinal.ToArray());
                    }
                }
            }
        }
示例#9
0
 internal Renderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
 {
     this.documentObject = renderInfo.DocumentObject;
     this.gfx = gfx;
     this.renderInfo = renderInfo;
     this.fieldInfos = fieldInfos;
 }
示例#10
0
        public void Draw(XGraphics gfx)
        {
            gfx.DrawRectangle(Pen, Brush, Rect);

            double yOffset = 5;

            //Print InputBox Title, Left Top corner
            if (!string.IsNullOrEmpty(Title))
            {
                var titleLabel = new Label(Rect.X + 5, Rect.Y, Title)
                    {
                        Brush = XBrushes.Black,
                        Font = new XFont(Font.FontFamily.Name, 8, XFontStyle.Bold, Font.PdfOptions),
                        Pen = XPens.Black
                    };
                titleLabel.Draw(gfx);
                yOffset = 15;
            }

            //Print InputBox Value
            if (!string.IsNullOrEmpty(Value))
            {
                var valLabel = new Label(new XRect(Rect.X + 10, Rect.Y + yOffset, Rect.Width, Rect.Height), Value)
                    {
                        Alignment = XParagraphAlignment.Left,
                        Brush = XBrushes.Black,
                        Font = new XFont(Font.FontFamily.Name, 12, XFontStyle.Regular, Font.PdfOptions),
                        Pen = XPens.Black,
                    };
                valLabel.Draw(gfx);
                yOffset += valLabel.Rect.Height;
            }
        }
示例#11
0
 internal void Format(XGraphics gfx)
 {
     _gfx = gfx;
     _isFirstArea = true;
     _formatter = new TopDownFormatter(this, _documentRenderer, TextArea.Elements);
     _formatter.FormatOnAreas(gfx, false);
 }
示例#12
0
        public void Create(string filename, int qcount, int cellsinq, List<string> cellslabels,int rowscount)
        {
            s_document = new PdfDocument();

            _page = new PdfPage();
            _page.Orientation = PageOrientation.Landscape;
            _page.Size = PageSize.A4;
            s_document.Pages.Add(_page);
            gfx = XGraphics.FromPdfPage(_page);

            DrawCenterMarker(7);

            DrawSideMarker(7, 10, 10);
            DrawSideMarker(7, 285, 10);
            DrawSideMarker(7, 10, 200);
            DrawSideMarker(7, 285, 200);

            AddFields();

            AddQuestions(qcount,cellsinq,cellslabels,rowscount);

            // Save the s_document...
            s_document.Save(filename);
            // ...and start a viewer
            Process.Start(filename);
        }
示例#13
0
    /// <summary>
    /// Demonstrates the use of XGraphics.DrawRoundedRectangle.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      // Stroke ellipse
      gfx.DrawEllipse(properties.Pen1.Pen, 50, 100, 450, 150);

      // Fill ellipse
      gfx.DrawEllipse(properties.Brush2.Brush, new Rectangle(50, 300, 450, 150));

      // Stroke and fill ellipse
      gfx.DrawEllipse(properties.Pen2.Pen, properties.Brush2.Brush, new RectangleF(50, 500, 450, 150));

      // Stroke circle
      gfx.DrawEllipse(properties.Pen2.Pen, new XRect(100, 200, 400, 400));

#if DEBUG
      int count = 360;
      XPoint[] circle = new XPoint[count];
      for (int idx = 0; idx < count; idx++)
      {
        double rad = idx * 2 * Math.PI / count;
        circle[idx].X = Math.Cos(rad) * 200 + 300;
        circle[idx].Y = Math.Sin(rad) * 200 + 400;
      }
      gfx.DrawPolygon(properties.Pen3.Pen, circle);
#endif
    }
示例#14
0
 public virtual void RenderPage(XGraphics gfx)
 {
   //Debug.WriteLine("RenderPage");
   gfx.Clear(this.properties.General.BackColor.Color);
   //DrawGridlines(gfx);
   gfx.SmoothingMode = XSmoothingMode.AntiAlias;
 }
示例#15
0
        public override void Render(ref PdfSharp.Drawing.XGraphics gfx, double offsetLeft, double offsetTop, double scaleX, double scaleY)
        {
            PreRender(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
            XRect rectangle = new XRect(
                Util.MillimeterToPoint(offsetLeft + Left),
                Util.MillimeterToPoint(offsetTop + Top),
                Util.MillimeterToPoint(Width * scaleX),
                Util.MillimeterToPoint(Height * scaleY));

            if (BindingOption == SpecialBinding.PageNumber)
            {
                PrintableComponent pc = Parent;
                while (pc != null && !(pc is PrintablePage))
                {
                    pc = pc.Parent;
                }

                if (pc != null)
                {
                    text = ((PrintablePage)pc).PageNumber.ToString();
                }
            }

            if (text != null && text != "Null")
            {
                XTextFormatter xtf = new XTextFormatter(gfx);
                xtf.Alignment = Style.FontAlignment;

                xtf.DrawString(text, Style.AsXFont(), (XBrush) new SolidBrush(Style.PrimaryColor), rectangle);
            }
            base.Render(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
        }
示例#16
0
 internal ShapeRenderer(XGraphics gfx, Shape shape, FieldInfos fieldInfos)
     : base(gfx, shape, fieldInfos)
 {
     this.shape = shape;
       LineFormat lf = (LineFormat)this.shape.GetValue("LineFormat", GV.ReadOnly);
       this.lineFormatRenderer = new LineFormatRenderer(lf, gfx);
 }
示例#17
0
    public override void RenderPage(XGraphics gfx)
    {
      //base.RenderPage(gfx);

      XTextFormatter tf = new XTextFormatter(gfx);
      XRect rect;
      string text = this.properties.Font1.Text;
      //text = "First\nSecond Line\nlaksdjf 234 234";

      rect = new XRect(40, 100, 250, 200);
      gfx.DrawRectangle(XBrushes.SeaShell, rect);
      //tf.Alignment = ParagraphAlignment.Left;
      tf.DrawString(text, this.properties.Font1.Font, this.properties.Font1.Brush, 
        rect, XStringFormats.TopLeft);

      rect = new XRect(310, 100, 250, 200);
      gfx.DrawRectangle(XBrushes.SeaShell, rect);
      tf.Alignment = XParagraphAlignment.Right;
      tf.DrawString(text, this.properties.Font1.Font, this.properties.Font1.Brush,
        rect, XStringFormats.TopLeft);

      rect = new XRect(40, 400, 250, 200);
      gfx.DrawRectangle(XBrushes.SeaShell, rect);
      tf.Alignment = XParagraphAlignment.Center;
      tf.DrawString(text, this.properties.Font1.Font, this.properties.Font1.Brush,
        rect, XStringFormats.TopLeft);

      rect = new XRect(310, 400, 250, 200);
      gfx.DrawRectangle(XBrushes.SeaShell, rect);
      tf.Alignment = XParagraphAlignment.Justify;
      tf.DrawString(text, this.properties.Font1.Font, this.properties.Font1.Brush,
        rect, XStringFormats.TopLeft);
    }
示例#18
0
    void Box2(XGraphics gfx, RectangleF rect, float startAngle, float sweepAngle)
    {
      float xc = rect.X + rect.Width / 2;
      float yc = rect.Y + rect.Height / 2;
      double a = startAngle * 0.0174532925199433;
      double b = (startAngle + sweepAngle) * 0.0174532925199433;

      gfx.DrawRectangle(XPens.Black, rect);

      for (float deg = 0; deg < 360; deg += 10)
        gfx.DrawLine(XPens.Yellow, xc, yc, 
          (float)(xc + rect.Width * Math.Cos(deg * 0.0174532925199433)), 
          (float)(yc + rect.Height * Math.Sin(deg * 0.0174532925199433)));

      //if (rect.Width == rect.Height)
      //{
      //  float f = Math.Max(rect.Width / 2, rect.Height / 2);
      //  for (float deg = 0; deg < 360; deg += 10)
      //    gfx.DrawLine(XPens.Goldenrod, xc, yc, 
      //      (float)(xc + f * Math.Cos(deg * 0.0174532925199433)), 
      //      (float)(yc + f * Math.Sin(deg * 0.0174532925199433)));
      //}
      //gfx.DrawLine(XPens.PaleGreen, xc, rect.Y, xc, rect.Y + rect.Height);
      //gfx.DrawLine(XPens.PaleGreen, rect.X, yc, rect.X + rect.Width, yc);
      gfx.DrawLine(XPens.DarkGray, xc, yc, (float)(xc + rect.Width / 2 * Math.Cos(a)), (float)(yc + rect.Height / 2 * Math.Sin(a)));
      gfx.DrawLine(XPens.DarkGray, xc, yc, (float)(xc + rect.Width / 2 * Math.Cos(b)), (float)(yc + rect.Height / 2 * Math.Sin(b)));
    }
示例#19
0
    public void Arc(XGraphics gfx, RectangleF rect, float startAngle, float sweepAngle)
    {
      RectangleF rect2 = RectangleF.Inflate(rect, rect.Width, 0);
      Box2(gfx, rect2, startAngle, sweepAngle);
      Box1(gfx, rect, startAngle, sweepAngle);
      //Box(gfx, rect, startAngle, sweepAngle);
      gfx.DrawArc(properties.Pen2.Pen, rect, startAngle, sweepAngle);
      gfx.DrawArc(properties.Pen3.Pen, rect2, 0, 90);
      gfx.DrawArc(properties.Pen2.Pen, rect2, startAngle, sweepAngle);

      float delta = (float)(Math.PI / 360);
      float rx = rect2.Width / 2;
      float ry = rect2.Height / 2;
      float dx = rect2.X + rx;
      float dy = rect2.Y + ry;
      for (float rad = 0; rad < Math.PI * 2; rad += delta)
      {
        gfx.DrawLine(XPens.LawnGreen, (float)(dx + rx * Math.Cos(rad)), (float)(dy + ry * Math.Sin(rad)), 
          (float)(dx + rx * Math.Cos(rad + delta)), (float)(dy + ry * Math.Sin(rad + delta)));
      }

      double gamma1 = (ry * Math.Cos(20 * 0.0174532925199433)) / (rx * Math.Sin(20 * 0.0174532925199433));
      gamma1 = Math.Atan(gamma1);
      gamma1 = 90 - gamma1 / 0.0174532925199433;
      double gamma2 = (ry * Math.Cos(70 * 0.0174532925199433)) / (rx * Math.Sin(70 * 0.0174532925199433));
      gamma2 = Math.Atan(gamma2);
      gamma2 = 90 - gamma2 / 0.0174532925199433 - gamma1;
      gfx.DrawArc(XPens.Black, rect2, (float)gamma1, (float)gamma2);
    }
示例#20
0
        public override void Render(ref PdfSharp.Drawing.XGraphics gfx, double offsetLeft, double offsetTop, double scaleX, double scaleY)
        {
            PreRender(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
            if (SourceImage != null)
            {
                double widthScale  = (Width * scaleX) / SourceImage.Width;
                double heightScale = (Height * scaleY) / SourceImage.Height;

                double scale = Math.Min(widthScale, heightScale);

                double width  = SourceImage.Width * scale;
                double height = SourceImage.Height * scale;

                double offsetLeftImage = ((Width * scaleX) - width) / 2.0;
                double offsetTopImage  = ((Height * scaleY) - height) / 2.0;

                gfx.DrawImage(SourceImage,
                              Util.MillimeterToPoint(offsetLeft + Left + offsetLeftImage),
                              Util.MillimeterToPoint(offsetTop + Top + offsetTopImage),
                              Util.MillimeterToPoint(width),
                              Util.MillimeterToPoint(height));
            }
            else
            {
                gfx.DrawRectangle(XBrushes.White, new Rectangle(
                                      (int)Util.MillimeterToPoint(offsetLeft + Left),
                                      (int)Util.MillimeterToPoint(offsetTop + Top),
                                      (int)Util.MillimeterToPoint(Width * scaleX),
                                      (int)Util.MillimeterToPoint(Height * scaleY)));
            }

            base.Render(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
        }
示例#21
0
 public StringObject(XGraphics graphics, string text, XFont font)
 {
     this.graphics = graphics;
       Text = text;
       Font = font;
       Brush = Brushes.Black;
 }
示例#22
0
    public override void RenderPage(XGraphics gfx)
    {
      //base.RenderPage(gfx);

      XFont font1 = new XFont("Arial", 9);
      XFont font2 = new XFont("Arial", 9, XFontStyle.Italic);
      XFont font3 = new XFont("Arial", 9, XFontStyle.Bold);
      XSolidBrush brush = new XSolidBrush(XColors.Black);

      gfx.DrawString("Page 5", font1, brush, 100, 100);
      gfx.DrawString("Water Sports You've Done continued", font2, brush, 100, 200);
      gfx.DrawString("Rowing", font1, brush, 100, 250);
      gfx.DrawString("Snorkeling", font1, brush, 100, 300);
      gfx.DrawString("WINTER SPORTS, SKIING, SKIING IN THE US", font3, XBrushes.Red, 100, 320);

      gfx.DrawLine(XPens.Red, 100, 100, 200, 200);

      gfx.DrawString("Resorts You've Skied in Vermont", font3, brush, 100, 400);
      gfx.DrawString("Haystack", font1, brush, 100, 420);

//      string text = "TgfÄÖÜWi9";
//      if (this.properties.Font1.Text != "")
//        text = this.properties.Font1.Text;
//      float x = 100, y = 300;
//      string familyName = properties.Font1.FamilyName;
//      XFontStyle style = this.properties.Font1.Style;
//      float emSize = this.properties.Font1.Size;
//      XFont font = CreateFont(familyName, emSize, style);
//      font = this.properties.Font1.Font;
//      XSize size = gfx.MeasureString(text, font);

//      double lineSpace = font.GetHeight(gfx);
//      int cellSpace   = font.FontFamily.GetLineSpacing(style);
//      int cellAscent  = font.FontFamily.GetCellAscent(style);
//      int cellDescent = font.FontFamily.GetCellDescent(style);
//      int cellLeading = cellSpace - cellAscent - cellDescent;

//      double ascent  = lineSpace * cellAscent / cellSpace;
//      gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent);

//      double descent = lineSpace * cellDescent / cellSpace;
//      gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent);

//      double leading = lineSpace * cellLeading / cellSpace;
//      gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading);

//      //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height);
//      //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y);
//      //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200);

//#if true_
//      XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true);
//      font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions);
//      text = "Hallo";
//      text = chinese;
//#endif
//      gfx.DrawString(text, font, this.properties.Font1.Brush, x, y);
//      gfx.DrawLine(XPens.Red, 0, 0, 100, 100);
//      gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20);
    }
示例#23
0
 public override void Visit(ExportPage page)
 {
     PdfPage = pdfDocument.AddPage();
     xGraphics = XGraphics.FromPdfPage(PdfPage);
     textFormatter  = new XTextFormatter(xGraphics);
     base.Visit(page);
 }
示例#24
0
    void Box(XGraphics gfx, XRect rect, double startAngle, double sweepAngle)
    {
      double xc = rect.X + rect.Width / 2;
      double yc = rect.Y + rect.Height / 2;
      double a = startAngle * 0.0174532925199433;
      double b = (startAngle + sweepAngle) * 0.0174532925199433;

      XGraphicsState state = gfx.Save();
      gfx.IntersectClip(rect);


#if true
#if true_
      for (double deg = 0; deg < 360; deg += 10)
        gfx.DrawLine(XPens.Yellow, xc, yc, 
          (xc + rect.Width / 2 * Math.Cos(deg * 0.0174532925199433)), 
          (yc + rect.Height / 2 * Math.Sin(deg * 0.0174532925199433)));
#endif
      double f = Math.Max(rect.Width / 2, rect.Height / 2);
      for (double deg = 0; deg < 360; deg += 10)
        gfx.DrawLine(XPens.Goldenrod, xc, yc, 
          (xc + f * Math.Cos(deg * 0.0174532925199433)), 
          (yc + f * Math.Sin(deg * 0.0174532925199433)));

      gfx.DrawLine(XPens.PaleGreen, xc, rect.Y, xc, rect.Y + rect.Height);
      gfx.DrawLine(XPens.PaleGreen, rect.X, yc, rect.X + rect.Width, yc);
      //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(a)), (yc + rect.Height / 2 * Math.Sin(a)));
      //gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(b)), (yc + rect.Height / 2 * Math.Sin(b)));
#endif
      gfx.Restore(state);
      gfx.DrawRectangle(properties.Pen1.Pen, rect);
    }
示例#25
0
    /// <summary>
    /// Demonstrates the use of XGraphics.Transform.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      //gfx.Clear(this.properties.General.BackColor.Color);
      base.RenderPage(gfx);

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));

      Matrix matrix = new Matrix();
      //matrix.Scale(2f, 1.5f);
      //matrix.Translate(-200, -400);
      //matrix.Rotate(45);
      //matrix.Translate(200, 400);
      //gfx.Transform = matrix;
      //gfx.TranslateTransform(50, 30);

#if true
      gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
      gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
      gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
      gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
      bool id = matrix.IsIdentity;
      matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
      //matrix.Translate(30, -50);
      matrix.Rotate(15, MatrixOrder.Prepend);
      //Matrix mtx = gfx.Transform.ToGdiMatrix();
      //gfx.Transform = matrix;

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));
    }
示例#26
0
    /// <summary>
    /// Demonstrates the use of XGraphics.DrawArc.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      double width = 230;
      double height = width / 2;
      //width  = 150;
      //height = 150;
#if true
      Arc(gfx, new XRect(50, 50, width, height), 10, 90);
      Arc(gfx, new XRect(320, 50, width, height), 10, -90);
      Arc(gfx, new XRect(50, 250, width, height), 90, 170);
      Arc(gfx, new XRect(320, 250, width, height), 80, 90);
      Arc(gfx, new XRect(50, 450, width, height), -30, 110);
      Arc(gfx, new XRect(320, 450, width, height), 15, 260);
      Arc(gfx, new XRect(50, 650, width, height), 20, -150);
      Arc(gfx, new XRect(320, 650, width, height), 110, -360);
#else
      int d = -320;
      Arc(gfx, new XRect(50, 50, width, height),    30, d);
      Arc(gfx, new XRect(320, 50, width, height),  120, d);
      Arc(gfx, new XRect(50, 250, width, height),  220, d);
      Arc(gfx, new XRect(320, 250, width, height), 310, d);

//      Arc(gfx, new XRect(50, 50, width, height),    90,  -90);
//      Arc(gfx, new XRect(320, 50, width, height),  180, -90);
//      Arc(gfx, new XRect(50, 250, width, height),  270, -90);
//      Arc(gfx, new XRect(320, 250, width, height), 360,  -90);

      Arc(gfx, new XRect(50, 450, width, height), -30, 30);
      Arc(gfx, new XRect(320, 450, width, height), 120, -25);
      Arc(gfx, new XRect(50, 650, width, height),  -140,  15);
      Arc(gfx, new XRect(320, 650, width, height),  140,  15);
#endif
    }
示例#27
0
 internal void Format(XGraphics gfx)
 {
   this.gfx = gfx;
   this.formatter = new TopDownFormatter(this, this.documentRenderer, this.cell.Elements);
   this.formatter.FormatOnAreas(gfx, false);
   this.contentHeight = CalcContentHeight(this.documentRenderer);
 }
示例#28
0
 internal Renderer(XGraphics gfx, RenderInfo renderInfo, FieldInfos fieldInfos)
 {
     _documentObject = renderInfo.DocumentObject;
     _gfx = gfx;
     _renderInfo = renderInfo;
     _fieldInfos = fieldInfos;
 }
示例#29
0
        /// <summary>
        /// Draws the Table Control. Will not draw, if height lower than table head height
        /// </summary>
        /// <param name="gfx">The GFX.</param>
        /// <param name="startY">The start Y. Relative to table</param>
        /// <param name="height">The height. Relative to table</param>
        public void Draw(XGraphics gfx, double startY, double height)
        {
            if (startY < 0 || height < 0)
            {
                throw new ArgumentException("Wrong Y range spefified");
            }

            List<IContainerControl> rows = Rows.Where(r => (r.Rect.Y + r.Rect.Height) <= startY + height).ToList();

            //Cannot draw lower table than header or Nothing to draw
            if (height < _headHight || !rows.Any())
            {
                Rect = new XRect(Rect.X, Rect.Y, Rect.Width, 0);
                return;
            }

            rows.InsertRange(0, HeadRows.Clone());
            double curentHeight = rows.Select(x => x.Rect.Height).Sum();

            Rect = new XRect(Rect.X, Rect.Y, Rect.Width, curentHeight + MarginTop + 1);
            _backgroundControl.Brush = XBrushes.LightGray;
            _backgroundControl.Pen = XPens.Black;
            _backgroundControl.Draw(gfx);

            double y = 0;
            foreach (IContainerControl row in rows)
            {
                row.Rect = new XRect(Rect.X + 1, Rect.Y + MarginTop + y, row.Rect.Width - 2,
                                     row.Rect.Height);
                y += row.Rect.Height;
                row.Draw(gfx);
            }
        }
 private double DrawRightGuard(ref PdfSharp.Drawing.XGraphics g, double left)
 {
     g.DrawRectangle(null, XBrushes.Black, new XRect(Util.MillimeterToPoint(left + Left + offsetLeft), Util.MillimeterToPoint(offsetTop + Top), Util.MillimeterToPoint(BarWidth), Util.MillimeterToPoint(Height)));
     left += BarWidth;
     left += BarWidth;
     g.DrawRectangle(null, XBrushes.Black, new XRect(Util.MillimeterToPoint(left + Left + offsetLeft), Util.MillimeterToPoint(offsetTop + Top), Util.MillimeterToPoint(BarWidth), Util.MillimeterToPoint(Height)));
     left += BarWidth;
     return(left);
 }
示例#31
0
        public override void Render(ref PdfSharp.Drawing.XGraphics gfx, double offsetLeft, double offsetTop, double scaleX, double scaleY)
        {
            PreRender(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);

            double imgwidth  = Util.MillimeterToPoint(ImageWidth) * scaleX,
                   imgheight = Util.MillimeterToPoint(ImageHeight) * scaleY,
                   imgpadx   = Util.MillimeterToPoint(ImagePaddingX) * scaleX,
                   imgpady   = Util.MillimeterToPoint(ImagePaddingY) * scaleY,
                   left      = Util.MillimeterToPoint(offsetLeft + Left),
                   top       = Util.MillimeterToPoint(offsetTop + Top),
                   width     = Util.MillimeterToPoint(Width * scaleX),
                   height    = Util.MillimeterToPoint(Height * scaleY);


            for (double y = 0; y + imgpady + imgheight < height; y += imgheight + imgpady)
            {
                if (RightToLeft)
                {
                    for (double x = width - imgwidth; x > 0; x -= imgwidth + imgpadx)
                    {
                        if (images.Count > 0)
                        {
                            gfx.DrawImage((XImage)images.Dequeue(), left + x, top + y, imgwidth, imgheight);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    for (double x = 0; x + imgpadx + imgwidth < width; x += imgwidth + imgpadx)
                    {
                        if (images.Count > 0)
                        {
                            gfx.DrawImage((XImage)images.Dequeue(), left + x, top + y, imgwidth, imgheight);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (images.Count == 0)
                {
                    break;
                }
            }


            base.Render(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
        }
示例#32
0
        public override void RenderPage(PdfSharp.Drawing.XGraphics gfx)
        {
            base.RenderPage(gfx);

            //Document doc = new Document();
            //Section sec = doc.AddSection();
            //Paragraph para = sec.AddParagraph("MigraDoc Paragraph");
            //para.Format.Borders.Color = Colors.Gold;

            //MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            //docRenderer.PrepareDocument();

            //docRenderer.RenderObject(gfx, XUnit.FromCentimeter(10), XUnit.FromCentimeter(11), "5cm", para);
        }
        public override void Render(ref PdfSharp.Drawing.XGraphics gfx, double _offsetLeft, double _offsetTop, double scaleX, double scaleY)
        {
            PreRender(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
            if (code != null && code.Length == 13)
            {
                double left = 0.0;
                offsetTop  = _offsetTop;
                offsetLeft = _offsetLeft;
                Width     *= scaleX;
                Height    *= scaleY;
                font       = new XFont(new Font("World", (float)Util.MillimeterToPoint((float)Math.Min(Height * 0.2, Width * 0.1) * 0.8), GraphicsUnit.World), new XPdfFontOptions(false, false));
                gfx.DrawString(code[0].ToString(), font, Brushes.Black, new PointF((float)(Util.MillimeterToPoint(offsetLeft + Left + left)), (float)(Util.MillimeterToPoint(offsetTop + Top + (Height * 0.95)))));
                left    += 4;
                BarWidth = (Width - left) / (3 + 6 * 7 + 5 + 6 * 7 + 3);
                left     = DrawLeftGuard(ref gfx, code[0].ToString(), left);

                int    first = int.Parse(code[0].ToString());
                Parity par   = EAN13.Parity[first];
                string digit = code[1].ToString();
                left = Draw(ref gfx, left, digit, EAN13.Codes[int.Parse(digit)].LhOdd);
                for (int i = 2; i <= 6; i++)
                {
                    digit = code[i].ToString();
                    Pattern p = EAN13.Codes[int.Parse(digit)];
                    left = Draw(ref gfx, left, digit, par.IsOdd(i - 2) ? p.LhOdd : p.LhEven);
                }
                left = DrawCenterGuard(ref gfx, left);
                for (int i = 7; i <= 12; i++)
                {
                    digit = code[i].ToString();
                    Pattern p = EAN13.Codes[int.Parse(digit)];
                    left = Draw(ref gfx, left, digit, p.Rh);
                }

                left    = DrawRightGuard(ref gfx, left);
                Width  /= scaleX;
                Height /= scaleY;
            }
            base.Render(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
        }
示例#34
0
        protected void ProduceResponse(string title, Render.RenderContext ctx, Size tileSize,
                                       int rot          = 0, float translateX = 0, float translateY = 0,
                                       bool transparent = false)
        {
            // New-style Options
            // TODO: move to ParseOptions (maybe - requires options to be parsed after stylesheet creation?)
            if (GetBoolOption("sscoords", defaultValue: false))
            {
                ctx.styles.hexCoordinateStyle = Stylesheet.HexCoordinateStyle.Subsector;
            }

            if (!GetBoolOption("routes", defaultValue: true))
            {
                ctx.styles.macroRoutes.visible = false;
                ctx.styles.microRoutes.visible = false;
            }

            double devicePixelRatio = GetDoubleOption("dpr", 1);

            if (Accepts(MediaTypeNames.Application.Pdf))
            {
                using (var document = new PdfDocument())
                {
                    document.Version       = 14; // 1.4 for opacity
                    document.Info.Title    = title;
                    document.Info.Author   = "Joshua Bell";
                    document.Info.Creator  = "TravellerMap.com";
                    document.Info.Subject  = DateTime.Now.ToString("F", CultureInfo.InvariantCulture);
                    document.Info.Keywords = "The Traveller game in all forms is owned by Far Future Enterprises. Copyright (C) 1977 - 2013 Far Future Enterprises. Traveller is a registered trademark of Far Future Enterprises.";

                    // TODO: Credits/Copyright
                    // This is close, but doesn't define the namespace correctly:
                    // document.Info.Elements.Add( new KeyValuePair<string, PdfItem>( "/photoshop/Copyright", new PdfString( "HelloWorld" ) ) );

                    PdfPage page = document.AddPage();

                    // NOTE: only PageUnit currently supported in XGraphics is Points
                    page.Width  = XUnit.FromPoint(tileSize.Width);
                    page.Height = XUnit.FromPoint(tileSize.Height);

                    PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page);

                    RenderToGraphics(ctx, rot, translateX, translateY, gfx);

                    using (var stream = new MemoryStream())
                    {
                        document.Save(stream, closeStream: false);

                        SetCommonResponseHeaders();

                        Response.ContentType = MediaTypeNames.Application.Pdf;
                        Response.AddHeader("content-length", stream.Length.ToString());
                        Response.AddHeader("content-disposition", "inline;filename=\"map.pdf\"");
                        Response.BinaryWrite(stream.ToArray());
                        Response.Flush();
                        stream.Close();
                    }

                    return;
                }
            }

            using (var bitmap = new Bitmap((int)Math.Floor(tileSize.Width * devicePixelRatio), (int)Math.Floor(tileSize.Height * devicePixelRatio), PixelFormat.Format32bppArgb))
            {
                if (transparent)
                {
                    bitmap.MakeTransparent();
                }

                using (var g = Graphics.FromImage(bitmap))
                {
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                    using (var graphics = XGraphics.FromGraphics(g, new XSize(tileSize.Width * devicePixelRatio, tileSize.Height * devicePixelRatio)))
                    {
                        if (devicePixelRatio != 0)
                        {
                            graphics.ScaleTransform(devicePixelRatio);
                        }

                        RenderToGraphics(ctx, rot, translateX, translateY, graphics);
                    }
                }

                SetCommonResponseHeaders();
                BitmapResponse(ctx.styles, bitmap, transparent ? Util.MediaTypeName_Image_Png : null);
            }
        }
        public override void Render(ref PdfSharp.Drawing.XGraphics gfx, double offsetLeft, double offsetTop, double scaleX, double scaleY)
        {
            PreRender(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
            double borderWidth = Util.MillimeterToPoint(BorderWidth);
            double radiusx     = Math.Min(Util.MillimeterToPoint(Width), Util.MillimeterToPoint(BorderRadius)) * 2.0;
            double radiusy     = Math.Min(Util.MillimeterToPoint(Height), Util.MillimeterToPoint(BorderRadius)) * 2.0;

            XPen pen = new XPen(BorderColor, borderWidth);

            if (BorderRadius == 0.0)
            {
                gfx.DrawRectangle(FillColor,
                                  Util.MillimeterToPoint(offsetLeft + Left),
                                  Util.MillimeterToPoint(offsetTop + Top),
                                  Util.MillimeterToPoint(Width * scaleX),
                                  Util.MillimeterToPoint(Height * scaleY));

                gfx.DrawRectangle(pen,
                                  Util.MillimeterToPoint(offsetLeft + Left + (BorderWidth / 2.0)),
                                  Util.MillimeterToPoint(offsetTop + Top + (BorderWidth / 2.0)),
                                  Util.MillimeterToPoint((Width - BorderWidth) * scaleX),
                                  Util.MillimeterToPoint((Height - BorderWidth) * scaleY));
            }
            else
            {
                double width  = (Width - BorderWidth) * scaleX;
                double height = (Height - BorderWidth) * scaleY;



                gfx.DrawRoundedRectangle(FillColor,
                                         Util.MillimeterToPoint(offsetLeft + Left),
                                         Util.MillimeterToPoint(offsetTop + Top),
                                         Util.MillimeterToPoint((Width) * scaleX),
                                         Util.MillimeterToPoint((Height) * scaleY),
                                         Math.Min(Util.MillimeterToPoint(Width), radiusx + Util.MillimeterToPoint(BorderWidth)) - 0.1,
                                         Math.Min(Util.MillimeterToPoint(Height), radiusy + Util.MillimeterToPoint(BorderWidth)) - 0.1);

                gfx.DrawRoundedRectangle(pen,
                                         Util.MillimeterToPoint(offsetLeft + Left + (BorderWidth / 2.0)),
                                         Util.MillimeterToPoint(offsetTop + Top + (BorderWidth / 2.0)),
                                         Util.MillimeterToPoint(width),
                                         Util.MillimeterToPoint(height),
                                         Math.Min(Util.MillimeterToPoint(width), radiusx) - 0.1,
                                         Math.Min(Util.MillimeterToPoint(height), radiusy) - 0.1);
            }



            /**/

            /*if (radiusx == 0.0 && radiusy == 0.0)
             * {
             * if (Fill)
             * {
             *  gfx.DrawRectangle(FillColor,
             *    Util.MillimeterToPoint(offsetLeft + Left),
             *    Util.MillimeterToPoint(offsetTop + Top),
             *    Util.MillimeterToPoint(Width * scaleX),
             *    Util.MillimeterToPoint(Height * scaleY));
             * }
             * if (BorderWidth > 0.0 && DrawBorder) {
             *  gfx.DrawRectangle(pen,
             *  Util.MillimeterToPoint(offsetLeft + Left + (borderWidth / 2f)),
             *  Util.MillimeterToPoint(offsetTop + Top + (borderWidth / 2f)),
             *  Util.MillimeterToPoint((Width - (borderWidth / 2f)) * scaleX),
             *  Util.MillimeterToPoint((Height - (borderWidth / 2f)) * scaleY));
             * }
             * }
             * else
             * {
             * if (Fill)
             * {
             *  gfx.DrawRoundedRectangle(FillColor,
             *    Util.MillimeterToPoint(offsetLeft + Left + borderWidth),
             *    Util.MillimeterToPoint(offsetTop + Top + borderWidth),
             *    Util.MillimeterToPoint((Width - (borderWidth * 2.0)) * scaleX),
             *    Util.MillimeterToPoint((Height - (borderWidth * 2.0)) * scaleY),
             *    radiusx,
             *    radiusy);
             * }
             * if (BorderWidth > 0.0)
             * {
             *  gfx.DrawRoundedRectangle(pen,
             *  Util.MillimeterToPoint(offsetLeft + Left+(BorderRadius/2f)),
             *  Util.MillimeterToPoint(offsetTop + Top + (BorderRadius / 2f)),
             *  Util.MillimeterToPoint((Width - (BorderRadius / 2f)) * scaleX),
             *  Util.MillimeterToPoint((Height - (BorderRadius / 2f)) * scaleY),
             *  radiusx,
             *  radiusy);
             * }
             * }*/

            base.Render(ref gfx, offsetLeft, offsetTop, scaleX, scaleY);
        }
        public static void Test(PdfSharp.Drawing.XGraphics gfx)
        {
            XRect  rect;
            XPen   pen;
            double x = 50, y = 100;
            XFont  fontH1     = new XFont("Times", 18, XFontStyle.Bold);
            XFont  font       = new XFont("Times", 12);
            XFont  fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
            double ls         = font.GetHeight(gfx);

            // Draw some text
            gfx.DrawString("Create PDF on the fly with PDFsharp",
                           fontH1, XBrushes.Black, x, x);
            gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " +
                           "text and images on different targets.", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("The object used for drawing is the XGraphics object.",
                           font, XBrushes.Black, x, y);
            y += 2 * ls;

            // Draw an arc
            pen           = new XPen(XColors.Red, 4);
            pen.DashStyle = XDashStyle.Dash;
            gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120);

            // Draw a star
            XGraphicsState gs = gfx.Save();

            gfx.TranslateTransform(x + 140, y + 30);
            for (int idx = 0; idx < 360; idx += 10)
            {
                gfx.RotateTransform(10);
                gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0);
            }
            gfx.Restore(gs);

            // Draw a rounded rectangle
            rect = new XRect(x + 230, y, 100, 60);
            pen  = new XPen(XColors.DarkBlue, 2.5);
            XColor color1 = XColor.FromKnownColor(System.Drawing.KnownColor.DarkBlue);
            XColor color2 = XColors.Red;
            XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2,
                                                                   XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10));

            // Draw a pie
            pen           = new XPen(XColors.DarkOrange, 1.5);
            pen.DashStyle = XDashStyle.Dot;
            gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135);

            // Draw some more text
            y += 60 + 2 * ls;
            gfx.DrawString("With XGraphics you can draw on a PDF page as well as " +
                           "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y);
            y += ls * 1.1;
            gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y);
            x += 10;
            y += ls * 1.1;
            gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw above or beneath of the content of an existing PDF page",
                           font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y);
            x -= 10;
            y += ls * 1.1;
            gfx.DrawString("You can also import an existing PDF page and use it like " +
                           "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y);
            y += ls * 1.1 * 2;
            gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " +
                           "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            gfx.DrawString("Below this text is a PDF form that will be visible when " +
                           "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            XGraphicsState state   = gfx.Save();
            XRect          rcImage = new XRect(100, y, 100, 100 * System.Math.Sqrt(2));

            gfx.DrawRectangle(XBrushes.Snow, rcImage);
            gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage);
            gfx.Restore(state);
        }
示例#37
0
        public override void PaintPdf(PdfSharp.Drawing.XGraphics g2D, int pageNo, PointF pageStart, Ctx ctx, bool isView)
        {
            if (m_item == null)
            {
                return;
            }
            //
            //System.Drawing.SolidBrush g2Dpen = new System.Drawing.SolidBrush(m_color);
            XSolidBrush g2Dpen = new XSolidBrush(XColor.FromArgb(m_color));
            XPen        pen    = new XPen(XColor.FromArgb(m_color));

            pen.DashStyle = PdfSharp.Drawing.XDashStyle.Solid;
            //
            PointF location = GetAbsoluteLocation(pageStart);
            int    x        = (int)location.X;
            int    y        = (int)location.Y;

            int width  = m_item.GetMaxWidth();
            int height = m_item.GetMaxHeight();

            if (m_item.GetPrintFormatType().Equals(MPrintFormatItem.PRINTFORMATTYPE_Line))
            {
                g2D.DrawLine(pen, (double)x, (double)y, (double)x + width, (double)y + height);
            }
            else
            {
                String type = m_item.GetShapeType();
                if (type == null)
                {
                    type = "";
                }
                if (m_item.IsFilledRectangle())
                {
                    if (type.Equals(MPrintFormatItem.SHAPETYPE_3DRectangle))
                    {
                        g2D.DrawRectangle(g2Dpen, (double)x, (double)y, (double)width, (double)height);
                    }
                    else if (type.Equals(MPrintFormatItem.SHAPETYPE_Oval))
                    {
                        g2D.DrawRectangle(g2Dpen, (double)x, (double)y, (double)width, (double)height);
                    }
                    else if (type.Equals(MPrintFormatItem.SHAPETYPE_RoundRectangle))
                    {
                        g2D.DrawRectangle(g2Dpen, (double)x, (double)y, (double)width, (double)height); //, m_item.getArcDiameter(), m_item.getArcDiameter());
                    }
                    else
                    {
                        g2D.DrawRectangle(g2Dpen, (double)x, (double)y, (double)width, (double)height);
                    }
                }
                else
                {
                    if (type.Equals(MPrintFormatItem.SHAPETYPE_3DRectangle))
                    {
                        g2D.DrawRectangle(pen, (double)x, (double)y, (double)width, (double)height);
                    }
                    else if (type.Equals(MPrintFormatItem.SHAPETYPE_Oval))
                    {
                        g2D.DrawEllipse(pen, (double)x, (double)y, (double)width, (double)height);
                    }
                    else if (type.Equals(MPrintFormatItem.SHAPETYPE_RoundRectangle))
                    {
                        g2D.DrawRectangle(pen, (double)x, (double)y, (double)width, (double)height); //, m_item.getArcDiameter(), m_item.getArcDiameter());
                    }
                    else
                    {
                        g2D.DrawRectangle(pen, (double)x, (double)y, (double)width, (double)height);
                    }

                    //PrintElement
                }
            }
        }
        private void button_generate_Click(object sender, EventArgs e)
        {
            int         yPoint   = 170;
            PdfDocument document = new PdfDocument();

            document.Info.Title = "Raport";
            PdfPage page = document.AddPage();

            PdfSharp.Drawing.XGraphics gfx = XGraphics.FromPdfPage(page);
            XFont font_bold = new XFont("Verdana", 10, XFontStyle.BoldItalic);

            DateTime date_from = dateTimePicker_from.Value;
            DateTime date_to   = dateTimePicker_to.Value;

            var orders = db.orders.Where(o => o.deadline >= date_from && o.deadline <= date_to);

            if (!orders.Any())
            {
                MessageBox.Show("There is no orders added to raport !");
            }
            else
            {
                XFont font_regular = new XFont("Verdana", 10, XFontStyle.Bold);



                gfx.DrawString("Raport from: " + date_from.ToString("d") + " to: " + date_to.ToString("d"), font_regular, XBrushes.Black, new XRect(60, 80, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);

                gfx.DrawString("Created: ", font_regular, XBrushes.Black, new XRect(60, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                gfx.DrawString("Deadline: ", font_regular, XBrushes.Black, new XRect(160, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                gfx.DrawString("Customer: ", font_regular, XBrushes.Black, new XRect(260, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                gfx.DrawString("Employee: ", font_regular, XBrushes.Black, new XRect(360, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                font_regular = new XFont("Verdana", 10, XFontStyle.Regular);

                foreach (order order in orders)
                {
                    gfx.DrawString(order.create_timestamp.ToString("d"), font_regular, XBrushes.Black, new XRect(60, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                    gfx.DrawString(order.deadline.ToString("d"), font_regular, XBrushes.Black, new XRect(160, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                    gfx.DrawString(order.customer.company_name, font_regular, XBrushes.Black, new XRect(260, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                    gfx.DrawString(order.employee.firstname + " " + order.employee.lastname, font_regular, XBrushes.Black, new XRect(360, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
                    gfx.DrawLine(XPens.Black, 0, yPoint, 1000, yPoint);
                    yPoint += 30;
                }
                gfx.DrawLine(XPens.Black, 0, yPoint, 1000, yPoint);

                SaveFileDialog sfd = new SaveFileDialog
                {
                    Filter   = "PDF (*.pdf)|*.pdf",
                    FileName = "Output.pdf"
                };
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        document.Save(sfd.FileName);
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                        MessageBox.Show("You cannot generate raport unless previous one is closed !");
                    }
                }
            }
        }
示例#39
-1
    /// <summary>
    /// Demonstrates serveral bar code types.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      XRect rc;
      base.RenderPage(gfx);

      Graphics grfx = gfx.Internals.Graphics;

      Code2of5Interleaved bc25 = new Code2of5Interleaved();
      bc25.Text = "123456";
      bc25.Size = new XSize(90, 30);
      //bc25.Direction = BarCodeDirection.RightToLeft;
      bc25.TextLocation = TextLocation.Above;
      gfx.DrawBarCode(bc25, XBrushes.DarkBlue, new XPoint(100, 100));

      CodeDataMatrix dm = new CodeDataMatrix("test", 26);
      dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15));
      gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 100));

      rc = new XRect(30, 200, XUnit.FromCentimeter(9.3) + XUnit.FromMillimeter(0.5), XUnit.FromMillimeter(6));
      gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(128, XColors.LightSeaGreen)), rc);

      CodeOmr omr = new CodeOmr(0xF8F5FF3F.ToString(), rc.Size, CodeDirection.LeftToRight);
      omr.MakerDistance = XUnit.FromMillimeter(3);
      omr.MakerThickness = XUnit.FromMillimeter(0.5);
      gfx.DrawBarCode(omr, XBrushes.Black, rc.Center);

      omr.Direction = CodeDirection.RightToLeft;
      gfx.DrawBarCode(omr, XBrushes.Black, rc.Center + new XSize(0, 50));

      omr.Direction = CodeDirection.RightToLeft;
      gfx.DrawBarCode(omr, XBrushes.Black, rc.Center + new XSize(0, 50));

      omr.Direction = CodeDirection.TopToBottom;
      gfx.DrawBarCode(omr, XBrushes.Black, rc.Center + new XSize(300, 25));
    }
示例#40
-1
 private static void DrawLineInternal(XGraphics gfx, XPen pen, bool isStroked, ref XPoint p0, ref XPoint p1)
 {
     if (isStroked)
     {
         gfx.DrawLine(pen, p0, p1);
     }
 }
示例#41
-1
        public void Render(XGraphics gfx, FixedElement element)
        {
            var spec = element.Specification;

            var penTop = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Top.Points);
            var penLeft = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Left.Points);
            var penRight = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Right.Points);
            var penBottom = new XPen(XColor.FromArgb(spec.Borders.Color), spec.Borders.Bottom.Points);

            var midBorderTop = element.InnerBox.Top - spec.Borders.Top / 2;
            var midBorderRight = element.InnerBox.Right + spec.Borders.Right / 2;
            var midBorderBottom = element.InnerBox.Bottom + spec.Borders.Bottom / 2;
            var midBorderLeft = element.InnerBox.Left - spec.Borders.Left / 2;

            if (spec.Borders.Top != Unit.Zero)
                gfx.DrawLine(penTop, element.InnerBox.Left.Points, midBorderTop.Points, element.InnerBox.Right.Points, midBorderTop.Points);

            if (spec.Borders.Right != Unit.Zero)
                gfx.DrawLine(penRight, midBorderRight.Points, element.MarginBox.Top.Points, midBorderRight.Points, element.MarginBox.Bottom.Points);

            if (spec.Borders.Bottom != Unit.Zero)
                gfx.DrawLine(penBottom, element.InnerBox.Left.Points, midBorderBottom.Points, element.InnerBox.Right.Points, midBorderBottom.Points);

            if (spec.Borders.Left != Unit.Zero)
                gfx.DrawLine(penLeft, midBorderLeft.Points, element.MarginBox.Top.Points, midBorderLeft.Points, element.MarginBox.Bottom.Points);
        }
示例#42
-1
        public static void BeginBox(XGraphics gfx, int number, string title,
            double borderWidth, double borderHeight,
            XColor shadowColor, XColor backColor, XColor backColor2,
            XPen borderPen)
        {
            const int dEllipse = 15;
            XRect rect = new XRect(0, 20, 300, 200);
            if (number % 2 == 0)
                rect.X = 300 - 5;
            rect.Y = 40 + ((number - 1) / 2) * (200 - 5);
            rect.Inflate(-10, -10);
            XRect rect2 = rect;
            rect2.Offset(borderWidth, borderHeight);
            gfx.DrawRoundedRectangle(new XSolidBrush(shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8));
            XLinearGradientBrush brush = new XLinearGradientBrush(rect, backColor, backColor2, XLinearGradientMode.Vertical);
            gfx.DrawRoundedRectangle(borderPen, brush, rect, new XSize(dEllipse, dEllipse));
            rect.Inflate(-5, -5);

            XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
            gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter);

            rect.Inflate(-10, -5);
            rect.Y += 20;
            rect.Height -= 20;

            state = gfx.Save();
            gfx.TranslateTransform(rect.X, rect.Y);
        }