当前位置: 首页>>代码示例>>C#>>正文


C# text.Font类代码示例

本文整理汇总了C#中iTextSharp.text.Font的典型用法代码示例。如果您正苦于以下问题:C# Font类的具体用法?C# Font怎么用?C# Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Font类属于iTextSharp.text命名空间,在下文中一共展示了Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateRow

        private static void GenerateRow(PdfPTable table, PlayerInfo player, Font font, BaseColor backgroundColor)
        {
            var jpg = Image.GetInstance(player.PictureUrl);
            table.AddCell(jpg);

            PdfPCell cell;

            cell = new PdfPCell(new Phrase(player.JerseyNumber, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.Name, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            if (table.NumberOfColumns == NumberColsWithPosition)
            {
                cell = new PdfPCell(new Phrase(player.Position, font)) {BackgroundColor = backgroundColor};
                table.AddCell(cell);
            }

            cell = new PdfPCell(new Phrase(player.Height, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.Weight, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.DateOfBirth, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.Age, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.BirthPlace, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);
        }
开发者ID:ColinStranc,项目名称:MockDraftAnalysis,代码行数:34,代码来源:PdfGenerator.cs

示例2: Write

        public void Write(string outputPath, FlowDocument doc)
        {
            Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
            Font textFont = new Font(baseFont, DEFAULT_FONTSIZE, Font.NORMAL, BaseColor.BLACK);
            Font headingFont = new Font(baseFont, DEFAULT_HEADINGSIZE, Font.BOLD, BaseColor.BLACK);
            using (FileStream stream = new FileStream(outputPath, FileMode.Create))
            {
                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
                pdfDoc.Open();
                foreach (Block i in doc.Blocks) {
                    if (i is System.Windows.Documents.Paragraph)
                    {
                        TextRange range = new TextRange(i.ContentStart, i.ContentEnd);
                        Console.WriteLine(i.Tag);
                        switch (i.Tag as string)
                        {
                            case "Paragraph": iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(range.Text, textFont);
                                par.Alignment = Element.ALIGN_JUSTIFIED;
                                              pdfDoc.Add(par);
                                              break;
                            case "Heading": iTextSharp.text.Paragraph head = new iTextSharp.text.Paragraph(range.Text, headingFont);
                                              head.Alignment = Element.ALIGN_CENTER;
                                              head.SpacingAfter = 10;
                                              pdfDoc.Add(head);
                                              break;
                            default:          iTextSharp.text.Paragraph def = new iTextSharp.text.Paragraph(range.Text, textFont);
                                              def.Alignment = Element.ALIGN_JUSTIFIED;
                                              pdfDoc.Add(def);
                                              break;

                        }
                    }
                    else if (i is System.Windows.Documents.List)
                    {
                        iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.UNORDERED, 10f);
                        list.SetListSymbol("\u2022");
                        list.IndentationLeft = 15f;
                        foreach (var li in (i as System.Windows.Documents.List).ListItems)
                        {
                            iTextSharp.text.ListItem listitem = new iTextSharp.text.ListItem();
                            TextRange range = new TextRange(li.Blocks.ElementAt(0).ContentStart, li.Blocks.ElementAt(0).ContentEnd);
                            string text = range.Text.Substring(1);
                            iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(text, textFont);
                            listitem.SpacingAfter = 10;
                            listitem.Add(par);
                            list.Add(listitem);
                        }
                        pdfDoc.Add(list);
                    }

               }
                if (pdfDoc.PageNumber == 0)
                {
                    iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(" ");
                    par.Alignment = Element.ALIGN_JUSTIFIED;
                    pdfDoc.Add(par);
                }
               pdfDoc.Close();
            }
        }
开发者ID:drdaemos,项目名称:ODTCONVERTvs10,代码行数:60,代码来源:PDFWriter.cs

示例3: BaseFontAndSize

 // 函数描述:设置字体的样式
 public static Font BaseFontAndSize(string fontName, int size, int style, BaseColor baseColor)
 {
     BaseFont.AddToResourceSearch("iTextAsian.dll");
     BaseFont.AddToResourceSearch("iTextAsianCmaps.dll");
     string fileName;
     switch (fontName)
     {
         case "黑体":
             fileName = "SIMHEI.TTF";
             break;
         case "华文中宋":
             fileName = "STZHONGS.TTF";
             break;
         case "宋体":
             fileName = "simsun_1.ttf";
             break;
         default:
             fileName = "simsun_1.ttf";
             break;
     }
     var baseFont = BaseFont.CreateFont(@"c:/windows/fonts/" + fileName, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
     var fontStyle = style < -1 ? Font.NORMAL : style;
     var font = new Font(baseFont, size, fontStyle, baseColor);
     return font;
 }
开发者ID:GankerChen2012,项目名称:PdfTools,代码行数:26,代码来源:ExamAnalysiseReportFormat.cs

示例4: ManipulatePdf

// ---------------------------------------------------------------------------    
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
    // Create a table with named actions
      Font symbol = new Font(Font.FontFamily.SYMBOL, 20);
      PdfPTable table = new PdfPTable(4);
      table.DefaultCell.Border = Rectangle.NO_BORDER;
      table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
      Chunk first = new Chunk( ((char)220).ToString() , symbol);
      first.SetAction(new PdfAction(PdfAction.FIRSTPAGE));
      table.AddCell(new Phrase(first));
      Chunk previous = new Chunk( ((char)172).ToString(), symbol);
      previous.SetAction(new PdfAction(PdfAction.PREVPAGE));
      table.AddCell(new Phrase(previous));
      Chunk next = new Chunk( ((char)174).ToString(), symbol);
      next.SetAction(new PdfAction(PdfAction.NEXTPAGE));
      table.AddCell(new Phrase(next));
      Chunk last = new Chunk( ((char)222).ToString(), symbol);
      last.SetAction(new PdfAction(PdfAction.LASTPAGE));
      table.AddCell(new Phrase(last));
      table.TotalWidth = 120;
      
      // Create a reader
      PdfReader reader = new PdfReader(src);
      using (MemoryStream ms = new MemoryStream()) {
        // Create a stamper
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          // Add the table to each page
          PdfContentByte canvas;
          for (int i = 0; i < reader.NumberOfPages; ) {
            canvas = stamper.GetOverContent(++i);
            table.WriteSelectedRows(0, -1, 696, 36, canvas);
          }
        }
        return ms.ToArray();
      }    
    }    
开发者ID:,项目名称:,代码行数:40,代码来源:

示例5: Write

 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         BaseFont bf;
         Font font;
         for (int i = 0; i < 3; i++)
         {
             bf = BaseFont.CreateFont(
               MOVIES[i][0], MOVIES[i][1], BaseFont.NOT_EMBEDDED
             );
             font = new Font(bf, 12);
             document.Add(new Paragraph(bf.PostscriptFontName, font));
             for (int j = 2; j < 5; j++)
             {
                 document.Add(new Paragraph(MOVIES[i][j], font));
             }
             document.Add(Chunk.NEWLINE);
         }
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:28,代码来源:CJKExample.cs

示例6: PopulateDocument

        protected override void PopulateDocument()
        {
            var bfCourier = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, false);
            var courier = new Font(bfCourier, 12, Font.ITALIC, BaseColor.RED);

            Document.Add(new Paragraph(string.Format("It did. {0}", DateTime.Now), courier));
        }
