Beispiel #1
0
        private static void drawTermsTable(PdfPage newPage, XGraphics gfx, XPen pen, int startX, int startY, int columnWidth, int rowHeight)
        {
            int rowCount = AppForm.CURR_OCTT_DOC.IncludedTerms.Count;

            gfx.DrawRectangle(pen, startX, startY, columnWidth, rowHeight * rowCount);

            for (int j = 0; j < rowCount - 1; j++)
            {
                gfx.DrawLine(pen, startX, startY + (j + 1) * rowHeight, startX + columnWidth, startY + (j + 1) * rowHeight);
            }

            for (int j = 0; j < rowCount; j++)
            {
                int[]     term      = (int [])AppForm.CURR_OCTT_DOC.IncludedTerms[j];
                string [] printTerm = new string[4];
                for (int t = 0; t < 4; t++)
                {
                    if (term[t] < 10)
                    {
                        printTerm[t] = "0" + System.Convert.ToString(term[t]);
                    }
                    else
                    {
                        printTerm[t] = System.Convert.ToString(term[t]);
                    }
                }

                string termText = printTerm[0] + ":" + printTerm[1] + "-" + printTerm[2] + ":" + printTerm[3];


                XRect rect = new XRect(startX + 4, startY + j * rowHeight + 4, columnWidth - 8, rowHeight - 8);

                XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
                //XFont font = new XFont("Arial", 8, XFontStyle.Bold, options);
                XFont font = getMyFont(Settings.TTREP_FONT_TIME_PERIODS, options);

                XBrush        brush  = XBrushes.Black;
                XStringFormat format = new XStringFormat();

                //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
                char[] separator = new char[1];
                separator[0] = ',';
                string[] ss = Settings.TTREP_COLOR_TP.Split(separator, 3);
                int      R  = System.Convert.ToInt32(ss[0]);
                int      G  = System.Convert.ToInt32(ss[1]);
                int      B  = System.Convert.ToInt32(ss[2]);

                gfx.DrawRectangle(XPens.Black, new XSolidBrush(XColor.FromArgb(R, G, B)), rect);
                //gfx.DrawRectangle(XPens.Black, XBrushes.LightBlue, rect);

                format.LineAlignment = XLineAlignment.Center;
                format.Alignment     = XStringAlignment.Center;
                gfx.DrawString(termText, font, brush, rect, format);
            }
        }
