Exemple #1
0
 public BarCodeRenderInfo(XGraphics gfx, XBrush brush, XFont font, XPoint position)
 {
     Gfx = gfx;
     Brush = brush;
     Font = font;
     Position = position;
 }
 public PrintSettings()
 {
     Margin = 10;
     AutoRotateImage = true;
     AutoScaleImage = true;
     AllowEnlargeImage = false;
     CenterImage = false;
     TextFont = new XFont("Arial", 10);
 }
Exemple #3
0
        /// <summary>
        /// Renders the OMR code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    gfx.RotateAtTransform(180, position);
                    break;

                case CodeDirection.TopToBottom:
                    gfx.RotateAtTransform(90, position);
                    break;

                case CodeDirection.BottomToTop:
                    gfx.RotateAtTransform(-90, position);
                    break;
            }

            //XPoint pt = center - size / 2;
            XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size);
            uint value;
            uint.TryParse(Text, out value);
#if true
            // HACK: Project Wallenwein: set LK
            value |= 1;
            _synchronizeCode = true;
#endif
            if (_synchronizeCode)
            {
                XRect rect = new XRect(pt.X, pt.Y, _makerThickness, Size.Height);
                gfx.DrawRectangle(brush, rect);
                pt.X += 2 * _makerDistance;
            }
            for (int idx = 0; idx < 32; idx++)
            {
                if ((value & 1) == 1)
                {
                    XRect rect = new XRect(pt.X + idx * _makerDistance, pt.Y, _makerThickness, Size.Height);
                    gfx.DrawRectangle(brush, rect);
                }
                value = value >> 1;
            }
            gfx.Restore(state);
        }
Exemple #4
0
        private void printRows()
        {
            PDFRow[] rows = parser.GetGridContent();
            rows_stat = rows.Length;
            double[] rowColor;
            double[] border     = RGBColor.GetColor(lineColor);
            double   y          = OffsetTop + headerHeight;
            bool     cellsLined = false;
            XFont    cf;
            int      rowsOnPage = 0;

            for (int rowNum = 0; rowNum < rows.Length; rowNum++)
            {
                double    x     = OffsetLeft;
                PDFCell[] cells = rows[rowNum].GetCells();
                if (rowNum % 2 == 0)
                {
                    rowColor = RGBColor.GetColor(scaleOneColor);
                }
                else
                {
                    rowColor = RGBColor.GetColor(scaleTwoColor);
                }
                rowsOnPage++;

                for (int colNum = 0; colNum < cells.Length; colNum++)
                {
                    #region columnDrawing
                    double height = cols[0][colNum].GetHeight() * LineHeight;
                    double width  = widths[colNum] * pageWidth / widthSum;
                    String al     = cells[colNum].GetAlign();
                    if (al.ToLower().Equals(""))
                    {
                        al = cols[0][colNum].GetAlign();
                    }
                    String tp = cols[0][colNum].getType();

                    XRect cellIn = new XRect();
                    cellIn.Location = new XPoint(x, y);
                    cellIn.Size     = new XSize(width, LineHeight);


                    gfx.DrawRectangle(new XSolidBrush(RGBColor.GetXColor(((!cells[colNum].GetBgColor().Equals("")) && (parser.GetProfile() == ColorProfile.FullColor)) ? RGBColor.GetColor(cells[colNum].GetBgColor()) : rowColor)), cellIn);

                    if (cells[colNum].GetBold())
                    {
                        if (cells[colNum].GetItalic())
                        {
                            if (f4 == null)
                            {
                                f4 = createFont("Helvetica-BoldOblique", fontSize);
                            }
                            cf = f4;
                        }
                        else
                        {
                            if (f2 == null)
                            {
                                f2 = createFont("Helvetica-Bold", fontSize);
                            }
                            cf = f2;
                        }
                    }
                    else if (cells[colNum].GetItalic())
                    {
                        if (f3 == null)
                        {
                            f3 = createFont("Helvetica-Oblique", fontSize);
                        }
                        cf = f3;
                    }
                    else
                    {
                        cf = f1;
                    }

                    XTextFormatter text = new XTextFormatter(gfx);
                    text.Font = cf;
                    text.Text = textWrap(cells[colNum].GetValue(), width - 2 * CellOffset, cf);


                    String label = textWrap(cells[colNum].GetValue(), width - 2 * CellOffset, cf);



                    if (al.ToLower().Equals("left") == true)
                    {
                        text.Alignment = XParagraphAlignment.Left;
                    }
                    else
                    {
                        if (al.ToLower().Equals("right") == true)
                        {
                            text.Alignment = XParagraphAlignment.Right;
                        }
                        else
                        {
                            text.Alignment = XParagraphAlignment.Center;
                        }
                    }



                    var checkbox_width = 15 / 2;//approxmatelly...
                    if (tp.ToLower().Equals("ch"))
                    {
                        double ch_x = width / 2 - checkbox_width;
                        double ch_y = LineHeight / 2 - checkbox_width;
                        if (text.Text.ToLower().Equals("1") == true)
                        {
                            drawCheckbox(true, ch_x, ch_y, cellIn);
                        }
                        else
                        {
                            drawCheckbox(false, ch_x, ch_y, cellIn);
                        }
                    }
                    else
                    {
                        if (tp.ToLower().Equals("ra"))
                        {
                            double ch_x = width / 2 - checkbox_width;
                            double ch_y = LineHeight / 2 - checkbox_width;
                            if (text.Text.ToLower().Equals("1") == true)
                            {
                                drawRadio(true, ch_x, ch_y, cellIn);
                            }
                            else
                            {
                                drawRadio(false, ch_x, ch_y, cellIn);
                            }
                        }
                        else
                        {
                            double text_y = (LineHeight + f1.Size) / 2;

                            XRect text_cell = new XRect();
                            text_cell.Size = new XSize(width - 2 * LineHeight / 5, gfx.MeasureString(text.Text, text.Font).Height);

                            text_cell.Location = new XPoint(x + LineHeight / 5, y + (LineHeight - text_cell.Size.Height) / 1.7);


                            text.DrawString(text.Text, text.Font, new XSolidBrush((!cells[colNum].GetTextColor().Equals("") && parser.GetProfile().Equals("full_color")) ? RGBColor.GetXColor(cells[colNum].GetTextColor()) : RGBColor.GetXColor(gridTextColor)), text_cell);
                        }
                    }
                    x += width;
                    #endregion
                }



                gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(OffsetLeft, y), new XPoint(OffsetLeft + pageWidth, y));

                y += LineHeight;
                gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(OffsetLeft, y), new XPoint(OffsetLeft + pageWidth, y));


                if (y + LineHeight - OffsetTop + footerHeight >= pageHeight)
                {
                    var left = OffsetLeft;
                    var top  = OffsetTop + headerHeight;

                    top = OffsetTop + headerHeight;
                    gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));

                    var widths = parser.GetWidths();
                    for (int colNum = 0; colNum < widths.Length; colNum++)
                    {
                        left += widths[colNum] * pageWidth / widthSum;
                        gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));
                    }

                    newPage();

                    if (firstPage == true)
                    {
                        pageHeight += getHeaderImgHeight();
                        OffsetTop  -= getHeaderImgHeight();
                        firstPage   = false;
                    }

                    double imgHeight = 0;
                    if (rows.Length - rowNum < rowsOnPage && parser.GetFooter())
                    {
                        imgHeight = getFooterImgHeight();
                    }
                    rowsOnPage = 0;
                    headerPrint();
                    footerHeight += imgHeight;
                    y             = OffsetTop + headerHeight;
                }
                x = OffsetLeft;
            }
            f1 = createFont("Helvetica", fontSize);

            if (!cellsLined)
            {
                var left = OffsetLeft;
                var top  = OffsetTop + headerHeight;


                top = OffsetTop + headerHeight;
                gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));

                var widths = parser.GetWidths();
                for (int colNum = 0; colNum < widths.Length; colNum++)
                {
                    left += widths[colNum] * pageWidth / widthSum;
                    gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));
                }
            }
        }
Exemple #5
0
        public static void CreatePdfPage(Sheet sheet, PdfPage page)
        {
            page.Width  = p(sheet.Width);         //XUnit.FromInch((double)sheet.Width/100);  //new XUnit((double)sheet.Width/100,XGraphicsUnit.Inch);
            page.Height = p(sheet.Height);        //new XUnit((double)sheet.Height/100,XGraphicsUnit.Inch);
            if (sheet.IsLandscape)
            {
                page.Orientation = PageOrientation.Landscape;
            }
            XGraphics g = XGraphics.FromPdfPage(page);

            g.SmoothingMode = XSmoothingMode.HighQuality;
            //g.PageUnit=XGraphicsUnit. //wish they had pixel
            //XTextFormatter tf = new XTextFormatter(g);//needed for text wrap
            //tf.Alignment=XParagraphAlignment.Left;
            //pd.DefaultPageSettings.Landscape=
            //already done?:SheetUtil.CalculateHeights(sheet,g);//this is here because of easy access to g.
            XFont      xfont;
            XFontStyle xfontstyle;

            //first, draw images--------------------------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Image)
                {
                    continue;
                }
                string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName);
                Bitmap bitmapOriginal  = null;
                if (field.FieldName == "Patient Info.gif")
                {
                    bitmapOriginal = Properties.Resources.Patient_Info;
                }
                else if (File.Exists(filePathAndName))
                {
                    bitmapOriginal = new Bitmap(filePathAndName);
                }
                else
                {
                    continue;
                }
                Bitmap bitmapResampled = (Bitmap)bitmapOriginal.Clone();
                if (bitmapOriginal.HorizontalResolution != 96 || bitmapOriginal.VerticalResolution != 96)            //to avoid slowdown for other pdfs
                //The scaling on the XGraphics.DrawImage() function causes unreadable output unless the image is in 96 DPI native format.
                //We use GDI here first to convert the image to the correct size and DPI, then pass the second image to XGraphics.DrawImage().
                {
                    bitmapResampled.Dispose();
                    bitmapResampled = null;
                    bitmapResampled = new Bitmap(field.Width, field.Height);
                    Graphics gr = Graphics.FromImage(bitmapResampled);
                    gr.DrawImage(bitmapOriginal, 0, 0, field.Width, field.Height);
                    gr.Dispose();
                }
                g.DrawImage(bitmapResampled, p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                bitmapResampled.Dispose();
                bitmapResampled = null;
                bitmapOriginal.Dispose();
                bitmapOriginal = null;
            }
            //then, drawings--------------------------------------------------------------------------------------------
            XPen pen = new XPen(XColors.Black, p(2));

            string[]     pointStr;
            List <Point> points;
            Point        point;

            string[] xy;
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.Drawing)
                {
                    continue;
                }
                pointStr = field.FieldValue.Split(';');
                points   = new List <Point>();
                for (int j = 0; j < pointStr.Length; j++)
                {
                    xy = pointStr[j].Split(',');
                    if (xy.Length == 2)
                    {
                        point = new Point(PIn.Int(xy[0]), PIn.Int(xy[1]));
                        points.Add(point);
                    }
                }
                for (int i = 1; i < points.Count; i++)
                {
                    g.DrawLine(pen, p(points[i - 1].X), p(points[i - 1].Y), p(points[i].X), p(points[i].Y));
                }
            }
            //then, rectangles and lines----------------------------------------------------------------------------------
            XPen pen2 = new XPen(XColors.Black, p(1));

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType == SheetFieldType.Rectangle)
                {
                    g.DrawRectangle(pen2, p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                }
                if (field.FieldType == SheetFieldType.Line)
                {
                    g.DrawLine(pen2, p(field.XPos), p(field.YPos),
                               p(field.XPos + field.Width),
                               p(field.YPos + field.Height));
                }
            }
            //then, draw text--------------------------------------------------------------------------------------------
            Bitmap   doubleBuffer = new Bitmap(sheet.Width, sheet.Height);
            Graphics gfx          = Graphics.FromImage(doubleBuffer);

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.InputField &&
                    field.FieldType != SheetFieldType.OutputText &&
                    field.FieldType != SheetFieldType.StaticText)
                {
                    continue;
                }
                xfontstyle = XFontStyle.Regular;
                if (field.FontIsBold)
                {
                    xfontstyle = XFontStyle.Bold;
                }
                xfont = new XFont(field.FontName, field.FontSize, xfontstyle);
                //xfont=new XFont(field.FontName,field.FontSize,xfontstyle);
                //Rectangle rect=new Rectangle((int)p(field.XPos),(int)p(field.YPos),(int)p(field.Width),(int)p(field.Height));
                XRect xrect = new XRect(p(field.XPos), p(field.YPos), p(field.Width), p(field.Height));
                //XStringFormat format=new XStringFormat();
                //tf.DrawString(field.FieldValue,font,XBrushes.Black,xrect,XStringFormats.TopLeft);
                GraphicsHelper.DrawStringX(g, gfx, 1d / p(1), field.FieldValue, xfont, XBrushes.Black, xrect);
            }
            gfx.Dispose();
            //then, checkboxes----------------------------------------------------------------------------------
            XPen pen3 = new XPen(XColors.Black, p(1.6f));

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.CheckBox)
                {
                    continue;
                }
                if (field.FieldValue == "X")
                {
                    g.DrawLine(pen3, p(field.XPos), p(field.YPos), p(field.XPos + field.Width), p(field.YPos + field.Height));
                    g.DrawLine(pen3, p(field.XPos + field.Width), p(field.YPos), p(field.XPos), p(field.YPos + field.Height));
                }
            }
            //then signature boxes----------------------------------------------------------------------
            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.FieldType != SheetFieldType.SigBox)
                {
                    continue;
                }
                SignatureBoxWrapper wrapper = new SignatureBoxWrapper();
                wrapper.Width  = field.Width;
                wrapper.Height = field.Height;
                if (field.FieldValue.Length > 0)              //a signature is present
                {
                    bool sigIsTopaz = false;
                    if (field.FieldValue[0] == '1')
                    {
                        sigIsTopaz = true;
                    }
                    string signature = "";
                    if (field.FieldValue.Length > 1)
                    {
                        signature = field.FieldValue.Substring(1);
                    }
                    string keyData = Sheets.GetSignatureKey(sheet);
                    wrapper.FillSignature(sigIsTopaz, keyData, signature);
                }
                XImage sigBitmap = XImage.FromGdiPlusImage(wrapper.GetSigImage());
                g.DrawImage(sigBitmap, p(field.XPos), p(field.YPos), p(field.Width - 2), p(field.Height - 2));
            }
        }
        /// <summary>
        /// Generate a first page
        /// </summary>
        /// <param name="gfx">First page graphics component</param>
        /// <param name="useCustomerLogo">If using a customerlogo. Needs to be created first!</param>
        private void GenerateFirstPage(XGraphics gfx)
        {
            if (customerLogoImage != null)
            {
                gfx.DrawImage(customerLogoImage, LogoRect.Left, LogoRect.Top);
            }
            else
            {
                gfx.DrawImage(ABECELogo, LogoRect.Left, LogoRect.Top);
            }

            //======================================================================================================================================//
            var font = new XFont("Calibri", 42.0, XFontStyle.Bold);

            //Get stringsize width
            XSize stringSize = gfx.MeasureString(reportTab.rpData.tb_Header_Text, font);

            //Get rectangle height dependning on how long the string is. Otherwise the text wont wrap.
            double rectHeight;

            if (stringSize.Width > UsableWidth)
            {
                rectHeight = font.GetHeight() + font.GetHeight() + font.GetHeight();
            }
            else
            {
                rectHeight = font.GetHeight();
            }

            var rect = new XRect(Margin, LogoRect.Bottom + 150, UsableWidth, rectHeight);

            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString(reportTab.rpData.tb_Header_Text, font, TextBrush, rect, XStringFormats.TopLeft);

            //======================================================================================================================================//
            //Add Plant: label
            font       = new XFont("Calibri", 24.0, XFontStyle.Bold | XFontStyle.Underline);
            stringSize = gfx.MeasureString("Plant: ", font);
            rect       = new XRect(Margin, PageHeight - 220, stringSize.Width, font.GetHeight());
            CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString("Plant: ", font, TextBrush, rect, XStringFormats.TopLeft);

            //======================================================================================================================================//
            //Add where text
            font       = new XFont("Calibri", 22.0, XFontStyle.Bold);
            stringSize = gfx.MeasureString(reportTab.rpData.tb_ReportFrom_Text, font);
            rect       = new XRect(Margin + rect.Width + 8, rect.Location.Y + 2, stringSize.Width, rectHeight);
            CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString(reportTab.rpData.tb_ReportFrom_Text, font, TextBrush, rect, XStringFormats.TopLeft);

            //======================================================================================================================================//
            //Add By: label
            font       = new XFont("Calibri", 24.0, XFontStyle.Bold | XFontStyle.Underline);
            stringSize = gfx.MeasureString("By: ", font);
            rect       = new XRect(Margin, rect.Location.Y + rect.Height, stringSize.Width, font.GetHeight());
            CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString("By: ", font, TextBrush, rect, XStringFormats.TopLeft);

            //======================================================================================================================================//
            //Add By: text
            font       = new XFont("Calibri", 22.0, XFontStyle.Bold);
            stringSize = gfx.MeasureString(reportTab.rpData.tb_ReportBy_Text, font);
            rect       = new XRect(Margin + rect.Width + 8, rect.Location.Y + 2, stringSize.Width, font.GetHeight());
            CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString(reportTab.rpData.tb_ReportBy_Text, font, TextBrush, rect, XStringFormats.TopLeft);

            //Add Date: label
            font       = new XFont("Calibri", 24.0, XFontStyle.Bold | XFontStyle.Underline);
            stringSize = gfx.MeasureString("Date: ", font);
            rect       = new XRect(Margin, rect.Location.Y + rect.Height + rect.Height, stringSize.Width, font.GetHeight());
            CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString("Date: ", font, TextBrush, rect, XStringFormats.TopLeft);

            //======================================================================================================================================//
            //Add date
            font       = new XFont("Calibri", 22.0, XFontStyle.Bold);
            stringSize = gfx.MeasureString(reportTab.rpData.tb_ReportBy_Text, font);
            rect       = new XRect(Margin + rect.Width + 8, rect.Location.Y + 2, stringSize.Width, font.GetHeight());
            CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString(reportTab.rpData.dtp_ReportDate.Date.ToShortDateString(), font, TextBrush, rect, XStringFormats.TopLeft);
        }