开发者ID:ColinStranc,项目名称:MockDraftAnalysis,代码行数:7,代码来源:PdfSample5.cs

示例7: NamedFont

 NamedFont(string name, Font font)
 {
     if (name =="" || font == null)
         throw new InvalidParameterException();
     Font = font;
     _name = name;
 }
开发者ID:Jazzuell,项目名称:parser,代码行数:7,代码来源:NamedFont.cs

示例8: Go

        public void Go()
        {
            // GetClassOutputPath() implementation left out for brevity
            var outputFile = Helpers.IO.GetClassOutputPath(this);

            using (FileStream stream = new FileStream(
                outputFile, 
                FileMode.Create, 
                FileAccess.Write))
            {
                Random random = new Random();

                StreamUtil.AddToResourceSearch(("iTextAsian.dll"));
                string chunkText = " 你好世界 你好你好,";
                var font = new Font(BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12);

                using (Document document = new Document())
                {
                    PdfWriter.GetInstance(document, stream);
                    document.Open();
                    Phrase phrase = new Phrase();
                    Chunk chunk = new Chunk("", font);
                    for (var i = 0; i < 1000; ++i)
                    {
                        var asterisk = new String('*', random.Next(1, 20));
                        chunk.Append(
                            string.Format("[{0}] {1} ", asterisk, chunkText) 
                        );
                    }
                    chunk.SetSplitCharacter(new CustomSplitCharacter());
                    phrase.Add(chunk);
                    document.Add(phrase);
                }
            }
        }