Beispiel #2
0
        private static void createTableRow(XGraphics gfx, Room room)
        {
            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 roomName = room.getName();

            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(roomName, font, brush, rect, format);

            currX += COL_WIDTH[0] + COL_GAP;

            string roomCapacity = room.getRoomCapacity().ToString();

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

            currX += COL_WIDTH[1] + COL_GAP;

            string roomExtID = room.ExtID;

            rect = new XRect(currX, CURR_Y, COL_WIDTH[2], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(roomExtID, 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;
        }
Beispiel #3
0
        private static void drawMainTable(PdfPage newPage, XGraphics gfx, XPen pen, int startX, int startY, int columnWidth, int rowHeight, DataTable dt)
        {
            int rowCount    = AppForm.CURR_OCTT_DOC.IncludedTerms.Count;
            int columnCount = AppForm.CURR_OCTT_DOC.getNumberOfDays();

            for (int j = 0; j < rowCount; j++)
            {
                gfx.DrawLine(pen, startX, startY + (j + 1) * rowHeight, startX + columnCount * columnWidth, startY + (j + 1) * rowHeight);

                for (int k = 0; k < columnCount; k++)
                {
                    gfx.DrawLine(pen, startX + (k + 1) * columnWidth, startY, startX + (k + 1) * columnWidth, startY + rowCount * rowHeight);
                }
            }

            for (int j = 0; j < rowCount; j++)
            {
                DataRow dr = dt.Rows[j];
                for (int k = 0; k < columnCount; k++)
                {
                    string cellString = (string)dr[k];
                    if (cellString != "")
                    {
                        XRect rect = new XRect(startX + k * columnWidth + 4, startY + j * rowHeight + 4, columnWidth - 8, rowHeight - 8);

                        //
                        XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

                        //XFont font = new XFont("Arial", 6, XFontStyle.Regular,  options);
                        XFont  font  = getMyFont(Settings.TTREP_FONT_TIME_SLOTS, options);
                        XBrush brush = XBrushes.Black;
                        //XStringFormat format = new XStringFormat();
                        //
                        char[] separator = new char[1];
                        separator[0] = ',';
                        string[] ss = Settings.TTREP_COLOR_TS.Split(separator, 3);
                        int      R  = System.Convert.ToInt32(ss[0]);
                        int      G  = System.Convert.ToInt32(ss[1]);
                        int      B  = System.Convert.ToInt32(ss[2]);

                        gfx.DrawRectangle(XPens.Black, new XSolidBrush(XColor.FromArgb(R, G, B)), rect);

                        //
                        //gfx.DrawRectangle(XPens.Black, XBrushes.LightCyan, rect);

                        rect = new XRect(startX + k * columnWidth + 6, startY + j * rowHeight + 6, columnWidth - 12, rowHeight - 12);

                        XTextFormatter tf = new XTextFormatter(gfx);
                        tf.Alignment = XParagraphAlignment.Center;
                        tf.DrawString(cellString, font, brush, rect, XStringFormat.TopLeft);
                    }
                }
            }
        }
Beispiel #4
0
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            string facename = "Times";
            XFont  fontR    = new XFont(facename, 40);
            XFont  fontB    = new XFont(facename, 40, XFontStyle.Bold);
            XFont  fontI    = new XFont(facename, 40, XFontStyle.Italic);
            XFont  fontBI   = new XFont(facename, 40, XFontStyle.Bold | XFontStyle.Italic);
            //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200);
            double x   = 80;
            XPen   pen = XPens.SlateBlue;

            gfx.DrawLine(pen, x, 100, x, 600);
            gfx.DrawLine(pen, x - 50, 200, 400, 200);
            gfx.DrawLine(pen, x - 50, 300, 400, 300);
            gfx.DrawLine(pen, x - 50, 400, 400, 400);
            gfx.DrawLine(pen, x - 50, 500, 400, 500);

            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;

            XFontMetrics metrics = fontR.Metrics;

            XSize size;

            gfx.DrawString("Times 40", fontR, this.properties.Font1.Brush, x, 200);
            size = gfx.MeasureString("Times 40", fontR);
            gfx.DrawLine(this.properties.Pen3.Pen, x, 200, x + size.Width, 200);

            gfx.DrawString("Times bold 40", fontB, this.properties.Font1.Brush, x, 300);
            size = gfx.MeasureString("Times bold 40", fontB);
            //gfx.DrawLine(this.properties.Pen3.Pen, x, 300, x + size.Width, 300);

            gfx.DrawString("Times italic 40", fontI, this.properties.Font1.Brush, x, 400);
            size = gfx.MeasureString("Times italic 40", fontI);
            //gfx.DrawLine(this.properties.Pen3.Pen, x, 400, x + size.Width, 400);

            gfx.DrawString("Times bold italic 40", fontBI, this.properties.Font1.Brush, x, 500);
            size = gfx.MeasureString("Times bold italic 40", fontBI);
            //gfx.DrawLine(this.properties.Pen3.Pen, x, 500, x + size.Width, 500);

#if true___
            // Check Malayalam
            XPdfFontOptions options       = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XFont           Kartika       = new XFont("Kartika", 20, XFontStyle.Regular, options);
            XFont           AnjaliOldLipi = new XFont("AnjaliOldLipi", 20, XFontStyle.Regular, options);
            gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", Kartika, this.properties.Font1.Brush, x, 600);
            gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", AnjaliOldLipi, this.properties.Font1.Brush, x, 650);
#endif
        }
Beispiel #5
0
        private void Init()
        {
            GlobalFontSettings.FontResolver = fontResolver;
            fontResolver.AddFont("Times New Roman", XFontStyle.Regular, fontTempatePath, true, true);

            // Устанавливаю кодировку - UNICODE
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            // Устанавливаю шрифт
            font = new XFont("Times New Roman", 12);
        }
Beispiel #6
0
        private void DrawOneBadge(XGraphics graph, int x, int y, string nev, string poszt, double wp, double hp)
        {
            const int BadgeWidth  = 255; // 90mm
            const int BadgeHeight = 156; // 55mm

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

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

            XImage logo = null;

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

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

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

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

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

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

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

            textFormatter.DrawString(nev, fontName, XBrushes.Black, new XRect(textStartX, textStartY, textWidth, textHeight));
            textFormatter.DrawString(poszt, fontPos, XBrushes.Black, new XRect(textStartX, textStartY + (lineNum * fontName.Height), textWidth, textHeight));
            graph.DrawImage(logo, logoStartX, logoStartY, logoWidth, logoHeight);
            graph.DrawLine(new Pen(Color.Black, 1), lineStartX, lineStartY, lineEndX, lineEndY);
        }
Beispiel #7
0
        public PdfType0Font(PdfDocument document, string idName, byte[] fontData, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorStock.Global.CreateDescriptor(idName, fontData);

            fontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            fontOptions    = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            Debug.Assert(fontOptions != null);

            cmapInfo                = new CMapInfo(ttDescriptor);
            descendantFont          = new PdfCIDFont(document, fontDescriptor, fontData);
            descendantFont.CMapInfo = cmapInfo;

            // Create ToUnicode map
            toUnicode = new PdfToUnicodeMap(document, cmapInfo);
            document.Internals.AddObject(toUnicode);
            Elements.Add(Keys.ToUnicode, toUnicode);

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

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

            //  case XFontStyle.Bold | XFontStyle.Italic:
            //    this.BaseFont += ",BoldItalic";
            //    break;
            //}

            // CID fonts are always embedded
            if (!BaseFont.Contains("+")) // HACK in PdfType0Font
            {
                BaseFont = CreateEmbeddedFontSubsetName(BaseFont);
            }

            fontDescriptor.FontName = BaseFont;
            descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);

            Owner.irefTable.Add(descendantFont);
            descendantFonts.Elements.Add(descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }
Beispiel #8
0
        private static void createPageHeader(XGraphics gfx)
        {
            string institutionName = AppForm.CURR_OCTT_DOC.EduInstitutionName;

            XRect rect = new XRect(45, 60, 505, 30);
            //XRect rect = new XRect(tableStartX + termsTableColumnWidth, tableStartY - 25, columnCount * columnWidth, 20);
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XFont           font    = new XFont("Arial", 16, XFontStyle.Regular, 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(institutionName, font, brush, rect, format);

            string reportName = RES_MANAGER.GetString("teacher_list");

            rect             = new XRect(75, 100, 445, 26);
            font             = new XFont("Arial", 14, XFontStyle.Bold, options);
            format.Alignment = XStringAlignment.Center;
            //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
            gfx.DrawString(reportName, font, brush, rect, format);


            string printDate = System.DateTime.Now.ToShortDateString();

            rect             = new XRect(430, 30, 120, 16);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Far;
            //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
            gfx.DrawString(printDate, font, brush, rect, format);

            createTableHeader(gfx);


            string pageNumber = RES_MANAGER.GetString("page") + ": " + PAGE_COUNTER + "/" + TOTAL_PAGE_NUMBER;

            rect             = new XRect(430, 790, 120, 16);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Far;
            //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
            gfx.DrawString(pageNumber, font, brush, rect, format);

            string octt = "Generated by Open Course Timetabler (www.openctt.org)";

            rect             = new XRect(150, 790, 295, 16);
            font             = new XFont("Tahoma", 7, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Center;
            //gfx.DrawRectangle(XPens.Black, XBrushes.Bisque, rect);
            gfx.DrawString(octt, font, brush, rect, format);
        }
        private static void createTableHeader(XGraphics gfx)
        {
            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, 1.5);
            XBrush xbrush = XBrushes.Bisque;

            XRect rect;
            XFont font;

            int currX = X_START;

            string headerLastName = RES_MANAGER.GetString("lastname");

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

            currX += COL_WIDTH[0] + COL_GAP;

            string headerName = RES_MANAGER.GetString("name");

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

            currX += COL_WIDTH[1] + COL_GAP;

            string headerTitle = RES_MANAGER.GetString("title");

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

            currX += COL_WIDTH[2] + COL_GAP;

            string headerEduRank = RES_MANAGER.GetString("hours_per_week");

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

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

            CURR_Y += 20;
        }
Beispiel #10
0
 //#if
 public TrueTypeDescriptor(XFont font, XPdfFontOptions options, XPrivateFontCollection privateFontCollection)
 {
     try
     {
         this.fontData = new FontData(font, options);
         this.fontName = font.Name;
         Initialize();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public OpenTypeDescriptor(XFont font, XPdfFontOptions options)
 {
     try
     {
         this.fontData = new FontData(font, options);
         this.fontName = font.Name;
         Initialize();
     }
     catch
     {
         throw;
     }
 }
        private void ExportHistoryDrawReportSummary(PagingSetup pagingSetup, PdfDocument document,
                                                    DateTime startDate, DateTime endDate)
        {
            var options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            ReportUtils.DrawParagraphLine(pagingSetup, document, new XFont("Tahoma", 12, XFontStyle.Bold, options),
                                          XParagraphAlignment.Center, pagingSetup.RegularLineHeight,
                                          string.Format("Từ ngày: {0} - Đến ngày: {1}",
                                                        startDate.ToString(CommonConstant.DateFormatDisplay),
                                                        endDate.ToString(CommonConstant.DateFormatDisplay)));

            ReportUtils.IncreaseLineHeight(pagingSetup, document, pagingSetup.RegularLineHeight);
        }
Beispiel #13
0
        static XFont XFontFromCache(Font font, bool unicode, PdfFontEmbedding fontEmbedding)
        {
            XFont xFont = null;

            XPdfFontOptions options = null;

            options = new XPdfFontOptions(fontEmbedding, unicode);
            XFontStyle style = GetXStyle(font);

            xFont = new XFont(font.Name, font.Size, style, options);

            return(xFont);
        }
Beispiel #14
0
        /* END OF OVERLOADS */

        //real konstruktor
        private void ParagraphConstructor(string text, bool IsFixed = false, double x = 0, double y = 0, double height = 0, double width = 0, string font = null, double size = 12, XFontStyle style = XFontStyle.Regular, XParagraphAlignment align = XParagraphAlignment.Left, XStringFormat format = null)
        {
            _text = text;

            if (height > 0)
            {
                this.height = height;
            }
            if (width > 0)
            {
                this.width = width;
            }

            if (IsFixed == true)
            {
                this.IsFixed = true;
            }
            _coords = new XPoint(x, y);

            /*if (font == null || size == 0)
             * {
             *
             *  XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
             *  if (font == null) { _font = new XFont("Calibri", size, style, options); }
             *  else if (size == 0) { _font = new XFont(font, 12, style, options); }
             *  else { _font = new XFont("Calibri", 12, style, options); }
             *
             * }
             * else
             * {*/

            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            _font = new XFont(font, size, style, options);

            //}

            _align = align;

            if (format == null)
            {
                _format = new XStringFormat
                {
                    Alignment = XStringAlignment.Near
                };
            }
            else
            {
                _format = format;
            }
        }
Beispiel #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            int LoopNum = 0;

            LoopNum++;
            this.textBox1.Text += "第" + LoopNum.ToString() + "次循环" + "\r\n";
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            document.Info.Title = "PDFSHARP测试";

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

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

            //XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            System.Drawing.Text.PrivateFontCollection pfcFonts = new System.Drawing.Text.PrivateFontCollection();
            //string strFontPath = @"C:/Windows/Fonts/msyh.ttc";//字体设置为微软雅黑
            //string strFontPath = @"C:/Windows/Fonts/STFANGSO.TTF";
            //STFANGSO.TTF   STXINGKA.TTF
            string strFontPath = @"C:/Windows/Fonts/simhei.ttf";

            //string strFontPath = @"C:\Windows\Boot\Fonts\msyh_boot.ttf";
            //string strFontPath = HttpContext.Current.Server.MapPath("msyh.ttf");
            pfcFonts.AddFontFile(strFontPath);

            //Document document1 = new Document();
            //Style style = document1.Styles["Normal"];
            ////style.Font= new MigraDoc.DocumentObjectModel.Font(pfcFonts.Families[0].Name, 12);
            //style.Font.Color = Colors.Black;
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XFont           font    = new XFont(pfcFonts.Families[0], 15, XFontStyle.Regular, options);

            // Create a font
            //XFont font = new XFont("Times New Roman", 20, XFontStyle.BoldItalic);

            // Draw the text
            gfx.DrawString("efgdfgdsgf你好,病理 世界!这个世在 中枥加格达奇是dsfjsdf罟顶替顶替顶替一压死二百五上下遥", font, XBrushes.Black, new XRect(-240, -400, page.Width, page.Height),
                           XStringFormats.Center);

            // Save the document...
            string filename = "HelloWorld_" + LoopNum.ToString() + ".pdf";

            //string _path = YZRHelper.RPath.GetPath(System.AppDomain.CurrentDomain.BaseDirectory, 2) + "\\PDF\\YZR.pdf";
            document.Save(filename);
            Process.Start(filename);
        }
Beispiel #16
0
        private void AddFields()
        {
            XPdfFontOptions o    = new XPdfFontOptions(PdfFontEncoding.Unicode);
            XFont           font = new XFont("Times New Roman", 14, XFontStyle.Regular, o);

            gfx.DrawString("Бланк фиксации результатов теста", font, XBrushes.Black,
                           new XRect(0, XUnit.FromMillimeter(17).Point, _page.Width, 5),
                           XStringFormats.Center);
            this.DrawLeftString("Подразделение_______________", 10, 25, 60, 10); this.DrawLeftString("Ф.И.О._____________________________________", 70, 25, 90, 10); this.DrawLeftString("Образование_________________", 150, 25, 30, 10);
            this.DrawLeftString("Дата рождения_______________", 10, 30, 60, 10); this.DrawLeftString("Дата тестирования_____________", 150, 30, 30, 10);
            this.DrawLeftString("M", 10, 35, 5, 14); this.DrawRectangle(4, 17, 38); this.DrawLeftString("Ж", 20, 35, 5, 14); this.DrawRectangle(4, 27, 38); this.DrawLeftString("Пример заполнения бланка", 40, 36, 50, 10); this.DrawRectangle(4, 85, 38); this.DrawLeftString("Х", 83, 35, 5, 14);

            this.DrawLine(0, (int)_page.Width.Millimeter, 41);
        }
        protected void DrawText(XGraphics gfx, PdfPage page)
        {
            const int rectHeight    = 200;
            const int middleRectY   = 300;
            const int topRectY      = 230;
            const int topRectHeight = 300;
            var       options       = new XPdfFontOptions(PdfFontEncoding.Unicode);
            var       font          = new XFont(FontName, BaseFontSize, XFontStyle.Regular, options);

            var format = new XStringFormat();

            var topRect = new XRect(LeftIndent, topRectY, TextWidth, topRectHeight);

            gfx.DrawRectangle(XBrushes.White, topRect);

            format.Alignment = XStringAlignment.Far;

            gfx.DrawString($"{_methodicDocument.Name} від {_methodicDocument.Date:dd/MM/yyyy}", font, XBrushes.Black, topRect, format);

            font = new XFont(FontName, TextFontSize, XFontStyle.Regular, options);

            var tfx = new TextFormatter(gfx);

            var middleRect = new XRect(LeftIndent, middleRectY, TextWidth, rectHeight);

            var documentTypeFont = new XFont(FontName, BaseFontSize + 4, XFontStyle.Bold, options);

            gfx.DrawString($"{MethodicDocumentTypeParser(_methodicDocument.Type)}", documentTypeFont, XBrushes.Black,
                           295, 200, XStringFormats.BaseLineCenter);

            tfx.PrepareDrawString(_methodicDocument.Description, font, new XRect(LeftIndent, middleRectY, TextWidth, double.MaxValue),
                                  out var lastCharIndex, out var neededHeight);
            if (neededHeight > rectHeight)
            {
                middleRect = new XRect(LeftIndent, middleRectY, TextWidth, neededHeight);
            }

            if (neededHeight > page.Height - rectHeight - middleRect.Y)
            {
                middleRect = new XRect(LeftIndent, middleRectY, TextWidth, page.Height - middleRect.Y - 30);
                tfx.PrepareDrawString(_methodicDocument.Description, font, middleRect,
                                      out lastCharIndex, out neededHeight);
                middleRect = new XRect(LeftIndent, middleRectY, TextWidth, neededHeight);
            }

            tfx.DrawString(_methodicDocument.Description, font, XBrushes.Black, middleRect, XStringFormats.TopLeft);
            if (lastCharIndex != -1)
            {
                DrawNextPage(_methodicDocument.Description[(lastCharIndex + 1)..], font);
Beispiel #18
0
        private void DrawText(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "Text Styles");
            XPdfFontOptions pdfOptions = new XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.Default);
            XFont           font       = new XFont("Times New Roman", 20.0, XFontStyle.Regular, pdfOptions);
            XFont           font2      = new XFont("Times New Roman", 20.0, XFontStyle.Bold, pdfOptions);
            XFont           font3      = new XFont("Times New Roman", 20.0, XFontStyle.Italic, pdfOptions);
            XFont           font4      = new XFont("Times New Roman", 20.0, XFontStyle.BoldItalic, pdfOptions);

            gfx.DrawString("Times (regular)", font, XBrushes.DarkSlateGray, 0.0, 30.0);
            gfx.DrawString("Times (bold)", font2, XBrushes.DarkSlateGray, 0.0, 65.0);
            gfx.DrawString("Times (italic)", font3, XBrushes.DarkSlateGray, 0.0, 100.0);
            gfx.DrawString("Times (bold italic)", font4, XBrushes.DarkSlateGray, 0.0, 135.0);
            base.EndBox(gfx);
        }
Beispiel #19
0
        private void DrawReportSummary(PagingSetup pagingSetup, PdfDocument document,
                                       RemovalNote removalNote)
        {
            var options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            ReportUtils.DrawParagraphLine(pagingSetup, document, new XFont("Tahoma", 12, XFontStyle.Bold, options),
                                          XParagraphAlignment.Center, pagingSetup.RegularLineHeight,
                                          string.Format("Mã hủy: {0}", removalNote.RemovalId));

            ReportUtils.IncreaseLineHeight(pagingSetup, document, pagingSetup.RegularLineHeight);

            ReportUtils.DrawParagraphLine(pagingSetup, document, PagingSetup.CreateDefaultPDFRegularFont(),
                                          XParagraphAlignment.Left, pagingSetup.RegularLineHeight,
                                          "Danh sách hủy: ");
        }
        protected void createPDF()
        {
            pdf = new PdfDocument();

            var font_settings = new XPdfFontOptions(PdfFontEncoding.Unicode);

            f1 = createFont("Verdana", fontSize);

            pdf.Version = 14;
            pages       = new List <PdfPage>();
            newPage();

            double[] sizes = parser.GetSizes();
            pageWidth  = sizes[0] - OffsetLeft - OffsetRight;
            pageHeight = sizes[1] - OffsetTop - OffsetBottom;
            printHeader();
        }
Beispiel #21
0
        private static void DrawText(XGraphics gfx, string text, string font, string style, double size, string color, int width, int height, int x, int y)
        {
            XPdfFontOptions options   = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Default);
            XFont           fontStyle = null;

            switch (style)
            {
            case "Bold":
                fontStyle = new XFont(font, size, XFontStyle.Bold, options);
                break;

            case "Italic":
                fontStyle = new XFont(font, size, XFontStyle.Italic, options);
                break;

            case "Regular":
                fontStyle = new XFont(font, size, XFontStyle.Regular, options);
                break;

            case "Underline":
                fontStyle = new XFont(font, size, XFontStyle.Underline, options);
                break;

            case "Strikeout":
                fontStyle = new XFont(font, size, XFontStyle.Strikeout, options);
                break;

            case "BoldItalic":
                fontStyle = new XFont(font, size, XFontStyle.BoldItalic, options);
                break;

            default:
                break;
            }
            System.Drawing.Color fontColor = ConverterManager.HexToColorConverter(color);
            XBrush fontBrush = new XSolidBrush(new XColor {
                R = fontColor.R, G = fontColor.G, B = fontColor.B
            });
            XRect         fontRect   = new XRect(x, y, width, height);
            XStringFormat fontFormat = new XStringFormat {
                Alignment = XStringAlignment.Center
            };

            gfx.DrawString(text, fontStyle, fontBrush, fontRect, fontFormat);
        }
Beispiel #22
0
        /// <summary>
        /// Converts a DOM Font to an XFont.
        /// </summary>
        internal static XFont FontToXFont(Font font, PdfFontEncoding encoding)
        {
            XPdfFontOptions options = new XPdfFontOptions(encoding);
            XFontStyle      style   = GetXStyle(font);

#if DEBUG
            if (StringComparer.OrdinalIgnoreCase.Compare(font.Name, "Segoe UI Semilight") == 0 &&
                (style & XFontStyle.BoldItalic) == XFontStyle.Italic)
            {
                font.GetType();
            }
#endif
            XFont xFont = new XFont(font.Name, font.Size, style, options);
#if DEBUG
            CreateFontCounter++;
#endif
            return(xFont);
        }
Beispiel #23
0
        private static XFont getMyFont(string myFontSettings, XPdfFontOptions options)
        {
            char[] separator = new char[1];
            separator[0] = ',';
            string[] ss         = myFontSettings.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);

            return(font);
        }
Beispiel #24
0
        static void RenderTextStyles(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            const string facename       = "Times New Roman";
            XFont        fontRegular    = new XFont(facename, 20, XFontStyle.Regular, options);
            XFont        fontBold       = new XFont(facename, 20, XFontStyle.Bold, options);
            XFont        fontItalic     = new XFont(facename, 20, XFontStyle.Italic, options);
            XFont        fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic, options);

            // The default alignment is baseline left (that differs from GDI+)
            gfx.DrawString(facename + " (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30);
            gfx.DrawString(facename + " (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65);
            gfx.DrawString(facename + " (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100);
            gfx.DrawString(facename + " (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135);
        }
Beispiel #25
0
        private static void createTableHeader(XGraphics gfx)
        {
            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, 1.5);
            XBrush xbrush = XBrushes.Bisque;

            XRect rect;
            XFont font;

            int currX = X_START;

            string headerRoom = RES_MANAGER.GetString("room");

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

            currX += COL_WIDTH[0] + COL_GAP;

            string headerCapacity = RES_MANAGER.GetString("capacity");

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

            currX += COL_WIDTH[1] + COL_GAP;

            string headerExtID = RES_MANAGER.GetString("extid");

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

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

            CURR_Y += 20;
        }
        public void drawTextLine(int pageNumber, string text, Size size, bool isTitle)
        {
            PdfPage page = pages[pageNumber - 1];
            // Get an XGraphics object for drawing
            XGraphics gfx = gfxes[pageNumber - 1];
            // Create a font
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XFont           font    = new XFont("標楷體", (int)size, XFontStyle.Bold, options);
            // Draw the text
            XStringFormat format = isTitle ? XStringFormats.TopCenter : XStringFormats.TopLeft;

            gfx.DrawString(text, font, XBrushes.Black,
                           new XRect(10, nowY[pageNumber - 1], page.Width - 20, (int)size), format);
            nowY[pageNumber - 1] = nowY[pageNumber - 1] + (int)size + 2;
            if (isTitle)
            {
                nowY[pageNumber - 1] = nowY[pageNumber - 1] + 10;
            }
        }
Beispiel #27
0
        private void AddFields(PdfRectangle rect)
        {
            float           offset = (float)XUnit.FromPoint(rect.X1).Millimeter;
            XPdfFontOptions o      = new XPdfFontOptions(PdfFontEncoding.Unicode);
            XFont           font   = new XFont("Times New Roman", 14, XFontStyle.Regular, o);

            gfx.DrawString("Бланк фиксации результатов теста", font, XBrushes.Black,
                           new XRect(rect.X1, rect.Y1 + XUnit.FromMillimeter(17).Point, rect.X2 - rect.X1, 5),
                           XStringFormats.Center);


            this.DrawLeftString("Подразделение_______________", 10 + offset, 25, 60, 10); this.DrawLeftString("Ф.И.О._____________________________________", 70 + offset, 25, 90, 10);
            this.DrawLeftString("Дата рождения_______________", 10 + offset, 30, 60, 10);
            this.DrawLeftString("Образование_________________", 10 + offset, 35, 30, 10); this.DrawLeftString("Дата тестирования__________________________", 70 + offset, 35, 30, 10);

            this.DrawLeftString("M", 10 + offset, 40, 5, 14); this.DrawRectangle(4, 17 + offset, 42); this.DrawLeftString("Ж", 20 + offset, 40, 5, 14); this.DrawRectangle(4, 27 + offset, 42); this.DrawLeftString("Пример заполнения бланка", 40 + offset, 40, 50, 10); this.DrawRectangle(4, 85 + offset, 42); this.DrawLeftString("Х", 83 + offset, 40, 5, 14);

            this.DrawLine(0, (int)_page.Width.Millimeter, 45);
        }
Beispiel #28
0
 /// <summary>
 /// This is an external helper function.
 /// </summary>
 public static byte[] F74167FFE4044F53B28A4AF049E9EF25(XFont font, XPdfFontOptions options, bool subset)
 {
     byte[] data = null;
     if (subset)
     {
         OpenTypeDescriptor descriptor = new OpenTypeDescriptor(font, options);
         FontData           image      = descriptor.fontData;
         CMapInfo           cmapInfo   = new CMapInfo(descriptor);
         cmapInfo.AddAnsiChars();
         image = image.CreateFontSubSet(cmapInfo.GlyphIndices, false);
         data  = image.Data;
     }
     else
     {
         FontData fontData = new FontData(font, options);
         data = fontData.Data;
     }
     return(data);
 }
Beispiel #29
0
        public static void save(List <Meal> meals, Label label1, Label label2)
        {
            if (Convert.ToDouble(label1.Text) < Convert.ToDouble(label2.Text))
            {
                return;
            }
            PdfDocument pdf = new PdfDocument();

            pdf.Info.Title = "Diet";
            PdfPage pdfPage = pdf.AddPage();

            XGraphics       graph   = XGraphics.FromPdfPage(pdfPage);
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            XFont font1 = new XFont("Times New Roman", 12, XFontStyle.Bold, options);
            XFont font2 = new XFont("Times New Roman", 14, XFontStyle.Bold);
            XFont font3 = new XFont("Castellar", 25, XFontStyle.Bold);

            int i = 3;

            graph.DrawString("Diet Page", font3, XBrushes.BlueViolet, new XPoint(230, 20));
            foreach (Meal meal in meals)
            {
                string name = meal.NameOfMeal;
                graph.DrawString(name, font2, XBrushes.Red, new XPoint(50, i * 20));
                XPen lineRed = new XPen(XColors.Purple, 1);
                graph.DrawLine(lineRed, 0, (i) * 20 + 5, pdfPage.Width, (i) * 20 + 5);
                i++;
                foreach (ProductUsed productUsed in meal.ProductsUsed)
                {
                    graph.DrawString(productUsed.Name + " " + productUsed.Gramms + "gramms", font1, XBrushes.Blue,
                                     new XPoint(100, i * 20));
                    graph.DrawLine(lineRed, 0, (i) * 20 + 5, pdfPage.Width, (i) * 20 + 5);
                    i++;
                }
            }
            graph.DrawString("Total Calories: " + label2.Text, font2, XBrushes.Green, new XPoint(230, (i + 1) * 20));
            string pdfFilename = "Diet.pdf";

            pdf.Save(pdfFilename);
            System.Diagnostics.Process.Start(pdfFilename);
        }
Beispiel #30
0
        /// <summary>
        /// Converts an DOM Font to an XFont.
        /// </summary>
        internal static XFont FontToXFont(Font font, XPrivateFontCollection pfc,
                                          PdfFontEncoding encoding)
        {
            XFont xFont = null;

            // #PFC
            XPdfFontOptions options = null;

            options = new XPdfFontOptions(encoding);
            XFontStyle style = GetXStyle(font);

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