Exemple #7
0
        private void addUser_Click(object sender, EventArgs e)
        {
            DateTime    thisDay  = DateTime.Today;
            string      today    = thisDay.ToString("dd/MM/yyyy");
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            page.Width  = 1181;
            page.Height = 1748;
            XGraphics gfx    = XGraphics.FromPdfPage(page);
            int       width  = this.photo.PixelWidth;
            int       height = this.photo.PixelHeight;

            XFont font  = new XFont("Spaceman", 32, XFontStyle.BoldItalic);
            XFont fontD = new XFont("Spaceman", 16, XFontStyle.BoldItalic);

            string subPath = "C:\\pdf\\";

            if (!Directory.Exists(subPath))
            {
                Directory.CreateDirectory(subPath);
            }

            if (!(textName.Text == ""))
            {
                gfx.DrawImage(this.background, 0, 0, 1163, 587);
                gfx.DrawString(textName.Text, font, XBrushes.White,
                               new XRect(200, 365, page.Width, page.Height), XStringFormats.TopLeft);
                gfx.DrawImage(this.photo, 855, 190, 270, 350);
                gfx.DrawString(today, fontD, XBrushes.MediumBlue,
                               new XRect(260, 545, page.Width, page.Height), XStringFormats.TopLeft);
                addUser.Enabled = true;
            }
            if (!(textName1.Text == ""))
            {
                gfx.DrawImage(this.background, 0, 587, 1163, 587);
                gfx.DrawString(textName1.Text, font, XBrushes.White,
                               new XRect(200, 952, page.Width, page.Height), XStringFormats.TopLeft);
                gfx.DrawImage(this.photo1, 855, 777, 270, 350);
                gfx.DrawString(today, fontD, XBrushes.MediumBlue,
                               new XRect(260, 1132, page.Width, page.Height), XStringFormats.TopLeft);
                addUser.Enabled = true;
            }
            if (!(textName2.Text == ""))
            {
                gfx.DrawImage(this.background, 0, 1174, 1163, 587);
                gfx.DrawString(textName2.Text, font, XBrushes.White,
                               new XRect(200, 1539, page.Width, page.Height), XStringFormats.TopLeft);
                gfx.DrawImage(this.photo2, 855, 1364, 270, 350);
                gfx.DrawString(today, fontD, XBrushes.MediumBlue,
                               new XRect(260, 1719, page.Width, page.Height), XStringFormats.TopLeft);
                addUser.Enabled = true;
            }

            string filename = "C:\\pdf\\" + textName.Text + textName1.Text + textName2.Text;

            while (File.Exists(filename + ".pdf"))
            {
                filename = filename + "1";
            }
            fname = filename + ".pdf";
            document.Save(filename + ".pdf");
            MessageBox.Show("Utworzono dokument w: " + filename + ".pdf");

            print.Enabled = true;
        }
Exemple #8
0
 /// <summary>
 /// Renders the content found in Text
 /// </summary>
 /// <param name="gfx">
 /// XGraphics - Instance of the drawing surface 
 /// </param>
 /// <param name="brush">
 /// XBrush - Line and Color to draw the bar code 
 /// </param>
 /// <param name="font">
 /// XFont - Font to use to draw the text string 
 /// </param>
 /// <param name="position">
 /// XPoint - Location to render the bar code 
 /// </param>
 protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
 {
     // Create the array to hold the values to be rendered
     this.Values = this.Code128Code == Code128Type.C ? new byte[this.text.Length / 2] : new byte[this.text.Length];
     String buffer = String.Empty;
     for (Int32 index = 0; index < text.Length; index++)
         switch (this.Code128Code)
         {
             case Code128Type.A:
                 if (text[index] < 32)
                     this.Values[index] = (byte)(text[index] + 64);
                 else if ((text[index] >= 32) && (text[index] < 64))
                     this.Values[index] = (byte)(text[index] - 32);
                 else
                     this.Values[index] = (byte)text[index];
                 break;
             case Code128Type.B:
                 this.Values[index] = (byte)(text[index] - 32);
                 break;
             case Code128Type.C:
                 if ((text[index] >= '0') && (text[index] <= '9'))
                 {
                     buffer += text[index];
                     if (buffer.Length == 2)
                     {
                         this.Values[index / 2] = byte.Parse(buffer);
                         buffer = String.Empty;
                     }
                 }
                 else
                     throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C");
                 break;
         }
     if (this.Values == null)
         throw new InvalidOperationException("Text or Values must be set");
     if (this.Values.Length == 0)
         throw new InvalidOperationException("Text or Values must have content");
     for (int x = 0; x < this.Values.Length; x++)
         if (this.Values[x] > 102)
             throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x));
     XGraphicsState state = gfx.Save();
     BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);
     this.InitRendering(info);
     info.CurrPosInString = 0;
     info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);
     this.RenderStart(info);
     foreach (byte c in this.Values)
         this.RenderValue(info, c);
     this.RenderStop(info);
     if (this.TextLocation != TextLocation.None)
         this.RenderText(info);
     gfx.Restore(state);
 }
    /// <summary>
    /// Renders the bar code.
    /// </summary>
    protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
    {
      XGraphicsState state = gfx.Save();

      BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position);
      InitRendering(info);
      info.CurrPosInString = 0;
      //info.CurrPos = info.Center - this.size / 2;
      info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);

      if (TurboBit)
        RenderTurboBit(info, true);
      RenderStart(info);
      while (info.CurrPosInString < this.text.Length)
      {
        RenderNextChar(info);
        RenderGap(info, false);
      }
      RenderStop(info);
      if (TurboBit)
        RenderTurboBit(info, false);
      if (TextLocation != TextLocation.None)
        RenderText(info);

      gfx.Restore(state);
    }
        private void BtnPrintInvoice_Click(object sender, RoutedEventArgs e)
        {
            var titleLines = new List <string>
            {
                $"|Invoice №{_currentDelivery.DeliveryNumber,39}|Order date:{_currentDelivery.DeliveryDate,78}|",
                $"|Provider:{_currentDelivery.ProviderTitle,39}|Contact person:{_currentDelivery.ContactPerson,40}|Phone:{_currentDelivery.PhoneNumber,27}|",
                "--------------------------------------------------------------------------------------------------------------------------------------------"
            };

            var    consgnmentsList = new List <string>();
            double totalPrice      = 0;

            foreach (var deliveryContent in FilteredDeliveryContentsDtos)
            {
                if (deliveryContent.ConsignmentNumber != null && deliveryContent.ConsignmentNumber != "")
                {
                    consgnmentsList.Add(
                        "--------------------------------------------------------------------------------------------------------------------------------------------");
                    consgnmentsList.Add(
                        $"|Code:{deliveryContent.ProductCode,10}|Producer:{deliveryContent.ProducerTitle,20}|Good:{deliveryContent.GoodTitle,20}|Consignment:{deliveryContent.ConsignmentNumber,15}|Amount:{deliveryContent.StringOrderAmount,12}|Price:{deliveryContent.StringIncomePrice,12}|");
                    totalPrice += deliveryContent.OrderAmount * deliveryContent.IncomePrice ?? 0;
                }
            }

            var stringTotalPrice = $"{totalPrice,0:C2}";

            var totalList = new List <string>
            {
                "--------------------------------------------------------------------------------------------------------------------------------------------",
                $"|Total:{stringTotalPrice,12}|"
            };

            if (File.Exists($"Invoice{_currentDelivery.DeliveryNumber}.pdf"))
            {
                File.Delete($"Invoice{_currentDelivery.DeliveryNumber}.pdf");
            }

            var pdf     = new PdfDocument();
            var pdfPage = pdf.Pages.Add();

            pdfPage.Orientation = PageOrientation.Landscape;
            var graph     = XGraphics.FromPdfPage(pdfPage);
            var titleFont = new XFont("Consolas", 10, XFontStyle.Bold);
            var font      = new XFont("Consolas", 10, XFontStyle.Regular);
            var tf        = new XTextFormatter(graph);
            var yPoint    = 0;

            foreach (var titleLine in titleLines)
            {
                tf.Alignment = XParagraphAlignment.Right;
                tf.DrawString(titleLine, titleFont, XBrushes.Black,
                              new XRect(10, yPoint, pdfPage.Width - 10, pdfPage.Height), XStringFormats.TopLeft);
                yPoint += 10;
            }

            foreach (var consignment in consgnmentsList)
            {
                tf.Alignment = XParagraphAlignment.Right;
                tf.DrawString(consignment, font, XBrushes.Black,
                              new XRect(10, yPoint, pdfPage.Width - 10, pdfPage.Height), XStringFormats.TopLeft);
                yPoint += 10;
            }

            foreach (var total in totalList)
            {
                tf.Alignment = XParagraphAlignment.Right;
                if (totalList.IndexOf(total) == totalList.Count - 1)
                {
                    tf.Alignment = XParagraphAlignment.Right;
                    tf.DrawString(total, titleFont, XBrushes.Black,
                                  new XRect(10, yPoint, pdfPage.Width - 10, pdfPage.Height), XStringFormats.TopLeft);
                }
                else
                {
                    tf.DrawString(total, titleFont, XBrushes.Black,
                                  new XRect(10, yPoint, pdfPage.Width - 10, pdfPage.Height), XStringFormats.TopLeft);
                }

                yPoint += 10;
            }

            var pdfFilename = $"Invoice{_currentDelivery.DeliveryNumber}.pdf";

            pdf.Save(pdfFilename);
            Process.Start("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
                          Path.GetFullPath(pdfFilename));
        }
Exemple #11
0
        public void Generate(Teacher teacher, Payslip payslip, PayrollRecord payrollRecord, string filename)
        {
            var months = new string[] { "Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
                                        "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" };

            var template = PdfReader.Open("fiche_paie.pdf");

            var page = template.Pages[0];

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Create a font
            XFont titleFont  = new XFont("Calibri", 20, XFontStyle.Bold);
            XFont normalFont = new XFont("Calibri", 12);

            // Draw the text
            //gfx.DrawString("FICHE DE PAIE", titleFont, XBrushes.Black,
            //  new XRect(0, 0, page.Width, page.Height),
            //  XStringFormats.TopCenter);

            // Draw teacher info box
            //var teacherInfoRect = new XRect(50, 50, 150, 100);
            //XPen pen = new XPen(XColors.Black, 1);
            //gfx.DrawRectangle(pen, teacherInfoRect);



            // Draw Teacher info
            gfx.DrawString(teacher.Id.ToString(), normalFont, XBrushes.Black,
                           new XPoint(130, 114), XStringFormats.TopLeft);

            gfx.DrawString(teacher.CIN, normalFont, XBrushes.Black,
                           new XPoint(130, 129), XStringFormats.TopLeft);

            gfx.DrawString(teacher.FullName, normalFont, XBrushes.Black,
                           new XPoint(130, 144), XStringFormats.TopLeft);

            gfx.DrawString(teacher.Grade.ToString(), normalFont, XBrushes.Black,
                           new XPoint(130, 158), XStringFormats.TopLeft);

            gfx.DrawString(teacher.Status.ToString(), normalFont, XBrushes.Black,
                           new XPoint(130, 172), XStringFormats.TopLeft);

            gfx.DrawString(teacher.Speciality, normalFont, XBrushes.Black,
                           new XPoint(130, 188), XStringFormats.TopLeft);

            // Draw Payment info

            gfx.DrawString(months[payslip.Payment.PaymentDate.Month - 1] + " " + payslip.Payment.PaymentDate.Year, normalFont, XBrushes.Black,
                           new XPoint(382, 114), XStringFormats.TopLeft);

            gfx.DrawString(payslip.Payment.PaymentDate.ToString(), normalFont, XBrushes.Black,
                           new XPoint(382, 129), XStringFormats.TopLeft);

            gfx.DrawString(payslip.Payment.PaymentType.ToString(), normalFont, XBrushes.Black,
                           new XPoint(382, 144), XStringFormats.TopLeft);

            gfx.DrawString(payslip.Payment.Bank ?? "", normalFont, XBrushes.Black,
                           new XPoint(382, 158), XStringFormats.TopLeft);

            if (payslip.Payment.PaymentType == PaymentType.BankTransfer)
            {
                gfx.DrawString(payslip.Payment.Reference, normalFont, XBrushes.Black,
                               new XPoint(382, 172), XStringFormats.TopLeft);
            }
            else if (payslip.Payment.PaymentType == PaymentType.Check)
            {
                gfx.DrawString(payslip.Payment.Reference, normalFont, XBrushes.Black,
                               new XPoint(382, 188), XStringFormats.TopLeft);
            }

            // Draw payroll info
            gfx.DrawString(payrollRecord.HoursCount.ToString(), normalFont, XBrushes.Black,
                           new XPoint(36, 238), XStringFormats.TopLeft);

            gfx.DrawString(formatMoney(payrollRecord.Rate), normalFont, XBrushes.Black,
                           new XPoint(135, 238), XStringFormats.TopLeft);;

            gfx.DrawString(formatMoney(payrollRecord.GrossPay), normalFont, XBrushes.Black,
                           new XPoint(245, 238), XStringFormats.TopLeft);

            gfx.DrawString("15%", normalFont, XBrushes.Black,
                           new XPoint(350, 238), XStringFormats.TopLeft);

            gfx.DrawString(formatMoney(payrollRecord.Net), normalFont, XBrushes.Black,
                           new XPoint(447, 238), XStringFormats.TopLeft);

            // Draw total

            gfx.DrawString(formatMoney(payrollRecord.Net), normalFont, XBrushes.Black,
                           new XPoint(447, 636), XStringFormats.TopLeft);


            // Save the document...
            // const string filename = "HelloWorld.pdf";


            template.Save(filename);
            Process.Start(new ProcessStartInfo(/*Directory.GetCurrentDirectory() + "\\" +*/ filename)
            {
                UseShellExecute = true
            });

            // ...and start a viewer.
            //Process.Start(filename);
        }