开发者ID:kuujinbo,项目名称:StackOverflow.iTextSharp,代码行数:35,代码来源:ChineseSetSplitCharacter.cs

示例9: OnEndPage

        //重写 关闭一个页面时
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            try
            {
                Font font = new Font(basefont, defaultFontSize);
                Phrase head = new Phrase(header, font);
                PdfContentByte cb = writer.DirectContent;
               
                //页眉显示的位置
                ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, head,
                        document.Right - 10 + document.LeftMargin, document.Top + 10, 0);
                if (PAGE_NUMBER)
                {
                    Phrase footer = new Phrase("第 " + writer.PageNumber + " / " + "   "+" 頁", font);
                    cb = writer.DirectContent;
                    //tpl = cb.CreateTemplate(100, 100);
                    //模版 显示总共页数
                    cb.AddTemplate(tpl, document.Left / 2 + document.Right / 2 , document.Bottom - 10);//调节模版显示的位置
                    //页脚显示的位置
                    ColumnText.ShowTextAligned(cb, Element.ALIGN_RIGHT, footer,
                            document.Left / 2+document.Right/ 2+23, document.Bottom - 10, 0);
                    

                }
            }
            catch (Exception ex)
            {
                throw new Exception("HeaderAndFooterEvent-->OnEndPage-->" + ex.Message);
            }
        }
开发者ID:lxh2014,项目名称:gigade-net,代码行数:31,代码来源:HeaderAndFooterEvent.cs

示例10: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "*.pdf|*.PDF";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var doc = new Document();
                BaseFont baseFont = BaseFont.CreateFont(@"TIMES.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                iTextSharp.text.Font zag = new iTextSharp.text.Font(baseFont, 16, iTextSharp.text.Font.BOLD);
                iTextSharp.text.Font curs = new iTextSharp.text.Font(baseFont, 14, iTextSharp.text.Font.ITALIC);
                iTextSharp.text.Font other_text = new iTextSharp.text.Font(baseFont, 12, iTextSharp.text.Font.BOLD);
                iTextSharp.text.Font othtext = new iTextSharp.text.Font(baseFont, 12, iTextSharp.text.Font.NORMAL);
                PdfWriter.GetInstance(doc, new FileStream(@saveFileDialog1.FileName, FileMode.Create));
                doc.Open();

                Paragraph par = new Paragraph("Акт закупок", zag);
                par.Alignment = Element.ALIGN_CENTER;
                Paragraph variant = new Paragraph("Аптека № 10", curs);
                variant.Alignment = Element.ALIGN_RIGHT;
                Paragraph otstup = new Paragraph("\r\n");
                doc.Add(par);

                doc.Add(otstup);
                PdfPTable table = new PdfPTable(5);

                PdfPCell cell1 = new PdfPCell(new Phrase("№", other_text));
                PdfPCell cell2 = new PdfPCell(new Phrase("Препарат", other_text));
                PdfPCell cell3 = new PdfPCell(new Phrase("Поставщик", other_text));
                PdfPCell cell4 = new PdfPCell(new Phrase("Количество", other_text));
                PdfPCell cell5 = new PdfPCell(new Phrase("Сумма", other_text));

                table.AddCell(cell1);
                table.AddCell(cell2);
                table.AddCell(cell3);
                table.AddCell(cell4);
                table.AddCell(cell5);

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; j++)
                    {
                        if (dataGridView1.Rows[i].Cells[j].Value != null)
                        {
                            string tempS = dataGridView1.Rows[i].Cells[j].Value.ToString();

                            cell1 = new PdfPCell(new Phrase(tempS, othtext));
                            table.AddCell(cell1);
                        }
                    }
                }

                doc.Add(table);
                doc.Add(variant);
                doc.Close();

                MessageBox.Show("ok");

            }
        }