Exemple #12
0
        public String invoicereport(int transaction_Id)
        {
            String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            String strUrl          = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");
            //string path ="E:\\Source";

            String path = getinvoicepaymentlink("GETinvoicereportdetails12");

            var newUploadPath = path;

            PdfDocument document = new PdfSharp.Pdf.PdfDocument();


            List <FavouriteModel> invoicedetails = getinvoicereport(transaction_Id);


            //document.Info.Title = "Study Certificate";
            PdfPage page = document.AddPage();

            page.Size = PageSize.A4;

            XGraphics      gfx = XGraphics.FromPdfPage(page);
            XTextFormatter tf  = new XTextFormatter(gfx);
            // var x1 = 40;
            XFont fonthead        = new XFont("Verdana", 13, XFontStyle.Bold);
            XFont fontbody        = new XFont("Times New Roman", 9, XFontStyle.Regular);
            XFont fontbodybold    = new XFont("Times New Roman", 11, XFontStyle.Bold);
            XFont subjectdata     = new XFont("Times New Roman", 10, XFontStyle.Regular);
            XFont subjectheader   = new XFont("Times New Roman", 10, XFontStyle.Bold);
            XFont subjectheader1  = new XFont("Times New Roman", 9, XFontStyle.Bold);
            XFont fontbodybold1   = new XFont("Times New Roman", 11, XFontStyle.Bold);
            XFont fontbodybold12  = new XFont("Times New Roman", 15, XFontStyle.Bold);
            XFont fontbodybold121 = new XFont("Times New Roman", 28, XFontStyle.Bold);
            XFont fontbodybold123 = new XFont("Times New Roman", 15, XFontStyle.Bold);
            XFont fontbodybold2   = new XFont("Times New Roman", 9, XFontStyle.Bold);
            XFont fontbodybold3   = new XFont("Times New Roman", 12, XFontStyle.Regular);


            var issdate = Convert.ToDateTime(invoicedetails[0].transaction_Date);
            var dat2    = issdate.ToString("dd/MM/yyyy");
            //school logo
            //getinvoicepaymentlink("GETinvoicereportdetails12");
            string uriPath = getinvoicepaymentlink("GETinvoicereportdetails");

            try
            {
                XImage image = XImage.FromFile(uriPath);
                gfx.DrawImage(image, 50, 20, 80, 80);
                if (!File.Exists(uriPath))
                {
                    throw new FileNotFoundException();
                }
            }
            catch (FileNotFoundException e)
            {
                // gfx.DrawImage(image, 260, x1, 80, 80);
            }


            int y = 0;

            y = y + 30;

            gfx.DrawString("INVOICE ", fontbodybold121, XBrushes.Black,
                           new XRect(450, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 70;
            gfx.DrawString(invoicedetails[0].customerName.ToString(), fontbodybold123, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 18;
            gfx.DrawString("Mobile No:", fontbodybold3, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("" + invoicedetails[0].mobile_No.ToString(), fontbodybold3, XBrushes.Black,
                           new XRect(109, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Bill To", fontbodybold1, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 15;
            gfx.DrawString("Email:", fontbodybold3, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("" + invoicedetails[0].email_id.ToString(), fontbodybold3, XBrushes.Black,
                           new XRect(95, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 50;
            gfx.DrawRectangle(XBrushes.LightGray, new XRect(50, y, 500, y - 100));
            gfx.DrawString("Invoice Number ", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(" " + invoicedetails[0].transaction_Id.ToString(), subjectdata, XBrushes.Black,
                           new XRect(160, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Date", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(dat2, subjectdata, XBrushes.Black,
                           new XRect(160, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Payment Terms", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("Due On receipt", subjectdata, XBrushes.Black,
                           new XRect(160, y + 9, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;
            gfx.DrawString("Due Date", fontbodybold1, XBrushes.Black,
                           new XRect(80, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(dat2, subjectdata, XBrushes.Black,
                           new XRect(160, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 20;

            y = y + 40;
            gfx.DrawString("DESCRIPTION", fontbodybold1, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("PRICE", fontbodybold1, XBrushes.Black,
                           new XRect(180, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);

            gfx.DrawString("DURATION", fontbodybold1, XBrushes.Black,
                           new XRect(320, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);


            gfx.DrawString("TOTAL", fontbodybold1, XBrushes.Black,
                           new XRect(450, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);

            y = y + 20;
            gfx.DrawLine(XPens.Gray, 50, y, 510, y);
            y = y + 10;
            gfx.DrawString(invoicedetails[0].category.ToString(), subjectdata, XBrushes.Black,
                           new XRect(50, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(invoicedetails[0].transaction_Amount.ToString(), subjectdata, XBrushes.Black,
                           new XRect(455, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString("6 Months", subjectdata, XBrushes.Black,
                           new XRect(325, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            gfx.DrawString(invoicedetails[0].transaction_Amount.ToString(), subjectdata, XBrushes.Black,
                           new XRect(175, y + 7, page.Width, page.Height),
                           XStringFormat.TopLeft);
            y = y + 30;
            gfx.DrawLine(XPens.Gray, 50, y, 510, y);
            //  y = y + 50;
            //  gfx.DrawString("Thank you", fontbodybold3, XBrushes.Black,
            //new XRect(50, y + 7, page.Width, page.Height),
            //XStringFormat.TopLeft);
            //       y = y + 15;
            //       gfx.DrawString("It is a long established fact that a reader will be distracted by the readable ", fontbodybold3, XBrushes.Black,
            //  new XRect(50, y + 7, page.Width, page.Height),
            //  XStringFormat.TopLeft);
            //       y = y + 15;
            //       gfx.DrawString("content of a page when looking at its layout.", fontbodybold3, XBrushes.Black,
            //new XRect(50, y + 7, page.Width, page.Height),
            //XStringFormat.TopLeft);
            try
            {
                string filename = "/InvoiceReport" + invoicedetails[0].transaction_Id + ".pdf";
                document.Save(newUploadPath + filename);
                if (!File.Exists(newUploadPath + filename))
                {
                    throw new System.IO.DirectoryNotFoundException();
                }
                Process process = new Process();
                process.StartInfo.UseShellExecute = true;
                process.StartInfo.FileName        = (newUploadPath + filename);
                //process.Start();
                return(newUploadPath + filename);
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                path = path.Replace("\\api\\", "\\Group\\");
                Directory.CreateDirectory(path);
                string filename2 = "/InvoiceReport.pdf";
                document.Save(path + filename2);
                Process process = new Process();
                process.StartInfo.UseShellExecute = true;
                process.StartInfo.FileName        = (path + filename2);
                //  process.Start();
                return(newUploadPath + filename2);
            }
        }
Exemple #13
0
 /// <summary>
 /// When defined in a derived class renders the code.
 /// </summary>
 protected internal abstract void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position);
Exemple #14
0
        /// <summary>Creates the table.</summary>
        /// <param name="section">The section.</param>
        /// <param name="tableObj">The table to convert to html.</param>
        private void CreateTable(Section section, AutoDocumentation.Table tableObj)
        {
            var table = section.AddTable();

            table.Style               = tableObj.Style;
            table.Borders.Color       = Colors.Blue;
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;

            var       fontSize = section.Document.Styles[tableObj.Style].Font.Size.Value;
            var       gdiFont  = new XFont("Arial", fontSize);
            XGraphics graphics = XGraphics.CreateMeasureContext(new XSize(2000, 2000), XGraphicsUnit.Point, XPageDirection.Downwards);

            // Add the required columns to the table.
            foreach (DataColumn column in tableObj.data.Table.Columns)
            {
                var column1 = table.AddColumn();
                column1.Format.Alignment = ParagraphAlignment.Right;
            }

            // Add a heading row.
            var headingRow = table.AddRow();

            headingRow.HeadingFormat    = true;
            headingRow.Format.Font.Bold = true;
            headingRow.Shading.Color    = Colors.LightBlue;

            for (int columnIndex = 0; columnIndex < tableObj.data.Table.Columns.Count; columnIndex++)
            {
                // Get column heading
                string heading = tableObj.data.Table.Columns[columnIndex].ColumnName;
                headingRow.Cells[columnIndex].AddParagraph(heading);

                // Get the width of the column
                double maxSize = graphics.MeasureString(heading, gdiFont).Width;
                for (int rowIndex = 0; rowIndex < tableObj.data.Count; rowIndex++)
                {
                    // Add a row to our table if processing first column.
                    MigraDoc.DocumentObjectModel.Tables.Row row;
                    if (columnIndex == 0)
                    {
                        table.AddRow();
                    }

                    // Get the row to process.
                    row = table.Rows[rowIndex + 1];

                    // Convert potential HTML to the cell in our row.
                    HtmlToMigraDoc.Convert(tableObj.data[rowIndex][columnIndex].ToString(),
                                           row.Cells[columnIndex],
                                           WorkingDirectory);

                    // Update the maximum size of the column with the value from the current row.
                    foreach (var element in row.Cells[columnIndex].Elements)
                    {
                        if (element is Paragraph)
                        {
                            var paragraph = element as Paragraph;
                            var contents  = string.Empty;
                            foreach (var paragraphElement in paragraph.Elements)
                            {
                                if (paragraphElement is MigraDoc.DocumentObjectModel.Text)
                                {
                                    contents += (paragraphElement as MigraDoc.DocumentObjectModel.Text).Content;
                                }
                                else if (paragraphElement is MigraDoc.DocumentObjectModel.Hyperlink)
                                {
                                    contents += (paragraphElement as MigraDoc.DocumentObjectModel.Hyperlink).Name;
                                }
                            }

                            var size = graphics.MeasureString(contents, gdiFont);
                            maxSize = Math.Max(maxSize, size.Width);
                        }
                    }
                }

                // maxWidth is the maximum allowed width of the column. E.g. if tableObj.ColumnWidth
                // is 50, then maxWidth is the amount of space taken up by 50 characters.
                // maxSize, on the other hand, is the length of the longest string in the column.
                // The actual column width is whichever of these two values is smaller.
                // MigraDoc will automatically wrap text to ensure the column respects this width.
                double maxWidth = graphics.MeasureString(new string('m', tableObj.ColumnWidth), gdiFont).Width;
                table.Columns[columnIndex].Width = Unit.FromPoint(Math.Min(maxWidth, maxSize) + 0);
            }

            section.AddParagraph();
        }
        public byte[] Create(string content)
        {
            // http://pdfsharp.net/wiki/PrivateFonts-sample.ashx
            // http://stackoverflow.com/questions/31568349/error-accessing-fonts-in-azure-web-app-when-using-pdfsharp
            var familyName = "Verdana";

            using (PdfDocument document = new PdfDocument())
            {
                document.Info.Title = "Jira Agile Cards";

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(content);

                if (xml.DocumentElement == null)
                {
                    throw new NotSupportedException("Xml document is invalid!");
                }

                var nodes = xml.DocumentElement.SelectNodes("//rss/channel/item");
                if (nodes == null)
                {
                    throw new NotSupportedException("Xml document is invalid!");
                }

                foreach (XmlNode node in nodes)
                {
                    var summary  = GetNodeValue(node, "summary");
                    var issueNo  = GetNodeValue(node, "key");
                    var parentNo = GetNodeValue(node, "parent");
                    var priority = GetNodeValue(node, "priority");
                    var taskType = GetNodeValue(node, "type");

                    var taskEstimate = GetNodeValue(node, "timeoriginalestimate");

                    if (taskType == "Story")
                    {
                        taskEstimate = GetNodeValue(node, "aggregatetimeoriginalestimate");
                        var customFields = node.SelectNodes("customfields/customfield");
                        if (customFields != null)
                        {
                            foreach (XmlNode customField in customFields)
                            {
                                var name = GetNodeValue(customField, "customfieldname");
                                if (name == "Story Points")
                                {
                                    var values = customField.SelectSingleNode("customfieldvalues");
                                    if (values != null)
                                    {
                                        var value = GetNodeValue(values, "customfieldvalue");
                                        if (!string.IsNullOrEmpty(value))
                                        {
                                            taskEstimate = value;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    var page = document.AddPage();
                    page.Size        = PageSize.A4;
                    page.Orientation = PageOrientation.Landscape;

                    XGraphics gfx = XGraphics.FromPdfPage(page);

                    gfx.DrawLine(XPens.Black, new XPoint(10, 450), new XPoint(610, 450));

                    XTextFormatter tf = new XTextFormatter(gfx)
                    {
                        Alignment = XParagraphAlignment.Left
                    };

                    var   summaryRectangle = new XRect(10, 10, 600, 450);
                    XFont summaryFont      = new XFont(familyName, 48, XFontStyle.Regular);
                    tf.DrawString(summary, summaryFont, XBrushes.Black, summaryRectangle, XStringFormats.TopLeft);

                    XFont issueNoFont      = new XFont(familyName, 36, XFontStyle.Regular);
                    var   issueNoRectangle = new XRect(10, 460, 290, 50);
                    tf.Alignment = XParagraphAlignment.Left;
                    tf.DrawString(issueNo, issueNoFont, XBrushes.Black, issueNoRectangle);

                    XFont parentNoFont      = new XFont(familyName, 26, XFontStyle.Regular);
                    var   parentNoRectangle = new XRect(320, 460, 290, 50);
                    tf.Alignment = XParagraphAlignment.Right;
                    tf.DrawString(parentNo, parentNoFont, XBrushes.DimGray, parentNoRectangle);

                    XFont priorityFont      = new XFont(familyName, 24, XFontStyle.Italic);
                    var   priorityRectangle = new XRect(10, 510, 290, 50);
                    tf.Alignment = XParagraphAlignment.Left;
                    tf.DrawString(priority, priorityFont, XBrushes.Black, priorityRectangle);

                    XFont taskTypeFont      = new XFont(familyName, 24, XFontStyle.Italic);
                    var   taskTypeRectangle = new XRect(320, 510, 290, 50);
                    tf.Alignment = XParagraphAlignment.Right;
                    tf.DrawString(taskType, taskTypeFont, XBrushes.Black, taskTypeRectangle);

                    var p1 = new XPoint(650, 10);
                    var p2 = new XPoint(800, 10);
                    var p3 = new XPoint(800, 160);
                    var p4 = new XPoint(650, 160);

                    gfx.DrawLines(XPens.Black, new[] { p1, p2, p3, p4, p1 });

                    XFont estimateFont      = new XFont(familyName, 48, XFontStyle.Regular);
                    var   estimateRectangle = new XRect(650, 50, 150, 100);
                    tf.Alignment = XParagraphAlignment.Center;
                    tf.DrawString(taskEstimate, estimateFont, XBrushes.Black, estimateRectangle);
                }

                using (var exportStream = new MemoryStream())
                {
                    document.Save(exportStream);
                    var array = exportStream.ToArray();
                    return(array);
                }
            }
        }
Exemple #16
0
    private void PrintSalesStatement()
    {
        #region variables
        double   bookPrice;
        double   cdPrice;
        double   sheetPrice;
        int      bookQty;
        int      cdQty;
        int      sheetQty;
        int      flag      = 0;
        int      pageCount = 1;
        string   strfd     = txtFromDate.Text;
        string[] strDate   = strfd.Split('-');
        string   date      = strDate[0];
        string   Month     = strDate[1];
        string   Year      = strDate[2];
        strfd = Year + '-' + Month + '-' + date;
        string strto = txtToDate.Text;
        strDate = strto.Split('-');
        date    = strDate[0];
        Month   = strDate[1];
        Year    = strDate[2];
        strto   = Year + '-' + Month + '-' + date;
        #endregion

        #region query

        DataTable dt1 = new Facade().GetReportByFromAndTo(strfd, strto, true, false, false); //dbHandler.GetDataTable(sql1);


//        string sql2 = @"select os.articlecode as ArticleCode,a.title as Title, Sum(unitprice) as Price,sum(os.quantity) as Quantity
//                    from orders o, ordersline os , article a
//                    where o.orderid = os.orderid
//                    and os.articlecode=a.articlecode
//                    and o.orderdate between '" + strfd + "' and '" + strto + @"'
//                    and (os.articlecode like 'c%' or os.articlecode like 'd%')
//                    group by os.articlecode,a.title
//                    order by Quantity desc, Price desc";

        DataTable dt2 = new Facade().GetReportByFromAndTo(strfd, strto, false, true, false); //dbHandler.GetDataTable(sql2);



        DataTable dt3 = new Facade().GetReportByFromAndTo(strfd, strto, false, false, true);

        #endregion
        // Create a new PDF document
        PdfDocument document = new PdfDocument();


        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

        int x = 30, y = 80;



        // Create a font
        XFont font_hdr   = new XFont("Arial", 20, XFontStyle.Regular);
        XFont font       = new XFont("Arial", 15, XFontStyle.Regular);
        XFont font_small = new XFont("Arial", 10, XFontStyle.Regular);

        XPen pen      = new XPen(XColor.FromArgb(50, 0, 0, 0), 2);
        XPen totalPen = new XPen(XColor.FromName("black"), 1);


        XTextFormatter tf  = new XTextFormatter(gfx);
        XTextFormatter tf1 = new XTextFormatter(gfx);
        XTextFormatter tf2 = new XTextFormatter(gfx);
        tf.Alignment  = XParagraphAlignment.Right;
        tf1.Alignment = XParagraphAlignment.Center;
        tf2.Alignment = XParagraphAlignment.Left;


        int   i       = 0;
        XRect rec_hdr = new XRect(x + 200, y - 65, 300, 100);
        tf2.DrawString("Sales Statement", font_hdr, XBrushes.Black, rec_hdr);
        XRect rec = new XRect(x - 22, y - 35, 200, 100);
        tf.DrawString("Date Range: " + txtFromDate.Text + " to: " + txtToDate.Text + "", font_small, XBrushes.Black, rec);
        XRect rec_b = new XRect(x, y - 20, 200, 100);
        tf2.DrawString("Books", font, XBrushes.Black, rec_b);
        gfx.DrawLine(pen, 30, y + 3, 600, y + 3);
        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        XRect rec1 = new XRect(x, y + 3, 570, 11);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec1);
        tf2.DrawString("Article Code", font_small, XBrushes.Black, new XRect(x + 15, y + 5, 110, 100));
        tf.DrawString("Title", font_small, XBrushes.Black, new XRect(x + 70, y + 5, 110, 100));
        tf.DrawString("Quantity", font_small, XBrushes.Black, new XRect(x + 300, y + 5, 110, 100));
        tf.DrawString("Price", font_small, XBrushes.Black, new XRect(x + 400, y + 5, 110, 100));


        //double sum = dt1.Columns[2].com
        DataColumn sumofBookPrice = new DataColumn("sum", Type.GetType("System.Double"), "sum(Price)");
        dt1.Columns.Add(sumofBookPrice);


        DataColumn sumofBookQty = new DataColumn("qty", Type.GetType("System.Int32"), "sum(Quantity)");
        dt1.Columns.Add(sumofBookQty);

        DataColumn sumofCD = new DataColumn("sum", Type.GetType("System.Double"), "sum(Price)");
        dt2.Columns.Add(sumofCD);

        DataColumn sumofCDQty = new DataColumn("qty", Type.GetType("System.Int32"), "sum(Quantity)");
        dt2.Columns.Add(sumofCDQty);

        DataColumn sumofSheet = new DataColumn("sum", Type.GetType("System.Double"), "sum(Price)");
        dt3.Columns.Add(sumofSheet);

        DataColumn sumofSheetQty = new DataColumn("qty", Type.GetType("System.Int32"), "sum(Quantity)");
        dt3.Columns.Add(sumofSheetQty);

        try
        {
            bookPrice = Convert.ToDouble(dt1.Rows[0]["sum"].ToString());
            bookQty   = Convert.ToInt32(dt1.Rows[0]["qty"].ToString());
        }
        catch
        {
            bookPrice = 0.0;
            bookQty   = 0;
        }
        try
        {
            cdPrice = Convert.ToDouble(dt2.Rows[0]["sum"].ToString());
            cdQty   = Convert.ToInt32(dt1.Rows[0]["qty"].ToString());
        }
        catch
        {
            cdPrice = 0.0;
            cdQty   = 0;
        }
        try
        {
            sheetPrice = Convert.ToDouble(dt3.Rows[0]["sum"].ToString());
            sheetQty   = Convert.ToInt32(dt3.Rows[0]["qty"].ToString());
        }
        catch
        {
            sheetPrice = 0.0;
            sheetQty   = 0;
        }


        foreach (DataRow row in dt1.Rows)
        {
            y += 25;
            tf2.DrawString(dt1.Rows[i]["ArticleCode"].ToString(), font_small, XBrushes.Black, new XRect(x + 20, y, 110, 100));
            tf2.DrawString(dt1.Rows[i]["Title"].ToString(), font_small, XBrushes.Black, new XRect(x + 90, y, 300, 100));
            tf.DrawString(dt1.Rows[i]["Quantity"].ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 100));
            tf.DrawString(dt1.Rows[i]["Price"].ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 100));
            i++;
            if (gfx.PageSize.Height - y <= 100)
            {
                page          = document.AddPage();
                gfx           = XGraphics.FromPdfPage(page);
                tf            = new XTextFormatter(gfx);
                tf1           = new XTextFormatter(gfx);
                tf2           = new XTextFormatter(gfx);
                tf.Alignment  = XParagraphAlignment.Right;
                tf1.Alignment = XParagraphAlignment.Center;
                tf2.Alignment = XParagraphAlignment.Left;
                y             = 50;
                ++pageCount;
            }
        }
        gfx.DrawLine(totalPen, 380, y + 15, 580, y + 15);
        y += 25;
        tf.DrawString("Total", font_small, XBrushes.Black, new XRect(x + 220, y, 110, 125));
        tf.DrawString(bookQty.ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 125));
        tf.DrawString(bookPrice.ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 125));
        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        i  = 0;
        y += 40;
        XRect rec_cd = new XRect(x, y, 200, 50);
        tf2.DrawString("CD/DVD", font, XBrushes.Black, rec_cd);
        gfx.DrawLine(pen, 30, y + 22, 600, y + 22);
        gfx.DrawLine(pen, 30, y + 36, 600, y + 36);
        XRect rec2 = new XRect(x, y + 22, 570, 15);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec2);
        y += 20;

        tf2.DrawString("Article Code", font_small, XBrushes.Black, new XRect(x + 15, y + 5, 110, 100));
        tf.DrawString("Title", font_small, XBrushes.Black, new XRect(x + 70, y + 5, 110, 100));
        tf.DrawString("Quantity", font_small, XBrushes.Black, new XRect(x + 300, y + 5, 110, 100));
        tf.DrawString("Price", font_small, XBrushes.Black, new XRect(x + 400, y + 5, 110, 100));

        foreach (DataRow row in dt2.Rows)
        {
            y += 25;
            //x += 50;
            tf2.DrawString(dt2.Rows[i]["ArticleCode"].ToString(), font_small, XBrushes.Black, new XRect(x + 20, y, 110, 100));
            tf2.DrawString(dt2.Rows[i]["Title"].ToString(), font_small, XBrushes.Black, new XRect(x + 90, y, 300, 100));
            tf.DrawString(dt2.Rows[i]["Quantity"].ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 100));
            tf.DrawString(dt2.Rows[i]["Price"].ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 100));
            i++;
            if (gfx.PageSize.Height - y <= 100)
            {
                page          = document.AddPage();
                gfx           = XGraphics.FromPdfPage(page);
                tf            = new XTextFormatter(gfx);
                tf1           = new XTextFormatter(gfx);
                tf2           = new XTextFormatter(gfx);
                tf.Alignment  = XParagraphAlignment.Right;
                tf1.Alignment = XParagraphAlignment.Center;
                tf2.Alignment = XParagraphAlignment.Left;
                y             = 50;
                ++pageCount;
            }
        }

        gfx.DrawLine(totalPen, 380, y + 15, 580, y + 15);
        y += 25;
        tf.DrawString("Total", font_small, XBrushes.Black, new XRect(x + 220, y, 110, 125));
        tf.DrawString(cdQty.ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 125));
        tf.DrawString(cdPrice.ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 125));

        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        i  = 0;
        y += 40;


        XRect rec_sm = new XRect(x, y, 200, 50);
        tf2.DrawString("Sheet Music", font, XBrushes.Black, rec_sm);
        gfx.DrawLine(pen, 30, y + 22, 600, y + 22);
        gfx.DrawLine(pen, 30, y + 36, 600, y + 36);
        XRect rec3 = new XRect(x, y + 22, 570, 15);
        gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(120, 204, 204, 204)), rec3);
        y += 20;

        tf2.DrawString("Article Code", font_small, XBrushes.Black, new XRect(x + 15, y + 5, 110, 100));
        tf.DrawString("Title", font_small, XBrushes.Black, new XRect(x + 70, y + 5, 110, 100));
        tf.DrawString("Quantity", font_small, XBrushes.Black, new XRect(x + 300, y + 5, 110, 100));
        tf.DrawString("Price", font_small, XBrushes.Black, new XRect(x + 400, y + 5, 110, 100));

        foreach (DataRow row in dt3.Rows)
        {
            y += 25;
            tf2.DrawString(dt3.Rows[i]["ArticleCode"].ToString(), font_small, XBrushes.Black, new XRect(x + 20, y, 110, 100));
            tf2.DrawString(dt3.Rows[i]["Title"].ToString(), font_small, XBrushes.Black, new XRect(x + 90, y, 300, 100));
            tf.DrawString(dt3.Rows[i]["Quantity"].ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 100));
            tf.DrawString(dt3.Rows[i]["Price"].ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 100));
            i++;
            if (gfx.PageSize.Height - y <= 100)
            {
                page          = document.AddPage();
                gfx           = XGraphics.FromPdfPage(page);
                tf            = new XTextFormatter(gfx);
                tf1           = new XTextFormatter(gfx);
                tf2           = new XTextFormatter(gfx);
                tf.Alignment  = XParagraphAlignment.Right;
                tf1.Alignment = XParagraphAlignment.Center;
                tf2.Alignment = XParagraphAlignment.Left;
                y             = 50;
                ++pageCount;
            }
        }

        gfx.DrawLine(totalPen, 380, y + 15, 580, y + 15);
        y += 25;
        tf.DrawString("Total", font_small, XBrushes.Black, new XRect(x + 220, y, 110, 125));
        tf.DrawString(sheetQty.ToString(), font_small, XBrushes.Black, new XRect(x + 300, y, 110, 125));
        tf.DrawString(sheetPrice.ToString(), font_small, XBrushes.Black, new XRect(x + 400, y, 110, 125));

        gfx.DrawLine(pen, 30, y + 15, 600, y + 15);
        MemoryStream sm = new MemoryStream();
        document.Save(sm, false);

        PdfDocument finalDoc  = PdfReader.Open(sm, PdfDocumentOpenMode.Import);
        PdfDocument outputDoc = new PdfDocument();
        for (int counter = 0; counter < document.Pages.Count; counter++)
        {
            PdfPage p = finalDoc.Pages[counter];
            outputDoc.AddPage(p);
            XGraphics xGraphics = XGraphics.FromPdfPage(outputDoc.Pages[counter]);

            tf            = new XTextFormatter(xGraphics);
            tf1           = new XTextFormatter(xGraphics);
            tf2           = new XTextFormatter(xGraphics);
            tf.Alignment  = XParagraphAlignment.Right;
            tf1.Alignment = XParagraphAlignment.Center;
            tf2.Alignment = XParagraphAlignment.Left;

            xGraphics.DrawString("Page " + (counter + 1) + " of " + pageCount + ".", font_small, XBrushes.Black, 30, xGraphics.PageSize.Height - 25);
            xGraphics.Dispose();
        }



        MemoryStream stream = new MemoryStream();
        //document.Save(stream, false);
        outputDoc.Save(stream, false);
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-length", stream.Length.ToString());
        Response.BinaryWrite(stream.ToArray());
        Response.Flush();
        stream.Close();
        Response.End();
    }
 string IContentStream.GetFontName(XFont font, out PdfFont pdfFont)
 {
     return(GetFontName(font, out pdfFont));
 }
 /// <summary>
 /// Draws the text.
 /// </summary>
 /// <param name="text">The text to be drawn.</param>
 /// <param name="font">The font.</param>
 /// <param name="brush">The text brush.</param>
 /// <param name="layoutRectangle">The layout rectangle.</param>
 /// <return>The height of the string</return>
 public int DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle)
 {
     return(DrawString(text, font, brush, layoutRectangle, XStringFormats.TopLeft));
 }
 /// <summary>
 /// Gets the resource name of the specified font within this page or form.
 /// </summary>
 internal string GetFontName(XFont font, out PdfFont pdfFont)
 {
     if (_page != null)
         return _page.GetFontName(font, out pdfFont);
     return _form.GetFontName(font, out pdfFont);
 }
        public static byte[] ConsultarCertificadoCertame(int certificadoId, string cpf)
        {
            var usuario = new BMUsuario().ObterPorCPF(cpf);

            if (usuario == null)
            {
                return(null);
            }

            var certificadoUsuario =
                usuario.ListaUsuarioCertificadoCertame.FirstOrDefault(x => x.CertificadoCertame.ID == certificadoId);

            if (certificadoUsuario == null)
            {
                return(null);
            }

            var certificado = certificadoUsuario.CertificadoCertame;

            // Removendo caracteres especiais que travam no chrome.
            certificado.Certificado.NomeDoArquivoOriginal =
                RemoverCaracterEspecial(certificado.Certificado.NomeDoArquivoOriginal);

            // Create the output document
            var outputDocument = new PdfDocument {
                PageLayout = PdfPageLayout.TwoPageLeft
            };

            var font   = new XFont("Verdana", 13);
            var format = new XStringFormat
            {
                Alignment     = XStringAlignment.Center,
                LineAlignment = XLineAlignment.Center
            };

            try
            {
                var repositorioUpload =
                    ConfiguracaoSistemaUtil.ObterInformacoes(enumConfiguracaoSistema.RepositorioUpload).Registro;
                var filePath = string.Concat(repositorioUpload, @"\", certificado.Certificado.NomeDoArquivoNoServidor);

                using (var ms = new MemoryStream())
                {
                    using (
                        var file =
                            new FileStream(
                                filePath,
                                FileMode.Open,
                                FileAccess.Read
                                )
                        )
                    {
                        var bytes = new byte[file.Length];
                        file.Read(bytes, 0, (int)file.Length);
                        ms.Write(bytes, 0, (int)file.Length);
                    }

                    // Por alguma bizarrice, tem que recriar o Stream.
                    var form = XPdfForm.FromStream(new MemoryStream(ms.ToArray()));

                    // Escrever FRENTE do certificado.
                    EscreverFrente(outputDocument, form, certificadoUsuario, font, format);

                    // Escrever VERSO do certificado.
                    EscreverVerso(outputDocument, form, certificadoUsuario, font, format);

                    var streamOutput = new MemoryStream();
                    outputDocument.Save(streamOutput, false);

                    return(streamOutput.ToArray());
                }
            }
            catch
            {
                return(null);
            }
        }
 /// <summary>
 /// Gets the resource name of the specified font within this page or form.
 /// </summary>
 internal string GetFontName(XFont font, out PdfFont pdfFont)
 {
   if (this.page != null)
     return this.page.GetFontName(font, out pdfFont);
   else
     return this.form.GetFontName(font, out pdfFont);
 }
        private static byte[] GerarBoletim(UsuarioCertificadoCertame certificadoUsuario, string repostorioArquivo, DateTime horaAtual)
        {
            var outputDocument = new PdfDocument {
                PageLayout = PdfPageLayout.SinglePage
            };

            var font         = new XFont("Verdana", 12);
            var fontBold     = new XFont("Verdana", 12, XFontStyle.Bold);
            var centerFormat = new XStringFormat
            {
                Alignment     = XStringAlignment.Center,
                LineAlignment = XLineAlignment.Center
            };
            var leftFormat = new XStringFormat
            {
                Alignment     = XStringAlignment.Near,
                LineAlignment = XLineAlignment.Center
            };

            var pagina = outputDocument.AddPage();

            pagina.Orientation = PageOrientation.Portrait;
            pagina.Size        = PageSize.A4;

            var gfx = XGraphics.FromPdfPage(pagina);

            // Desenhar a logo do CESPE.
            gfx.DrawImage(XImage.FromFile(Path.Combine(repostorioArquivo, "BoletinsCertame", "cespe.png")),
                          new XRect(new XPoint(10, 10), new XPoint(130, 50)));

            // Desenhar data e hora
            gfx.DrawString(horaAtual.ToString("G", new CultureInfo("pt-BR")), new XFont("Verdana", 8), XBrushes.Black, pagina.Width / 2, 10, centerFormat);

            // Desenhar cabeçalho.
            gfx.DrawString("SEBRAE NACIONAL - Serviço de Apoio às Micro e Pequenas Empresas", font, XBrushes.Black,
                           pagina.Width / 2, 70, centerFormat);
            gfx.DrawString($"CERTIFICAÇÃO INTERNA DE CONHECIMENTOS - {certificadoUsuario.CertificadoCertame.Ano}", font,
                           XBrushes.Black, pagina.Width / 2, 90, centerFormat);
            gfx.DrawString("ESPELHO DE DESEMPENHO", font, XBrushes.Black, pagina.Width / 2, 110, centerFormat);

            // Desenhar dados do usuário
            gfx.DrawString("Nome:", fontBold, XBrushes.Black, 50, 140, leftFormat);
            gfx.DrawString(certificadoUsuario.Usuario.Nome, font, XBrushes.Black, 130, 140, leftFormat);

            gfx.DrawString("CPF:", fontBold, XBrushes.Black, 50, 160, leftFormat);
            gfx.DrawString(certificadoUsuario.Usuario.CPF, font, XBrushes.Black, 130, 160, leftFormat);

            gfx.DrawString("Inscrição:", fontBold, XBrushes.Black, 50, 180, leftFormat);
            gfx.DrawString(certificadoUsuario.NumeroInscricao ?? "", font, XBrushes.Black, 130, 180, leftFormat);

            gfx.DrawString("Unidade:", fontBold, XBrushes.Black, 50, 200, leftFormat);
            gfx.DrawString(certificadoUsuario.Usuario.Unidade ?? "", font, XBrushes.Black, 130, 200, leftFormat);

            // Desenhar a tabela.
            DesenharTabela(gfx, certificadoUsuario, pagina);

            var streamOutput = new MemoryStream();

            outputDocument.Save(streamOutput, false);

            return(streamOutput.ToArray());
        }
Exemple #23
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="text">The text to be drawn.</param>
        /// <param name="font">The font.</param>
        /// <param name="brush">The text brush.</param>
        /// <param name="layoutRectangle">The layout rectangle.</param>
        /// <param name="format">The format. Must be <c>XStringFormat.TopLeft</c></param>
        public void DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
        {
            if (text == null)
                throw new ArgumentNullException("text");
            if (font == null)
                throw new ArgumentNullException("font");
            if (brush == null)
                throw new ArgumentNullException("brush");
            if (format.Alignment != XStringAlignment.Near || format.LineAlignment != XLineAlignment.Near)
                throw new ArgumentException("Only TopLeft alignment is currently implemented.");

            Text = text;
            Font = font;
            LayoutRectangle = layoutRectangle;

            if (text.Length == 0)
                return;

            CreateBlocks();

            CreateLayout();

            double dx = layoutRectangle.Location.X;
            double dy = layoutRectangle.Location.Y + _cyAscent;
            int count = _blocks.Count;
            for (int idx = 0; idx < count; idx++)
            {
                Block block = _blocks[idx];
                if (block.Stop)
                    break;
                if (block.Type == BlockType.LineBreak)
                    continue;
                _gfx.DrawString(block.Text, font, brush, dx + block.Location.X, dy + block.Location.Y);
            }
        }
        public void printBill()
        {
            try
            {
                int    i         = 0;
                int    yPoint    = 0;
                string TenMonAn  = null;
                string SoLuong   = null;
                string DonGia    = null;
                string ThanhTien = null;
                string MaHoaDon  = null;
                if (idBanAn != null)
                {
                    ThanhTien = Double.Parse(HOADONBAN.Ins.getTongTienTheoBanAn(idBanAn).Rows[0][0].ToString()).ToString("#,##0");
                }

                // connetionString = "Data Source=THANHNGUYEN;Initial Catalog=QLKH;User ID=sa;Password=1334567701";
                // sql = "select TenMonAn,SoLuong,DonGia from TestHoaDon";
                // connection = new SqlConnection(connetionString);
                // connection.Open();
                // command = new SqlCommand(sql, connection);
                // adapter.SelectCommand = command;
                // adapter.Fill(ds);
                // connection.Close();
                DataTable   ds      = BLL.MONAN.Ins.getListMonTheoId(idBanAn);
                string      NgayBan = ds.Rows[0].ItemArray[4].ToString();
                PdfDocument pdf     = new PdfDocument();
                pdf.Info.Title = "Database to PDF";
                PdfPage   pdfPage = pdf.AddPage();
                XGraphics graph   = XGraphics.FromPdfPage(pdfPage);
                XFont     font    = new XFont("Verdana", 10, XFontStyle.Regular);
                XFont     Font_1  = new XFont("Verdana", 30, XFontStyle.Regular);
                yPoint = yPoint + 100;
                graph.DrawString("Hóa Đơn Bán", Font_1, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 50;
                graph.DrawString("khu phố 6 phường Linh Trung ", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("--------------------------------------------------------", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Mã Hóa Đơn", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(idBanAn, font, XBrushes.Black, new XRect(120, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Ngày Bán", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString(NgayBan, font, XBrushes.Black, new XRect(120, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("--------------------------------------------------------", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Tên Món Ăn", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Số Lượng", font, XBrushes.Black, new XRect(160, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                graph.DrawString("Đơn Giá", font, XBrushes.Black, new XRect(250, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                for (i = 0; i <= ds.Rows.Count - 1; i++)
                {
                    TenMonAn = ds.Rows[i].ItemArray[1].ToString();
                    SoLuong  = ds.Rows[i].ItemArray[3].ToString();
                    DonGia   = ds.Rows[i].ItemArray[2].ToString();

                    graph.DrawString(TenMonAn, font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                    graph.DrawString(SoLuong, font, XBrushes.Black, new XRect(160, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                    graph.DrawString(DonGia, font, XBrushes.Black, new XRect(250, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                    yPoint = yPoint + 20;
                }
                graph.DrawString("--------------------------------------------------------", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                yPoint = yPoint + 20;
                graph.DrawString("Tổng Tiền", font, XBrushes.Black, new XRect(40, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                graph.DrawString(ThanhTien, font, XBrushes.Black, new XRect(250, yPoint, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

                string pdfFilename = "dbtopdf.pdf";
                pdf.Save(pdfFilename);
                Process.Start(pdfFilename);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public static void DrawGridLine(List <CellDisplay> listCellDisplay,
                                        PagingSetup pagingSetup, PdfDocument document, XFont font,
                                        double lineHeight)
        {
            PdfPage currentPage = document.Pages[document.Pages.Count - 1];

            using (var gfx = XGraphics.FromPdfPage(currentPage))
            {
                var    regularPen = new XPen(XColor.FromArgb(255, 0, 0, 0));
                double lineWidth  = currentPage.Width - pagingSetup.MarginLeft - pagingSetup.MarginRight;

                double offsetRect = pagingSetup.MarginLeft;
                for (int i = 0; i < listCellDisplay.Count; i++)
                {
                    double rectWidth = lineWidth * listCellDisplay[i].Ratio / 100;
                    var    gridRect  = new XRect(offsetRect, pagingSetup.CurrentOffset, rectWidth, lineHeight);
                    gfx.DrawRectangle(regularPen, gridRect);
                    if (listCellDisplay[i].DisplayText != null)
                    {
                        gridRect = new XRect(offsetRect + listCellDisplay[i].PaddingLeft, pagingSetup.CurrentOffset, rectWidth - 2 * listCellDisplay[i].PaddingLeft, lineHeight);
                        gfx.DrawString(listCellDisplay[i].DisplayText, font, XBrushes.Black,
                                       gridRect, listCellDisplay[i].CellAlign);
                    }

                    offsetRect += rectWidth;
                }
            }
            IncreaseLineHeight(pagingSetup, document, lineHeight);
        }
Exemple #26
0
        public void CreatePDF(Sale sale)
        {
            // Her bruges classen pdfDocument.
            PdfDocument document = new PdfDocument();

            // Her laver jeg et pdf dokument og kalder det Faktura
            document.Info.Title = "Faktura";

            // Her laves en side
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Opret skrift størelse og stil
            XFont companyAndDebtor = new XFont("Calibri", 10, XFontStyle.Regular);
            XFont fakture          = new XFont("Calibri", 20, XFontStyle.Bold);
            XFont smallHeadLine    = new XFont("Calibri", 10, XFontStyle.Bold);
            XFont priceFat         = new XFont("Calibri", 10, XFontStyle.Bold);

            // Draw the text. Dette er hvad der skal være på teksten, og hvor det skal være. Der kan laves lige så mange som man vil
            //Kunde Oplysninger------------------------------------------------------------------------------------------------------------------------------
            if (sale.customer == null)
            {
            }
            else
            {
                gfx.DrawString((string)sale.customer.name, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -270, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString((string)sale.customer.address, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -260, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString((string)sale.customer.email, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -250, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString((string)sale.customer.phone, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -230, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            //FAKTURA---------------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("FAKTURA", fakture, XBrushes.Black,
                           new XRect(80, -170, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Billede af Firmallogo---------------------------------------------------------------------------------------
            //Mangler


            //Firma informationer----------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("AnimalHouse", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -300, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Snudesvej 1", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -290, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("7100 Vejle", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -280, page.Width, page.Height),
                           XStringFormats.CenterRight);


            //BankOplysninger------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("Bank ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -250, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Reg. Nr:3141", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -240, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Konto Nr:5926535897932384 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -230, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Ordrenummer " + sale.saleID.ToString(), companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -180, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Dato " + sale.salesDay.ToString("dd-MM-yyyy"), companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -170, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Navn på vare antal pris beløb-------------------------------------------------------------------------------------------------------------
            //varens navn
            gfx.DrawString("Vare", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -130, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Antal
            gfx.DrawString("Antal", companyAndDebtor, XBrushes.Black,
                           new XRect(-80, -130, page.Width, page.Height),
                           XStringFormats.Center);

            //Stykpris
            gfx.DrawString("Stykpris", companyAndDebtor, XBrushes.Black,
                           new XRect(90, -130, page.Width, page.Height),
                           XStringFormats.Center);

            //I alt
            gfx.DrawString("I alt", companyAndDebtor, XBrushes.Black,
                           new XRect(200, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -125, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            int lineSpace = 0;

            for (int i = 0; i < sale.saleLineItems.Count; i++)
            {
                //Her bliver Variablen sat til 15. så hver gange der bliver kørt GetLeaseOrders(tilføjet en ny vare linje bliver der pludset 15 til y aksens position)
                lineSpace = 15 * i;

                //varens navn
                gfx.DrawString((string)sale.saleLineItems[i].item.name, companyAndDebtor, XBrushes.Black,
                               new XRect(80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                //Antal
                gfx.DrawString(sale.saleLineItems[i].amount.ToString(), companyAndDebtor, XBrushes.Black,
                               new XRect(-80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                //Stykpris
                gfx.DrawString((sale.saleLineItems[i].price.ToString() + " Kr"), companyAndDebtor, XBrushes.Black,
                               new XRect(90, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                //I alt
                decimal priceSum = sale.Price();
                gfx.DrawString((priceSum.ToString() + " Kr"), companyAndDebtor, XBrushes.Black,
                               new XRect(200, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);
            }

            //Hvis det er erhvers person
            if (sale.customer != null)
            {
                if (sale.customer.GetType() == typeof(BusinessCustomer))
                {
                    gfx.DrawString("Total: ", priceFat, XBrushes.Black,
                                   new XRect(400, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);



                    gfx.DrawString(sale.Price() + " Kr", companyAndDebtor, XBrushes.Black,
                                   new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);

                    gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                                   new XRect(400, -15 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);
                }

                else
                {
                    decimal momsPrice         = sale.Moms();
                    decimal totalPriceInkMoms = sale.TotalPriceInkMoms();

                    gfx.DrawString("Netto: ", companyAndDebtor, XBrushes.Black,
                                   new XRect(400, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);

                    gfx.DrawString("Moms (25%): ", companyAndDebtor, XBrushes.Black,
                                   new XRect(400, -5 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);

                    gfx.DrawString("Total ink. Moms: ", priceFat, XBrushes.Black,
                                   new XRect(400, 10 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);

                    //Viser den totate nettopris
                    gfx.DrawString(sale.Price() + " Kr", companyAndDebtor, XBrushes.Black,
                                   new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);

                    //Viser prisen på momsen
                    gfx.DrawString(momsPrice.ToString() + " Kr", companyAndDebtor, XBrushes.Black,
                                   new XRect(-60, -5 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);


                    //viser den totale pris ink moms
                    gfx.DrawString(totalPriceInkMoms.ToString() + " Kr", priceFat, XBrushes.Black,
                                   new XRect(-60, 10 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterRight);

                    gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                                   new XRect(400, 15 + lineSpace, page.Width, page.Height),
                                   XStringFormats.CenterLeft);
                }
            }
            else
            {
                decimal momsPrice         = sale.Moms();
                decimal totalPriceInkMoms = sale.TotalPriceInkMoms();

                gfx.DrawString("Netto: ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Moms (25%): ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Total ink. Moms: ", priceFat, XBrushes.Black,
                               new XRect(400, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                //Viser den totate nettopris
                gfx.DrawString(sale.Price() + " Kr", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                //Viser prisen på momsen
                gfx.DrawString(momsPrice.ToString() + " Kr", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);


                //viser den totale pris ink moms
                gfx.DrawString(totalPriceInkMoms.ToString() + " Kr", priceFat, XBrushes.Black,
                               new XRect(-60, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                               new XRect(400, 15 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -100 + lineSpace, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Her Laves navnet på filen
            string filename = "Faktura" + sale.saleID.ToString() + ".pdf";

            //Dette er til at gemme pdf
            document.Save(filename);
        }
        private void GenerateSummaryPage(XGraphics gfx, int firstIndex)
        {
            //======================================================================================================================================//
            //Add summary header
            var font       = new XFont("Calibri", 30.0, XFontStyle.Bold);
            var stringSize = gfx.MeasureString("SUMMARY", font);
            var rect       = new XRect(Margin, Margin, UsableWidth, font.GetHeight());

            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("SUMMARY", font, TextBrush, rect, XStringFormats.TopLeft);

            //======================================================================================================================================//
            //Add: Summary header boxes
            int bigBoxW    = (int)UsableWidth / 2,
                smallBoxW  = (int)UsableWidth / 5,
                startX     = (int)PageWidth / 2 - (bigBoxW + smallBoxW + smallBoxW) / 2,
                startY     = (int)rect.Location.Y + (int)rect.Height + 10,
                rectHeight = 25;

            XPen pen = XPens.Black;

            Rectangle[] rects =
            {
                //msgTextRect
                new Rectangle(new System.Drawing.Point(startX,                       startY), new System.Drawing.Size(bigBoxW,   rectHeight)),
                //amountTextRect
                new Rectangle(new System.Drawing.Point(startX + bigBoxW,             startY), new System.Drawing.Size(smallBoxW, rectHeight)),
                //durationTextRect
                new Rectangle(new System.Drawing.Point(startX + bigBoxW + smallBoxW, startY), new System.Drawing.Size(smallBoxW, rectHeight))
            };

            gfx.DrawRectangles(pen, rects);

            //======================================================================================================================================//
            //Add summary table
            font = new XFont("Calibri", 15.0, XFontStyle.Bold);
            var msgTextRect      = new XRect(rects[0].Location.X + 1, rects[0].Location.Y + 3, rects[0].Width - 2, rects[0].Height - 2);
            var amountTextRect   = new XRect(rects[1].Location.X + 1, rects[1].Location.Y + 3, rects[1].Width - 2, rects[1].Height - 2);
            var durationTextRect = new XRect(rects[2].Location.X + 1, rects[2].Location.Y + 3, rects[2].Width - 2, rects[2].Height - 2);

            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("Alarm text", font, TextBrush, msgTextRect, XStringFormats.TopLeft);
            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("Amount", font, TextBrush, amountTextRect, XStringFormats.TopLeft);
            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("Total duration", font, TextBrush, durationTextRect, XStringFormats.TopLeft);

            font = new XFont("Calibri", 11.0, XFontStyle.Bold);
            XRect loopRect;
            int   y = 1; //Maximum 26 then new page is needed

            for (int i = firstIndex; i < parent.mySummary.Count - 1; i++)
            {
                loopRect = new XRect(startX, startY + (rectHeight * y), bigBoxW, rectHeight);
                gfx.DrawRectangle(pen, loopRect);

                loopRect = new XRect(startX + 2, startY + (rectHeight * y) + 5, rects[0].Width - 2, rects[0].Height - 2);
                CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString(parent.mySummary[i].MsgText, font, TextBrush, loopRect, XStringFormats.TopLeft);

                loopRect = new XRect(startX + bigBoxW, startY + (rectHeight * y), smallBoxW, rectHeight);
                gfx.DrawRectangle(pen, loopRect);

                loopRect = new XRect(startX + bigBoxW + 1, startY + (rectHeight * y) + 5, rects[1].Width - 2, rects[1].Height - 2);
                CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString(parent.mySummary[i].Amount.ToString(), font, TextBrush, loopRect, XStringFormats.TopLeft);

                loopRect = new XRect(startX + bigBoxW + smallBoxW, startY + (rectHeight * y), smallBoxW, rectHeight);
                gfx.DrawRectangle(pen, loopRect);

                loopRect = new XRect(startX + bigBoxW + smallBoxW + 1, startY + (rectHeight * y) + 5, rects[2].Width - 2, rects[2].Height - 2);
                CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString(parent.mySummary[i].StopDuration.ToString(@"hh\:mm\:ss"), font, TextBrush, loopRect, XStringFormats.TopLeft);
                y++;
            }
        }
Exemple #28
0
        public static void setCard(XGraphics gfx, int cardNumber, String color, String imageBoxRound, ModelStudent obj, String themePath)
        {
            // Settings for width and height , font and size
            double labelValueY                   = 110;
            double labelValueX                   = 95;
            double labelValueX2                  = 385;
            string lableFontStatic               = "Comic Sans MS";
            string lableFontDynamic              = "Calibri (Body)";
            double fontStaticSize                = 6;
            double fontDynamicSize               = 9;
            double constantGapPictureAndWords    = 30;
            double constantYAxisIncrementPerCard = 300;


            XImage ximageTheme = XImage.FromFile(themePath);

            // assign new numbers based on card number


            if (ximageTheme.Size.Width < 340)
            {
                System.Windows.Forms.MessageBox.Show("Theme image width  is too small");
                return;
            }
            else if (ximageTheme.Size.Width >= 360)
            {
                System.Windows.Forms.MessageBox.Show("Theme image width is too much");
                return;
            }
            else if (ximageTheme.Size.Height < 220)
            {
                System.Windows.Forms.MessageBox.Show("Theme image Height  is too small");
                return;
            }
            else if (ximageTheme.Size.Height >= 240)
            {
                System.Windows.Forms.MessageBox.Show("Theme image Height is too much");
                return;
            }
            ximageTheme.Interpolate = false;
            if (cardNumber == 1)
            {
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 2)
            {
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }
            else if (cardNumber == 3)
            {
                labelValueY = (1 * constantYAxisIncrementPerCard);
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 4)
            {
                labelValueY = (1 * constantYAxisIncrementPerCard);
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }
            else if (cardNumber == 5)
            {
                labelValueY = (2 * constantYAxisIncrementPerCard) - 110;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 6)
            {
                labelValueY = (2 * constantYAxisIncrementPerCard) - 110;
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }
            else if (cardNumber == 7)
            {
                labelValueY = (3 * constantYAxisIncrementPerCard) - 220;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX - 60, labelValueY - 80));
            }
            else if (cardNumber == 8)
            {
                labelValueY = (3 * constantYAxisIncrementPerCard) - 220;
                labelValueX = labelValueX2;
                gfx.DrawImage(ximageTheme, new XPoint(labelValueX2 - 60, labelValueY - 80));
            }

            // set image frame
            if (imageBoxRound.Equals("boxedblue.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedblue);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("boxedgreen.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedgreen);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("boxedorange.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedorange);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("boxedred.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.boxedred);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("roundblue.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundblue);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("roundgreen.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundgreen);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }
            else if (imageBoxRound.Equals("roundorange.png"))
            {
                XImage ximageBackground;
                ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundorange);
                gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
            }

            /* else if (imageBoxRound.Equals("roundred.png"))
             * {
             *   XImage ximageBackground;
             *   ximageBackground = XImage.FromGdiPlusImage(Properties.Resources.roundred);
             *   gfx.DrawImage(ximageBackground, labelValueX - 50, labelValueY - 9, 75, 75);
             * } */

            XImage ximage;

            if (File.Exists(obj.studentImagePath))
            {
                ximage = XImage.FromFile(obj.studentImagePath);
            }
            else
            {
                ximage = XImage.FromGdiPlusImage(Properties.Resources.android_contact);
            }
            gfx.DrawImage(ximage, labelValueX - 45, labelValueY - 3, 62, 60);

            // name
            XFont fontNameLabel = new XFont(lableFontStatic, fontStaticSize, XFontStyle.BoldItalic);

            if (color.Equals("orange"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.DarkOrange, labelValueX + constantGapPictureAndWords, labelValueY);
            }
            else if (color.Equals("blue"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.Blue, labelValueX + constantGapPictureAndWords, labelValueY);
            }
            else if (color.Equals("red"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.DarkRed, labelValueX + constantGapPictureAndWords, labelValueY);
            }
            else if (color.Equals("green"))
            {
                gfx.DrawString("Name :", fontNameLabel, XBrushes.Green, labelValueX + constantGapPictureAndWords, labelValueY);
            }

            XFont fontNameString = new XFont(lableFontDynamic, fontDynamicSize, XFontStyle.Bold);

            gfx.DrawString(obj.fullName, fontNameString, XBrushes.Black, labelValueX + constantGapPictureAndWords, labelValueY + 8);

            // DOB
            XFont fontDOBLabel = new XFont(lableFontStatic, fontStaticSize, XFontStyle.BoldItalic);

            if (color.Equals("orange"))
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.DarkOrange, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }
            else if (color.Equals("red"))
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.DarkRed, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }
            else if (color.Equals("green"))
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.Green, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }
            else
            {
                gfx.DrawString("Date Of Birth :", fontNameLabel, XBrushes.Blue, labelValueX + constantGapPictureAndWords, labelValueY + 18);
            }



            XFont fontDOBString = new XFont(lableFontDynamic, fontDynamicSize, XFontStyle.Bold);

            gfx.DrawString(obj.DOB, fontDOBString, XBrushes.Black, labelValueX + constantGapPictureAndWords, labelValueY + 28);


            // National Id
            XFont fontNationalIdLabel = new XFont(lableFontStatic, fontStaticSize, XFontStyle.BoldItalic);

            if (color.Equals("orange"))
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.DarkOrange, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }
            else if (color.Equals("red"))
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.DarkRed, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }
            else if (color.Equals("green"))
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.Green, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }
            else
            {
                gfx.DrawString("SRN :", fontNameLabel, XBrushes.Blue, labelValueX + constantGapPictureAndWords, labelValueY + 38);
            }


            XFont fontNationalIdString = new XFont(lableFontDynamic, fontDynamicSize, XFontStyle.Bold);

            gfx.DrawString(obj.nationalId, fontNationalIdString, XBrushes.Black, labelValueX + constantGapPictureAndWords, labelValueY + 48);
        }
Exemple #29
0
        /// <summary>
        /// Initializes a new instance of PdfTrueTypeFont from an XFont.
        /// </summary>
        public PdfTrueTypeFont(PdfDocument document, XFont font)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/TrueType");

            // TrueType with WinAnsiEncoding only
            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(font);

            fontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            fontOptions    = font.PdfOptions;
            Debug.Assert(fontOptions != null);

            //this.cmapInfo = new CMapInfo(null/*ttDescriptor*/);
            cmapInfo = new CMapInfo(ttDescriptor);

            BaseFont = font.Name.Replace(" ", "");
            switch (font.Style & (XFontStyle.Bold | XFontStyle.Italic))
            {
            case XFontStyle.Bold:
                BaseFont += ",Bold";
                break;

            case XFontStyle.Italic:
                BaseFont += ",Italic";
                break;

            case XFontStyle.Bold | XFontStyle.Italic:
                BaseFont += ",BoldItalic";
                break;
            }
            if (fontOptions.FontEmbedding == PdfFontEmbedding.Always)
            {
                BaseFont = CreateEmbeddedFontSubsetName(BaseFont);
            }
            fontDescriptor.FontName = BaseFont;

            Debug.Assert(fontOptions.FontEncoding == PdfFontEncoding.WinAnsi);
            if (!IsSymbolFont)
            {
                Encoding = "/WinAnsiEncoding";
            }

            //        {
            //#if true
            //          throw new NotImplementedException("Specifying a font file is not yet supported.");
            //#else
            //          // Testcode
            //          FileStream stream = new FileStream("WAL____I.AFM", FileAccess.Read);
            //          int length = stream.Length;
            //          byte[] fontProgram = new byte[length];
            //          PdfDictionary fontStream = new PdfDictionary(this.Document);
            //          this.Document.xrefTable.Add(fontStream);
            //          this.fontDescriptor.Elements[PdfFontDescriptor.Keys.FontFile] = fontStream.XRef;

            //          fontStream.Elements["/Length1"] = new PdfInteger(fontProgram.Length);
            //          if (!this.Document.Options.NoCompression)
            //          {
            //            fontProgram = Filtering.FlateDecode.Encode(fontProgram);
            //            fontStream.Elements["/Filter"] = new PdfName("/FlateDecode");
            //          }
            //          fontStream.Elements["/Length"] = new PdfInteger(fontProgram.Length);
            //          fontStream.CreateStream(fontProgram);
            //#endif
            //        }

            Owner.irefTable.Add(fontDescriptor);
            Elements[Keys.FontDescriptor] = fontDescriptor.Reference;

            FontEncoding  = font.PdfOptions.FontEncoding;
            FontEmbedding = font.PdfOptions.FontEmbedding;
        }
Exemple #30
0
        private static void createTableRow(XGraphics gfx, Teacher teacher)
        {
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XBrush          brush   = XBrushes.Black;
            XStringFormat   format  = new XStringFormat();

            format.LineAlignment = XLineAlignment.Center;

            XPen   xpen   = new XPen(XColors.Black, 0.5);
            XBrush xbrush = XBrushes.Bisque;

            XRect rect;
            XFont font;

            int currX = X_START - 30;

            string ordinalNum = ROW_COUNTER.ToString() + ".";

            rect             = new XRect(currX, CURR_Y, 28, ROW_HEIGHT);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Far;
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(ordinalNum, font, brush, rect, format);

            currX = X_START;

            string teacherLastName = teacher.getLastName();

            rect             = new XRect(currX, CURR_Y, COL_WIDTH[0], ROW_HEIGHT);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Near;
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherLastName, font, brush, rect, format);

            currX += COL_WIDTH[0] + COL_GAP;

            string teacherName = teacher.getName();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[1], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherName, font, brush, rect, format);

            currX += COL_WIDTH[1] + COL_GAP;

            string teacherTitle = teacher.getTitle();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[2], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherTitle, font, brush, rect, format);

            currX += COL_WIDTH[2] + COL_GAP;

            string teacherEduRank = teacher.getEduRank();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[3], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherEduRank, font, brush, rect, format);

            currX += COL_WIDTH[3] + COL_GAP;

            string teacherExtID = teacher.ExtID;

            rect = new XRect(currX, CURR_Y, COL_WIDTH[4], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherExtID, font, brush, rect, format);

            gfx.DrawLine(xpen, X_START - 20, CURR_Y + ROW_HEIGHT + 2, X_START + 475, CURR_Y + ROW_HEIGHT + 2);

            CURR_Y += ROW_HEIGHT + 4;
        }
Exemple #31
0
        protected void btnExportPdf_Click(object sender, EventArgs e)
        {
            // Populate report
            PopulateGrid();

            var documentDirectory = String.Format("{0}\\Temp\\", System.AppDomain.CurrentDomain.BaseDirectory);
            var logoDirectory     = String.Format("{0}\\img\\", System.AppDomain.CurrentDomain.BaseDirectory);

            string destName = string.Format("RCNS_{0}.pdf", DateTime.Now.ToString("yyyyMMddhhmmsss"));
            string destFile = string.Format("{0}{1}", documentDirectory, destName);

            string logoName = string.Format("SIAPS_USAID_Horiz.png");
            string logoFile = string.Format("{0}{1}", logoDirectory, logoName);

            string fontFile = string.Format("{0}\\arial.ttf", System.AppDomain.CurrentDomain.BaseDirectory);

            var linePosition   = 60;
            var columnPosition = 30;

            // Create document
            PdfDocument  pdfDoc = new PdfDocument();
            XmlNode      rootNode;
            XmlNode      filterNode;
            XmlNode      contentHeadNode;
            XmlNode      contentNode;
            XmlNode      contentValueNode;
            XmlAttribute attrib;
            XmlComment   comment;

            // Create a new page
            PdfPage page = pdfDoc.AddPage();

            page.Orientation = PageOrientation.Landscape;

            // Get an XGraphics object for drawing
            XGraphics      gfx = XGraphics.FromPdfPage(page);
            XTextFormatter tf  = new XTextFormatter(gfx);
            XPen           pen = new XPen(XColor.FromArgb(255, 0, 0));

            // Logo
            XImage image = XImage.FromFile(logoFile);

            gfx.DrawImage(image, 10, 10);

            // Create a new font
            Uri fontUri = new Uri(fontFile);

            try
            {
                XPrivateFontCollection.Global.Add(fontUri, "#Arial");
            }
            catch
            {
            }

            XFont fontb = new XFont("Calibri", 10, XFontStyle.Bold | XFontStyle.Underline);
            XFont fontr = new XFont("Calibri", 10, XFontStyle.Regular);

            // Write header
            pdfDoc.Info.Title = "Causality Report for " + DateTime.Now.ToString("yyyy-MM-dd hh:MM");
            gfx.DrawString("Causality Report for " + DateTime.Now.ToString("yyyy-MM-dd hh:MM"), fontb, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);

            // Write filter
            linePosition += 24;
            gfx.DrawString("Range From : " + txtSearchFrom.Value, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);
            linePosition += 24;
            gfx.DrawString("Range To : " + txtSearchTo.Value, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);

            // Write content
            var pageCount = 1;
            var rowCount  = 0;
            var cellCount = 0;

            ArrayList headerArray = new ArrayList();
            ArrayList widthArray  = new ArrayList();

            foreach (TableRow row in dt_basic.Rows)
            {
                rowCount += 1;
                cellCount = 0;

                linePosition  += 24;
                columnPosition = 30;

                if (linePosition >= 480)
                {
                    pageCount += 1;

                    page             = pdfDoc.AddPage();
                    page.Orientation = PageOrientation.Landscape;

                    linePosition = 60;

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

                    // Logo
                    gfx.DrawImage(image, 10, 10);

                    gfx.DrawString("Causality Report (Page " + pageCount.ToString() + ")", fontb, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft);

                    linePosition += 24;

                    /// rewrite column headers
                    foreach (var header in headerArray)
                    {
                        cellCount += 1;
                        var width = Convert.ToInt32(widthArray[cellCount - 1]);

                        gfx.DrawString(header.ToString(), fontb, XBrushes.Black, new XRect(columnPosition, linePosition, width, 20), XStringFormats.TopLeft);
                        columnPosition += width;
                    }

                    columnPosition = 30;
                    linePosition  += 24;
                    cellCount      = 0;
                }

                foreach (TableCell cell in row.Cells)
                {
                    int[] ignore = { };

                    if (!ignore.Contains(cellCount))
                    {
                        cellCount += 1;

                        if (rowCount == 1)
                        {
                            widthArray.Add((int)cell.Width.Value * 8);
                            headerArray.Add(cell.Text);

                            gfx.DrawString(cell.Text, fontb, XBrushes.Black, new XRect(columnPosition, linePosition, cell.Width.Value * 8, 20), XStringFormats.TopLeft);
                            columnPosition += (int)cell.Width.Value * 8;
                        }
                        else
                        {
                            var width = Convert.ToInt32(widthArray[cellCount - 1]);

                            tf.DrawString(cell.Text, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, width, 20), XStringFormats.TopLeft);
                            columnPosition += width;
                        }
                    }
                }
            }

            pdfDoc.Save(destFile);

            Response.Clear();
            Response.Buffer          = true;
            Response.ContentEncoding = Encoding.UTF8;
            Response.ContentType     = "application/pdf";
            Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", destName));
            Response.Charset     = "";
            this.EnableViewState = false;

            Response.WriteFile(destFile);
            Response.End();
        }
Exemple #32
0
        /// <summary>
        /// Renders a single paragraph.
        /// </summary>
        void GenerateReport(PdfDocument document)
        {
            //PdfPage page = document.AddPage();
            PdfPage page = document.Pages[0];

            XGraphics gfx = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH  = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Default;

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



            // map image origin
            //gfx.DrawString("O", font, XBrushes.Red, new XRect(5, 5, 108, 161), XStringFormats.Center);


            // ovmap image origin
            //gfx.DrawString("X", font, XBrushes.Red, new XRect(5, 5, 798, 1144), XStringFormats.Center);



            //gfx.DrawString("+", font, XBrushes.Red, new XRect(5, 5, 100, 1299), XStringFormats.Center);



            //XImage ximg = XImage.FromFile(mapImagePth);
            XImage ximg = XImage.FromGdiPlusImage(mimg);

            //ximg.Interpolate = true;
            Point ipt = new Point(58, 86);

            //gfx.SmoothingMode = XSmoothingMode.HighQuality;
            gfx.DrawImage(ximg, ipt);



            //gfx.DrawImage(ximg, ipt.X, ipt.Y, ApplyTransform(ximg.PointWidth), ApplyTransform(ximg.PointHeight));


            /*
             * XImage ximg_ov = XImage.FromFile(ovmapImagePth);
             * Point ov_ipt = new Point(398, 580);
             * gfx.DrawImage(ximg_ov, ov_ipt);
             */

            //String ovmapImageTPth = @"C:\inetpub\wwwroot\ms6\output\ov\ov13_mxd_a.png";

            /*
             * XImage ximg_ov = XImage.FromFile(ovmapImagePth);
             *
             * Point ov_ipt = new Point(408, 570);
             * //gfx.DrawImage(ximg_ov, ov_ipt);
             * gfx.DrawImage(ximg_ov, ov_ipt.X, ov_ipt.Y,97,130);
             */
            /*
             * double rminx = 1218342.661;
             * double rminy = 500202.9879;
             * double rmaxx = 1397365.953;
             * double rmaxy = 738900.7105;
             * double rxw = 179023.292;
             * double rxh = 238697.7226;
             * double img_width = 97.0;
             * double img_height = 130.0;
             */
            double rminx      = 1232659.28962;
            double rminy      = 498047.976697;
            double rmaxx      = 1390211.37295;
            double rmaxy      = 739801.448919;
            double rxw        = 157552.0833;
            double rxh        = 241753.4722;
            double img_width  = 87;
            double img_height = 133;
            double qx         = minx + ((maxx - minx) / 2.0);
            double qy         = miny + ((maxy - miny) / 2.0);

            double pct_x = (qx - rminx) / rxw;
            double pct_y = (qy - rminy) / rxh;

            double px_x = pct_x * img_width;
            double px_y = (1.0 - pct_y) * img_height;

            double ul_px = ((minx - rminx) / rxw) * img_width;
            double ul_py = (1.0 - ((maxy - rminy) / rxh)) * img_height;

            double qwidth_pct = (maxx - minx) / (rmaxx - rminx);
            double qhght_pct  = (maxy - miny) / (rmaxy - rminy);

            double px_width = qwidth_pct * img_width;
            double px_hgt   = qhght_pct * img_height;


            //Debug.Print(String.Format("qx/qy: {0}  {1}    pct_x/pct_y: {2}  {3}   px_x/px_y:  {4}  {5} ", qx, qy, pct_x, pct_y, px_x, px_y));



            // option #1 - using graphics object directly on image
            Image ovImg = Image.FromFile(ovmapImageTPth);

            using (Graphics g = Graphics.FromImage(ovImg))
            {
                Pen myPen = new Pen(System.Drawing.Color.Red, 5);
                System.Drawing.Font myFont = new System.Drawing.Font("Helvetica", 15, FontStyle.Bold);
                Brush myBrush = new SolidBrush(System.Drawing.Color.Red);
                g.DrawString("x", myFont, myBrush, new PointF((float)px_x, (float)px_y));
                g.DrawRectangle(myPen, (float)ul_px, (float)ul_py, (float)px_width, (float)px_hgt);
            }

            ovImg.Save(ovmapImagePth);
            XImage ximg_ov = XImage.FromFile(ovmapImagePth);



            XImage ximgn = XImage.FromFile(northimgpth);

            //ximg.Interpolate = true;
            Point iptn = new Point(520, 570);

            //gfx.SmoothingMode = XSmoothingMode.HighQuality;
            gfx.DrawImage(ximgn, iptn);



            Point ov_ipt = new Point(400, 570);
            //gfx.DrawImage(ximg_ov, ov_ipt);

            //gfx.DrawImage(ximg_ov, ov_ipt.X, ov_ipt.Y, 97, 130);

            RectangleF srcR  = new RectangleF(0, 0, (int)img_width, (int)img_height);
            RectangleF destR = new RectangleF(ov_ipt.X, ov_ipt.Y, (int)img_width, (int)img_height);

            gfx.DrawImage(ximg_ov, destR, srcR, XGraphicsUnit.Point);

            // option #2 - using pdf object directly on report



            // XPen peno = new XPen(XColors.Aqua, 0.5);

            //gfx.DrawRectangle(peno, 408, 570,  95,  128);

            //peno = new XPen(XColors.DodgerBlue, 0.5);

            //gfx.DrawRectangle(peno, 354, 570, 200, 128);



            XPen pen = new XPen(XColors.Black, 0.5);

            gfx.DrawRectangle(pen, 29, 59, 555, 643);


            XPen pen2 = new XPen(XColors.Black, 0.8);

            gfx.DrawRectangle(pen, 29, 566, 555, 136);


            XPen   pen3  = new XPen(XColors.HotPink, 0.5);
            XBrush brush = XBrushes.LightPink;

            gfx.DrawRectangle(pen, brush, 29, 705, 555, 43);



            Document doc = new Document();



            // You always need a MigraDoc document for rendering.

            Section sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            Paragraph para = sec.AddParagraph();

            para.Format.Alignment  = ParagraphAlignment.Justify;
            para.Format.Font.Name  = "Verdana";
            para.Format.Font.Size  = Unit.FromPoint(6);
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            //para.AddText("Duisism odigna acipsum delesenisl ");
            //para.AddFormattedText("ullum in velenit", TextFormat.Bold);

            para.AddText("Okaloosa County makes every effort to produce the most accurate information possible. No warranties, expressed or implied, are provided for the data herein, its use or interpretation. The assessment information is from the last certified taxroll. All data is subject to change before the next certified taxroll. PLEASE NOTE THAT THE GIS MAPS ARE FOR ASSESSMENT PURPOSES ONLY NEITHER OKALOOSA COUNTY NOR ITS EMPLOYEES ASSUME RESPONSIBILITY FOR ERRORS OR OMISSIONS ---THIS IS NOT A SURVEY---");


            //para.Format.Borders.Distance = "1pt";
            //para.Format.Borders.Color = Colors.Orange;

            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.  29, 705, 555, 43
            docRenderer.RenderObject(gfx, XUnit.FromPoint(38), XUnit.FromPoint(710), XUnit.FromPoint(535), para);



            Section section = doc.AddSection();



            MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable();
            table.Style         = "Table";
            table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            table.Borders.Width = 0.25;

            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;
            table.Format.Font.Name    = "Verdana";
            table.Format.Font.Size    = Unit.FromPoint(6);
            table.Rows.Height         = Unit.FromInch(0.203);

            /*
             * // Before you can add a row, you must define the columns
             * Column column = table.AddColumn("1cm");
             * column.Format.Alignment = ParagraphAlignment.Center;
             *
             * column = table.AddColumn("2.5cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * column = table.AddColumn("3cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * column = table.AddColumn("3.5cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * column = table.AddColumn("2cm");
             * column.Format.Alignment = ParagraphAlignment.Center;
             *
             * column = table.AddColumn("4cm");
             * column.Format.Alignment = ParagraphAlignment.Right;
             *
             * // Create the header of the table
             * Row row = table.AddRow();
             * row.HeadingFormat = true;
             * row.Format.Alignment = ParagraphAlignment.Center;
             * row.Format.Font.Bold = true;
             * row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.Blue;
             * row.Cells[0].AddParagraph("Item");
             * row.Cells[0].Format.Font.Bold = false;
             * row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom;
             * row.Cells[0].MergeDown = 1;
             * row.Cells[1].AddParagraph("Title and Author");
             * row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[1].MergeRight = 3;
             * row.Cells[5].AddParagraph("Extended Price");
             * row.Cells[5].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[5].VerticalAlignment = VerticalAlignment.Bottom;
             * row.Cells[5].MergeDown = 1;
             *
             *
             * row = table.AddRow();
             * row.HeadingFormat = true;
             * row.Format.Alignment = ParagraphAlignment.Center;
             * row.Format.Font.Bold = true;
             * row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.BlueViolet;
             * row.Cells[1].AddParagraph("Quantity");
             * row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[2].AddParagraph("Unit Price");
             * row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[3].AddParagraph("Discount (%)");
             * row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[4].AddParagraph("Taxable");
             * row.Cells[4].Format.Alignment = ParagraphAlignment.Left;
             */


            Column column = table.AddColumn(Unit.FromInch(0.31));

            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromInch(2.0));
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn(Unit.FromInch(0.8));
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn(Unit.FromInch(1.0));
            column.Format.Alignment = ParagraphAlignment.Right;

            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Okaloosa County Property Appraiser  -  2013 Certified Values");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table.AddRow();
            row.Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[0].AddParagraph("Parcel: " + obCama.pinstr);
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;


            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Name");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.owner);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Land Value:");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.landval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Site");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.site_addr);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Building Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.bldval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Sale");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.sale_info);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Misc Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.miscval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("\nMail\n");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[0].MergeDown = 3;

            //row.Cells[1].AddParagraph(obCama.mail_addr);
            row.Cells[1].AddParagraph(obCama.mail_addr_1);
            row.Cells[1].AddParagraph(obCama.mail_addr_2);

            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].MergeDown        = 3;

            row.Cells[2].AddParagraph("Just Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.justval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            row = table.AddRow();

            row.Cells[2].AddParagraph("Assessed Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.assdval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();

            row.Cells[2].AddParagraph("Exempt Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.exempt_val));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();

            row.Cells[2].AddParagraph("Taxable Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.taxblval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            // Create a renderer and prepare (=layout) the document
            //MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromInch(0.4025), XUnit.FromInch(7.88), XUnit.FromInch(3.85), table);

            //table.SetEdge(0, 0, 2, 2, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Colors.Yellow);

            // table.SetEdge(0, 0, 6, 2, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Colors.Yellow);


            XFont    font2       = new XFont("Verdana", 5, XFontStyle.Regular);
            DateTime tdate       = DateTime.Now;
            String   datestr     = tdate.ToString("MMM dd,yyy");
            String   metadataMSG = String.Format("map created {0}", datestr);

            gfx.DrawString(metadataMSG, font2, XBrushes.Black, new XRect(480, 769, 100, 20), XStringFormats.Center);

            /*
             * double xp = 0;
             * double yp = 0;
             * int numticks = 10;
             *
             * double w_inc = page.Width.Value / (double)numticks;
             * double h_inc = page.Height.Value / (double)numticks;
             *
             * for (int x = 0; x < numticks; x++)
             * {
             * for (int y = 0; y < numticks; y++)
             * {
             *
             *     xp = (double)x * w_inc;
             *     yp = (double)y * h_inc;
             *
             *     XUnit xu_x = new XUnit(xp, XGraphicsUnit.Point);
             *     XUnit xu_y = new XUnit(yp, XGraphicsUnit.Point);
             *
             *     xu_x.ConvertType(XGraphicsUnit.Inch);
             *     xu_y.ConvertType(XGraphicsUnit.Inch);
             *
             *     gfx.DrawString("+", font, XBrushes.Red, new XRect( xp,  yp, 5, 5), XStringFormats.Center);
             *     String lbl = String.Format("{0},{1}-{2},{3}", (int)xp, (int)yp, xu_x.Value, xu_y.Value);
             *     gfx.DrawString(lbl, font, XBrushes.Red, new XRect( xp + 5,  yp + 5, 5, 5), XStringFormats.Center);
             *
             *
             * }
             *
             * }
             */
        }
Exemple #33
0
        double _realizedCharSpace;  // Reference: TABLE 5.2  Text state operators / Page 398

        public void RealizeFont(XFont font, XBrush brush, int renderingMode)
        {
            const string format = Config.SignificantFigures3;

            // So far rendering mode 0 (fill text) and 2 (fill, then stroke text) only.
            RealizeBrush(brush, _renderer._colorMode, renderingMode, font.Size); // _renderer.page.document.Options.ColorMode);

            // Realize rendering mode.
            if (_realizedRenderingMode != renderingMode)
            {
                _renderer.AppendFormatInt("{0} Tr\n", renderingMode);
                _realizedRenderingMode = renderingMode;
            }

            // Realize character spacing.
            if (_realizedRenderingMode == 0)
            {
                if (_realizedCharSpace != 0)
                {
                    _renderer.Append("0 Tc\n");
                    _realizedCharSpace = 0;
                }
            }
            else  // _realizedRenderingMode is 2.
            {
                double charSpace = font.Size * Const.BoldEmphasis;
                if (_realizedCharSpace != charSpace)
                {
                    _renderer.AppendFormatDouble("{0:" + format + "} Tc\n", charSpace);
                    _realizedCharSpace = charSpace;
                }
            }

            _realizedFont = null;
            string fontName = _renderer.GetFontName(font, out _realizedFont);
            if (fontName != _realizedFontName || _realizedFontSize != font.Size)
            {
                if (_renderer.Gfx.PageDirection == XPageDirection.Downwards)
                    _renderer.AppendFormatFont("{0} {1:" + format + "} Tf\n", fontName, font.Size);
                else
                    _renderer.AppendFormatFont("{0} {1:" + format + "} Tf\n", fontName, font.Size);
                _realizedFontName = fontName;
                _realizedFontSize = font.Size;
            }
        }
        public static void createPdfDocument(ArrayList pdfReportDataTablesList)
        {
            int tableStartX           = Settings.TTREP_MTS_X;
            int tableStartY           = Settings.TTREP_MTS_Y;
            int rowHeight             = Settings.TTREP_MTRH;
            int columnWidth           = Settings.TTREP_MTCW;
            int headerTableRowHeight  = Settings.TTREP_HTRH;
            int termsTableColumnWidth = Settings.TTREP_TPTCW;

            string fileName = "ReportTimetable" + ".pdf";

            PDFDOCUMENT              = new PdfDocument();
            PDFDOCUMENT.Info.Title   = "OCTT Timetable Report";
            PDFDOCUMENT.Info.Author  = "Open Course Timetabler";
            PDFDOCUMENT.Info.Subject = "Свободное расписание";

            foreach (Object[] reportGroupAndTable in pdfReportDataTablesList)
            {
                PdfPage newPage = PDFDOCUMENT.AddPage();
                //newPage.Size = PageSize.A4;

                Type ps = typeof(PageSize);
                newPage.Size = (PageSize)getValueForEnumeration(ps, Settings.TTREP_PAPER_SIZE);
                //Console.WriteLine(newPage.Width + "," + newPage.Height);

                //newPage.Orientation = PdfSharp.PageOrientation.Landscape;
                Type po = typeof(PageOrientation);
                newPage.Orientation = (PageOrientation)getValueForEnumeration(po, Settings.TTREP_PAPER_ORIENTATION);

                XGraphics gfx = XGraphics.FromPdfPage(newPage);
                XPen      pen = new XPen(XColors.Black, 0.3);


                int rowCount    = AppForm.CURR_OCTT_DOC.IncludedTerms.Count;
                int columnCount = AppForm.CURR_OCTT_DOC.getNumberOfDays();

                string groupTitle = (string)reportGroupAndTable[0];

                XRect           rect    = new XRect(tableStartX + termsTableColumnWidth, tableStartY - 25, columnCount * columnWidth, 20);
                XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

                //

                /*char[] separator = new char[1];
                 * separator[0] = ',';
                 * string[] ss = Settings.TTREP_FONT_PAGE_TITLE.Split(separator, 3);
                 * string fontFamily = ss[0];
                 * string fontStyle = ss[1];
                 * int fontSize = System.Convert.ToInt32(ss[2]);
                 * //
                 * Type fs = typeof(XFontStyle);
                 * XFontStyle xfs=(XFontStyle)getValueForEnumeration(fs, fontStyle);
                 *
                 * XFont font = new XFont(fontFamily, fontSize, xfs, options);*/
                //XFont font = new XFont("Times", 16, XFontStyle.Bold, options);

                XFont font = getMyFont(Settings.TTREP_FONT_PAGE_TITLE, options);

                XBrush        brush  = XBrushes.Black;
                XStringFormat format = new XStringFormat();
                //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
                format.LineAlignment = XLineAlignment.Center;
                format.Alignment     = XStringAlignment.Center;
                gfx.DrawString(groupTitle, font, brush, rect, format);

                DataTable groupTable = (DataTable)reportGroupAndTable[1];

                drawHeaderTable(newPage, gfx, pen, tableStartX + termsTableColumnWidth, tableStartY, columnWidth, headerTableRowHeight);

                drawTermsTable(newPage, gfx, pen, tableStartX, tableStartY + headerTableRowHeight, termsTableColumnWidth, rowHeight);

                drawMainTable(newPage, gfx, pen, tableStartX + termsTableColumnWidth, tableStartY + headerTableRowHeight, columnWidth, rowHeight, groupTable);



                string docPropertiesString = AppForm.CURR_OCTT_DOC.EduInstitutionName + " " + AppForm.CURR_OCTT_DOC.SchoolYear;

                string lastChangeString;
                if (AppForm.CURR_OCTT_DOC.FullPath != null)
                {
                    FileInfo fi = new FileInfo(AppForm.CURR_OCTT_DOC.FullPath);
                    lastChangeString = RES_MANAGER.GetString("lastchangedate.text") + " " + fi.LastWriteTime.ToShortDateString() + " " + fi.LastWriteTime.ToLongTimeString();
                }
                else
                {
                    lastChangeString = "";
                }

                rect = new XRect(tableStartX, tableStartY + headerTableRowHeight + rowHeight * rowCount + 5, 250, 10);
                //font = new XFont("Times", 8, XFontStyle.Regular, options);
                font = getMyFont(Settings.TTREP_FONT_FOOTER, options);
                //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
                format.LineAlignment = XLineAlignment.Center;
                format.Alignment     = XStringAlignment.Near;
                gfx.DrawString(docPropertiesString, font, brush, rect, format);

                rect = new XRect(tableStartX + termsTableColumnWidth + columnWidth * columnCount - 200, tableStartY + headerTableRowHeight + rowHeight * rowCount + 5, 200, 10);
                //font = new XFont("Times", 8, XFontStyle.Regular, options);
                //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
                format.LineAlignment = XLineAlignment.Center;
                format.Alignment     = XStringAlignment.Far;
                gfx.DrawString(lastChangeString, font, brush, rect, format);

                rect = new XRect(tableStartX, tableStartY + headerTableRowHeight + rowHeight * rowCount + 5, tableStartX + termsTableColumnWidth + columnWidth * columnCount, 10);
                //font = new XFont("Times", 8, XFontStyle.Regular, options);
                //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
                format.LineAlignment = XLineAlignment.Center;
                format.Alignment     = XStringAlignment.Center;
                gfx.DrawString("Свободное расписание (КонтинентСвободы.рф)", font, brush, rect, format);
            }



            try
            {
                PDFDOCUMENT.Save(fileName);
                Process.Start(Settings.PDF_READER_APPLICATION, fileName);
            }
            catch (Exception e)
            {
                try
                {
                    Process.Start(fileName);
                }
                catch (Exception e2)
                {
                    MessageBox.Show(e2.Message);
                }
            }
        }
Exemple #35
0
 /// <summary>
 /// When defined in a derived class renders the code.
 /// </summary>
 protected internal abstract void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position);
Exemple #36
0
 public void DrawString(string s, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format)
 {
 }
 /// <summary>
 /// Makes the specified font and brush to the current graphics objects.
 /// </summary>
 void Realize(XFont font, XBrush brush, int renderingMode)
 {
     BeginPage();
     RealizeTransform();
     BeginTextMode();
     _gfxState.RealizeFont(font, brush, renderingMode);
 }
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            string facename = "Times";
            float  size     = 24;
            XFont  fontR    = new XFont(facename, size, this.properties.Font1.Style);

            fontR = this.properties.Font1.Font;
            //XFont fontB = new XFont(facename, size, XFontStyle.Bold);
            //XFont fontI = new XFont(facename, size, XFontStyle.Italic);
            //XFont fontBI = new XFont(facename, size, XFontStyle.Bold | XFontStyle.Italic);
            //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200);
            float      x0   = 80;
            float      x1   = 520;
            float      y0   = 80;
            float      y1   = 760 / 2;
            RectangleF rect = new RectangleF(x0, y0, x1 - x0, y1 - y0);
            XPen       pen  = XPens.SlateBlue;

            gfx.DrawRectangle(pen, rect);
            gfx.DrawLine(pen, (x0 + x1) / 2, y0, (x0 + x1) / 2, y1);
            gfx.DrawLine(pen, x0, (y0 + y1) / 2, x1, (y0 + y1) / 2);

            XSolidBrush   brush  = this.properties.Font1.Brush;
            XStringFormat format = new XStringFormat();

            double lineSpace   = fontR.GetHeight(gfx);
            int    cellSpace   = fontR.FontFamily.GetLineSpacing(fontR.Style);
            int    cellAscent  = fontR.FontFamily.GetCellAscent(fontR.Style);
            int    cellDescent = fontR.FontFamily.GetCellDescent(fontR.Style);
            double cyAscent    = lineSpace * cellAscent / cellSpace;

            gfx.DrawString("TopLeft", fontR, brush, rect, format);

            format.Alignment = XStringAlignment.Center;
            gfx.DrawString("TopCenter", fontR, brush, rect, format);

            format.Alignment = XStringAlignment.Far;
            gfx.DrawString("TopRight", fontR, brush, rect, format);

            format.LineAlignment = XLineAlignment.Center;
            format.Alignment     = XStringAlignment.Near;
            gfx.DrawString("CenterLeft", fontR, brush, rect, format);

            format.Alignment = XStringAlignment.Center;
            gfx.DrawString("Center", fontR, brush, rect, format);

            format.Alignment = XStringAlignment.Far;
            gfx.DrawString("CenterRight", fontR, brush, rect, format);


            format.LineAlignment = XLineAlignment.Far;
            format.Alignment     = XStringAlignment.Near;
            gfx.DrawString("BottomLeft", fontR, brush, rect, format);

            format.Alignment = XStringAlignment.Center;
            gfx.DrawString("BottomCenter", fontR, brush, rect, format);

            format.Alignment = XStringAlignment.Far;
            gfx.DrawString("BottomRight", fontR, brush, rect, format);


//      format.LineAlignment= XLineAlignment.Center;
//      format.Alignment = XStringAlignment.Center;
//      gfx.DrawString("CenterLeft", fontR, brush, rect, format);

//      gfx.DrawString("Times 40", fontR, this.properties.Font1.Brush, x, 200);
//      gfx.DrawString("Times bold 40", fontB, this.properties.Font1.Brush, x, 300);
//      gfx.DrawString("Times italic 40", fontI, this.properties.Font1.Brush, x, 400);
//      gfx.DrawString("Times bold italic 40", fontBI, this.properties.Font1.Brush, x, 500);
        }
        // ----- DrawString ---------------------------------------------------------------------------

        public void DrawString(string s, XFont font, XBrush brush, XRect rect, XStringFormat format)
        {
            double x = rect.X;
            double y = rect.Y;

            double lineSpace = font.GetHeight();
            double cyAscent = lineSpace * font.CellAscent / font.CellSpace;
            double cyDescent = lineSpace * font.CellDescent / font.CellSpace;
            double width = _gfx.MeasureString(s, font).Width;

            //bool bold = (font.Style & XFontStyle.Bold) != 0;
            //bool italic = (font.Style & XFontStyle.Italic) != 0;
            bool italicSimulation = (font.GlyphTypeface.StyleSimulations & XStyleSimulations.ItalicSimulation) != 0;
            bool boldSimulation = (font.GlyphTypeface.StyleSimulations & XStyleSimulations.BoldSimulation) != 0;
            bool strikeout = (font.Style & XFontStyle.Strikeout) != 0;
            bool underline = (font.Style & XFontStyle.Underline) != 0;

            Realize(font, brush, boldSimulation ? 2 : 0);

            switch (format.Alignment)
            {
                case XStringAlignment.Near:
                    // nothing to do
                    break;

                case XStringAlignment.Center:
                    x += (rect.Width - width) / 2;
                    break;

                case XStringAlignment.Far:
                    x += rect.Width - width;
                    break;
            }
            if (Gfx.PageDirection == XPageDirection.Downwards)
            {
                switch (format.LineAlignment)
                {
                    case XLineAlignment.Near:
                        y += cyAscent;
                        break;

                    case XLineAlignment.Center:
                        // TODO: Use CapHeight. PDFlib also uses 3/4 of ascent
                        y += (cyAscent * 3 / 4) / 2 + rect.Height / 2;
                        break;

                    case XLineAlignment.Far:
                        y += -cyDescent + rect.Height;
                        break;

                    case XLineAlignment.BaseLine:
                        // Nothing to do.
                        break;
                }
            }
            else
            {
                switch (format.LineAlignment)
                {
                    case XLineAlignment.Near:
                        y += cyDescent;
                        break;

                    case XLineAlignment.Center:
                        // TODO: Use CapHeight. PDFlib also uses 3/4 of ascent
                        y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2;
                        break;

                    case XLineAlignment.Far:
                        y += -cyAscent + rect.Height;
                        break;

                    case XLineAlignment.BaseLine:
                        // Nothing to do.
                        break;
                }
            }

            PdfFont realizedFont = _gfxState._realizedFont;
            Debug.Assert(realizedFont != null);
            realizedFont.AddChars(s);

            const string format2 = Config.SignificantFigures4;
            OpenTypeDescriptor descriptor = realizedFont.FontDescriptor._descriptor;

            string text = null;
            if (font.Unicode)
            {
                StringBuilder sb = new StringBuilder();
                bool isSymbolFont = descriptor.FontFace.cmap.symbol;
                for (int idx = 0; idx < s.Length; idx++)
                {
                    char ch = s[idx];
                    if (isSymbolFont)
                    {
                        // Remap ch for symbol fonts.
                        ch = (char)(ch | (descriptor.FontFace.os2.usFirstCharIndex & 0xFF00));  // @@@ refactor
                    }
                    int glyphID = descriptor.CharCodeToGlyphIndex(ch);
                    sb.Append((char)glyphID);
                }
                s = sb.ToString();

                byte[] bytes = PdfEncoders.RawUnicodeEncoding.GetBytes(s);
                bytes = PdfEncoders.FormatStringLiteral(bytes, true, false, true, null);
                text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length);
            }
            else
            {
                byte[] bytes = PdfEncoders.WinAnsiEncoding.GetBytes(s);
                text = PdfEncoders.ToStringLiteral(bytes, false, null);
            }

            // Map absolute position to PDF world space.
            XPoint pos = new XPoint(x, y);
            pos = WorldToView(pos);

            double verticalOffset = 0;
            if (boldSimulation)
            {
                // Adjust baseline in case of bold simulation???
                // No, because this would change the center of the glyphs.
                //verticalOffset = font.Size * Const.BoldEmphasis / 2;
            }

#if ITALIC_SIMULATION
            if (italicSimulation)
            {
                if (_gfxState.ItalicSimulationOn)
                {
                    AdjustTdOffset(ref pos, verticalOffset, true);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} Td\n{2} Tj\n", pos.X, pos.Y, text);
                }
                else
                {
                    // Italic simulation is done by skewing characters 20° to the right.
                    XMatrix m = new XMatrix(1, 0, Const.ItalicSkewAngleSinus, 1, pos.X, pos.Y);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} {2:" + format2 + "} {3:" + format2 + "} {4:" + format2 + "} {5:" + format2 + "} Tm\n{6} Tj\n",
                        m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY, text);
                    _gfxState.ItalicSimulationOn = true;
                    AdjustTdOffset(ref pos, verticalOffset, false);
                }
            }
            else
            {
                if (_gfxState.ItalicSimulationOn)
                {
                    XMatrix m = new XMatrix(1, 0, 0, 1, pos.X, pos.Y);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} {2:" + format2 + "} {3:" + format2 + "} {4:" + format2 + "} {5:" + format2 + "} Tm\n{6} Tj\n",
                        m.M11, m.M12, m.M21, m.M22, m.OffsetX, m.OffsetY, text);
                    _gfxState.ItalicSimulationOn = false;
                    AdjustTdOffset(ref pos, verticalOffset, false);
                }
                else
                {
                    AdjustTdOffset(ref pos, verticalOffset, false);
                    AppendFormatArgs("{0:" + format2 + "} {1:" + format2 + "} Td {2} Tj\n", pos.X, pos.Y, text);
                }
            }
#else
                AdjustTextMatrix(ref pos);
                AppendFormat2("{0:" + format2 + "} {1:" + format2 + "} Td {2} Tj\n", pos.X, pos.Y, text);
#endif
            if (underline)
            {
                double underlinePosition = lineSpace * realizedFont.FontDescriptor._descriptor.UnderlinePosition / font.CellSpace;
                double underlineThickness = lineSpace * realizedFont.FontDescriptor._descriptor.UnderlineThickness / font.CellSpace;
                //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness);
                double underlineRectY = Gfx.PageDirection == XPageDirection.Downwards
                    ? y - underlinePosition
                    : y + underlinePosition - underlineThickness;
                DrawRectangle(null, brush, x, underlineRectY, width, underlineThickness);
            }

            if (strikeout)
            {
                double strikeoutPosition = lineSpace * realizedFont.FontDescriptor._descriptor.StrikeoutPosition / font.CellSpace;
                double strikeoutSize = lineSpace * realizedFont.FontDescriptor._descriptor.StrikeoutSize / font.CellSpace;
                //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize);
                double strikeoutRectY = Gfx.PageDirection == XPageDirection.Downwards
                    ? y - strikeoutPosition
                    : y + strikeoutPosition - strikeoutSize;
                DrawRectangle(null, brush, x, strikeoutRectY, width, strikeoutSize);
            }
        }
 internal static double GetSubSuperScaling(XFont font)
 {
     return(0.8 * GetAscent(font) / font.GetHeight());
 }
    /// <summary>
    /// Makes the specified font and brush to the current graphics objects.
    /// </summary>
    void Realize(XFont font, XBrush brush, int renderMode)
    {
      BeginPage();
      RealizeTransform();

      if (this.streamMode != StreamMode.Text)
      {
        this.streamMode = StreamMode.Text;
        this.content.Append("BT\n");
        // Text matrix is empty after BT
        this.gfxState.realizedTextPosition = new XPoint();
      }
      this.gfxState.RealizeFont(font, brush, renderMode);
    }
        /// <summary>
        /// Converts an DOM Font to an XFont.
        /// </summary>
        internal static XFont FontToXFont(Font font, XPrivateFontCollection pfc,
                                          PdfFontEncoding encoding, PdfFontEmbedding fontEmbedding)
        {
            XFont xFont = null;

#if GDI____  // done in PDFsharp
#if CACHE_FONTS
            string signature = BuildSignature(font, unicode, fontEmbedding);
            xFont = fontCache[signature] as XFont;
            if (xFont == null)
            {
                XPdfFontOptions options = null;
                options = new XPdfFontOptions(fontEmbedding, unicode);
                XFontStyle style = GetXStyle(font);
                xFont = new XFont(font.Name, font.Size, style, options);
                fontCache[signature] = xFont;
            }
#else
            XPdfFontOptions options = null;
            options = new XPdfFontOptions(encoding, fontEmbedding);
            XFontStyle style = GetXStyle(font);
            if (pfc != null && pfc.PrivateFontCollection != null)
            {
                // Is it a private font?
                try
                {
                    foreach (System.Drawing.FontFamily ff in pfc.PrivateFontCollection.Families)
                    {
                        if (String.Compare(ff.Name, font.Name, true) == 0)
                        {
                            xFont = new XFont(ff, font.Size, style, options, pfc);
                            break;
                        }
                    }
                }
                catch
                {
#if DEBUG
                    pfc.GetType();
#endif
                }
            }
#endif
#endif

#if WPF___
            XPdfFontOptions options = null;
            options = new XPdfFontOptions(encoding, fontEmbedding);
            XFontStyle style = GetXStyle(font);
            //if (pfc != null &&
            //  pfc.PrivateFontCollection != null)
            //{
            //  // Is it a private font?
            //  try
            //  {
            //    foreach (System.Drawing.FontFamily ff in pfc.PrivateFontCollection.Families)
            //    {
            //      if (String.Compare(ff.Name, font.Name, true) == 0)
            //      {
            //        xFont = new XFont(ff, font.Size, style, options, pfc);
            //        break;
            //      }
            //    }
            //  }
            //  catch
            //  {
            //  }
            //}
#endif

            // #PFC
            XPdfFontOptions options = null;
            options = new XPdfFontOptions(encoding, fontEmbedding);
            XFontStyle style = GetXStyle(font);

            if (xFont == null)
            {
                xFont = new XFont(font.Name, font.Size, style, options);
            }
#if DEBUG
            CreateFontCounter++;
#endif
            return(xFont);
        }
    // ----- DrawString ---------------------------------------------------------------------------

    public void DrawString(string s, XFont font, XBrush brush, XRect rect, XStringFormat format)
    {
      Realize(font, brush, 0);

      double x = rect.X;
      double y = rect.Y;

      double lineSpace = font.GetHeight(this.gfx);
      //int cellSpace = font.cellSpace; // font.FontFamily.GetLineSpacing(font.Style);
      //int cellAscent = font.cellAscent; // font.FontFamily.GetCellAscent(font.Style);
      //int cellDescent = font.cellDescent; // font.FontFamily.GetCellDescent(font.Style);
      //double cyAscent = lineSpace * cellAscent / cellSpace;
      //double cyDescent = lineSpace * cellDescent / cellSpace;
      double cyAscent = lineSpace * font.cellAscent / font.cellSpace;
      double cyDescent = lineSpace * font.cellDescent / font.cellSpace;
      double width = this.gfx.MeasureString(s, font).Width;

      bool bold = (font.Style & XFontStyle.Bold) != 0;
      bool italic = (font.Style & XFontStyle.Italic) != 0;
      bool strikeout = (font.Style & XFontStyle.Strikeout) != 0;
      bool underline = (font.Style & XFontStyle.Underline) != 0;

      switch (format.Alignment)
      {
        case XStringAlignment.Near:
          // nothing to do
          break;

        case XStringAlignment.Center:
          x += (rect.Width - width) / 2;
          break;

        case XStringAlignment.Far:
          x += rect.Width - width;
          break;
      }
      if (Gfx.PageDirection == XPageDirection.Downwards)
      {
        switch (format.LineAlignment)
        {
          case XLineAlignment.Near:
            y += cyAscent;
            break;

          case XLineAlignment.Center:
            // TODO use CapHeight. PDFlib also uses 3/4 of ascent
            y += (cyAscent * 3 / 4) / 2 + rect.Height / 2;
            break;

          case XLineAlignment.Far:
            y += -cyDescent + rect.Height;
            break;

          case XLineAlignment.BaseLine:
            // nothing to do
            break;
        }
      }
      else
      {
        switch (format.LineAlignment)
        {
          case XLineAlignment.Near:
            y += cyDescent;
            break;

          case XLineAlignment.Center:
            // TODO use CapHeight. PDFlib also uses 3/4 of ascent
            y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2;
            break;

          case XLineAlignment.Far:
            y += -cyAscent + rect.Height;
            break;

          case XLineAlignment.BaseLine:
            // nothing to do
            break;
        }
      }

      PdfFont realizedFont = this.gfxState.realizedFont;
      Debug.Assert(realizedFont != null);
      realizedFont.AddChars(s);

      OpenTypeDescriptor descriptor = realizedFont.FontDescriptor.descriptor;

      if (bold && !descriptor.IsBoldFace)
      {
        // TODO: emulate bold by thicker outline
      }

      if (italic && !descriptor.IsBoldFace)
      {
        // TODO: emulate italic by shearing transformation
      }

      if (font.Unicode)
      {
        string s2 = "";
        for (int idx = 0; idx < s.Length; idx++)
        {
          char ch = s[idx];
          int glyphID = 0;
          if (descriptor.fontData.cmap.symbol)
          {
            glyphID = (int)ch + (descriptor.fontData.os2.usFirstCharIndex & 0xFF00);
            glyphID = descriptor.CharCodeToGlyphIndex((char)glyphID);
          }
          else
            glyphID = descriptor.CharCodeToGlyphIndex(ch);
          s2 += (char)glyphID;
        }
        s = s2;

        byte[] bytes = PdfEncoders.RawUnicodeEncoding.GetBytes(s);
        bytes = PdfEncoders.FormatStringLiteral(bytes, true, false, true, null);
        string text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length);
        XPoint pos = new XPoint(x, y);
        AdjustTextMatrix(ref pos);
        AppendFormat(
          "{0:0.####} {1:0.####} Td {2} Tj\n", pos.x, pos.y, text);
        //PdfEncoders.ToStringLiteral(s, PdfStringEncoding.RawEncoding, null));
      }
      else
      {
        byte[] bytes = PdfEncoders.WinAnsiEncoding.GetBytes(s);
        XPoint pos = new XPoint(x, y);
        AdjustTextMatrix(ref pos);
        AppendFormat(
          "{0:0.####} {1:0.####} Td {2} Tj\n", pos.x, pos.y,
          PdfEncoders.ToStringLiteral(bytes, false, null));
      }

      if (underline)
      {
        double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace;
        double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace;
        DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness);
      }

      if (strikeout)
      {
        double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace;
        double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace;
        DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize);
      }
    }
Exemple #44
0
        public string MakePDF(Lease lease, Business business)
        {
            // Her bruges classen pdfDocument.
            PdfDocument document = new PdfDocument();

            // Her laver jeg et pdf dokument og kalder det Faktura
            document.Info.Title = "Faktura";

            // Her laves en side
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Opret skrift størelse og sill
            XFont companyAndDebtor = new XFont("Calibri", 10, XFontStyle.Regular);
            XFont fakture          = new XFont("Calibri", 20, XFontStyle.Bold);
            XFont smallHeadLine    = new XFont("Calibri", 10, XFontStyle.Bold);
            XFont priceFat         = new XFont("Calibri", 10, XFontStyle.Bold);

            // Draw the text. Dette er hvad der skal være på teksten, og hvor det skal være. Der kan laves lige så mange som man vil
            //Kunde Oplysninger------------------------------------------------------------------------------------------------------------------------------

            gfx.DrawString($"{business.companyName}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -270, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString($"{business.street}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -260, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString($"{business.postalCode} {business.city}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -250, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString($"Kunde Nr: {lease.debtorID}", companyAndDebtor, XBrushes.Black,
                           new XRect(80, -230, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //FAKTURA---------------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("FAKTURA", fakture, XBrushes.Black,
                           new XRect(80, -170, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Billede af Delpin----------------------------------------------------------------------------------------------------------------------------
            var image = DelpinCore.Properties.Resources.Delpinlogo;

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);

            XImage xImage = XImage.FromStream(stream);

            gfx.DrawImage(xImage, 405, 35);

            //Firma informationer----------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("Nordvesthavnsvej 60 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -300, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("6400 Sønderborg ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -290, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Tlf 74 48 88 88 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -280, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //BankOplysninger------------------------------------------------------------------------------------------------------------------------------
            gfx.DrawString("Bank ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -250, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Reg. Nr:9735 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -240, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString("Konto Nr:4571973602842330 ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -230, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Fakture Nr dato og betalings dato------------------------------------------------------------------------------------------------------------
            gfx.DrawString($"Faktura Nr.{lease.leaseID} ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -180, page.Width, page.Height),
                           XStringFormats.CenterRight);

            gfx.DrawString($"{lease.dateCreated.ToShortDateString()} ", companyAndDebtor, XBrushes.Black,
                           new XRect(-60, -170, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Headlines Resurce Antal Pris Beløb-----------------------------------------------------------------------------------------------------------
            gfx.DrawString("Vare ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -130, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            gfx.DrawString("Antal Dage ", smallHeadLine, XBrushes.Black,
                           new XRect(0, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("Daglig Lejepris ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("Levering ", smallHeadLine, XBrushes.Black,
                           new XRect(150, -130, page.Width, page.Height),
                           XStringFormats.Center);

            gfx.DrawString("Beløb ", smallHeadLine, XBrushes.Black,
                           new XRect(-60, -130, page.Width, page.Height),
                           XStringFormats.CenterRight);

            //Navn på vare antal pris beløb-------------------------------------------------------------------------------------------------------------
            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -125, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Her oprettes en variabel som sættes til 0
            int lineSpace = 0;

            for (int i = 0; i < lease.GetLeaseOrders().Count; i++)
            {
                //Her bliver Variablen sat til 15. så hver gange der bliver kørt GetLeaseOrders(tilføjet en ny vare linje bliver der pludset 15 til y aksens position)
                lineSpace = 15 * i;

                gfx.DrawString($"{lease.GetLeaseOrders()[i].modelName}", companyAndDebtor, XBrushes.Black,
                               new XRect(80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString($"{lease.GetLeaseOrders()[i].GetDaysRented()}", companyAndDebtor, XBrushes.Black,
                               new XRect(0, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                gfx.DrawString($"Kr. {lease.GetLeaseOrders()[i].leasePrice} ", companyAndDebtor, XBrushes.Black,
                               new XRect(80, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                gfx.DrawString($"Kr. {lease.GetLeaseOrders()[i].deliveryPrice}", companyAndDebtor, XBrushes.Black,
                               new XRect(150, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.Center);

                gfx.DrawString($"Kr. {lease.GetLeaseOrders()[i].GetTotalPrice()}", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -110 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);
            }

            gfx.DrawString("___________________________________________________________________________________________ ", smallHeadLine, XBrushes.Black,
                           new XRect(80, -100 + lineSpace, page.Width, page.Height),
                           XStringFormats.CenterLeft);

            //Hvis det er erhvers person
            if (business.CVR.Length == 8)
            {
                gfx.DrawString("Total: ", priceFat, XBrushes.Black,
                               new XRect(400, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString($"Kr. {lease.GetTotalPrice()} ", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                               new XRect(400, -15 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            //Hvis det er Privat person
            else
            {
                gfx.DrawString("Netto: ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Moms (25%): ", companyAndDebtor, XBrushes.Black,
                               new XRect(400, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString("Total: ", priceFat, XBrushes.Black,
                               new XRect(400, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);

                gfx.DrawString($"Kr. {lease.GetTotalPrice()} ", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -20 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString($"Kr. {Moms(lease.GetTotalPrice())} ", companyAndDebtor, XBrushes.Black,
                               new XRect(-60, -5 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString($"Kr. {endPrice(Moms(lease.GetTotalPrice()), lease.GetTotalPrice())} ", priceFat, XBrushes.Black,
                               new XRect(-60, 10 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterRight);

                gfx.DrawString("___________________________ ", smallHeadLine, XBrushes.Black,
                               new XRect(400, 15 + lineSpace, page.Width, page.Height),
                               XStringFormats.CenterLeft);
            }

            //Her Laves navnet på filen
            string filename = $"Faktura{lease.leaseID}.pdf";

            try
            {
                //Dette er til at gemme pdf
                document.Save(filename);
            }
            catch (Exception)
            {
                return("Filen kan ikke gemmes");
            }

            //Dette er til at vise PDF
            Process.Start(filename);
            return("Success");
        }
    public void RealizeFont(XFont font, XBrush brush, int renderMode)
    {
      // So far rendering mode 0 only
      RealizeBrush(brush, this.renderer.colorMode); // this.renderer.page.document.Options.ColorMode);

      this.realizedFont = null;
      string fontName = this.renderer.GetFontName(font, out this.realizedFont);
      if (fontName != this.realizedFontName || this.realizedFontSize != font.Size)
      {
        if (this.renderer.Gfx.PageDirection == XPageDirection.Downwards)
          this.renderer.AppendFormat("{0} {1:0.###} Tf\n", fontName, -font.Size);
        else
          this.renderer.AppendFormat("{0} {1:0.###} Tf\n", fontName, font.Size);

        this.realizedFontName = fontName;
        this.realizedFontSize = font.Size;
      }
    }
Exemple #46
0
 /// <summary>
 /// Draws the text.
 /// </summary>
 /// <param name="text">The text to be drawn.</param>
 /// <param name="font">The font.</param>
 /// <param name="brush">The text brush.</param>
 /// <param name="layoutRectangle">The layout rectangle.</param>
 public void DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle)
 {
     DrawString(text, font, brush, layoutRectangle, XStringFormats.TopLeft);
 }