开发者ID:Geliya94,项目名称:oop,代码行数:60,代码来源:Zakaz.cs

示例11: MovieHistory

 static MovieHistory()
 {
     FONT[0] = new Font(Font.FontFamily.HELVETICA, 24);
     FONT[1] = new Font(Font.FontFamily.HELVETICA, 18);
     FONT[2] = new Font(Font.FontFamily.HELVETICA, 14);
     FONT[3] = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:7,代码来源:MovieHistory.cs

示例12: TestNotoFont

        public void TestNotoFont()
        {
            Document document = new Document();

            PdfAWriter writer = PdfAWriter.GetInstance(document, new MemoryStream(), PdfAConformanceLevel.PDF_A_1B);
            writer.CreateXmpMetadata();

            document.Open();
            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();
            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            String fontPath = RESOURCES + "NotoSansCJKjp-Bold.otf";
            BaseFont bf = BaseFont.CreateFont(fontPath, "Identity-H", true);
            Font font = new Font(bf, 14);
            String[] lines = new String[] {"Noto test", "in japanese:", "\u713C"};

            foreach (String line in lines)
            {
                document.Add(new Paragraph(line, font));
            }

            document.Close();
        }
开发者ID:newlysoft,项目名称:itextsharp,代码行数:25,代码来源:PdfAFontEmbeddingTest.cs

示例13: Write

// ===========================================================================
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter.GetInstance(document, stream).InitialLeading = 16;
        // step 3
        document.Open();
        // add the ID in another font
        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, BaseColor.WHITE);
        // step 4
        using (var c =  AdoDB.Provider.CreateConnection()) {
          c.ConnectionString = AdoDB.CS;
          using (DbCommand cmd = c.CreateCommand()) {
            cmd.CommandText = 
              "SELECT country,id FROM film_country ORDER BY country";
            c.Open();
            using (var r = cmd.ExecuteReader()) {
              while (r.Read()) {
                var country = r.GetString(0);
                var ID = r.GetString(1);
                document.Add(new Chunk(country));
                document.Add(new Chunk(" "));
                Chunk id = new Chunk(ID, font);
                // with a background color
                id.SetBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                // and a text rise
                id.SetTextRise(6);
                document.Add(id);
                document.Add(Chunk.NEWLINE);
              }
            }
          }
        }
      }
    }
开发者ID:,项目名称:,代码行数:36,代码来源:

示例14: AddText

        /// <summary>
        /// <para>座標を指定してテキストを追加します。</para>
        /// <para>PDF では用紙左上が座標基準 (0, 0) である点に注意してください。</para>
        /// </summary>
        /// <param name="text">追加するテキスト</param>
        /// <param name="fontSize">フォントサイズ</param>
        /// <param name="x">X 座標</param>
        /// <param name="y">Y座標</param>
        public void AddText(string text, int fontSize, int x, int y)
        {
            // 左下の座標
            float llx = x;
            float lly = 0f;

            // 右上の座標
            float urx = this.Page.Width;
            float ury = y;

            var pcb = this.Writer.DirectContent;
            var ct = new ColumnText(pcb);
            var font = new Font(this.BaseFont, fontSize, Font.NORMAL);

            var phrase = new Phrase(text, font);

            ct.SetSimpleColumn(
                phrase,
                llx,
                lly,
                urx,
                ury,
                0,
                Element.ALIGN_LEFT | Element.ALIGN_TOP
                );

            // 以下を実行して反映する (消さないこと)
            ct.Go();
        }
开发者ID:pine,项目名称:KutDormitoryReport,代码行数:37,代码来源:PdfReport.cs

示例15: PdfArchiver

 static PdfArchiver()
 {
     BaseFont.AddToResourceSearch("iTextAsian.dll");
     _font = new Font(
        BaseFont.CreateFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED)
        , 16);
 }
开发者ID:karino2,项目名称:wikipediaconv,代码行数:7,代码来源:PdfArchiver.cs


注:本文中的iTextSharp.text.Font类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。