本文整理汇总了C#中PdfSharp.Drawing.XFont类的典型用法代码示例。如果您正苦于以下问题:C# XFont类的具体用法?C# XFont怎么用?C# XFont使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XFont类属于PdfSharp.Drawing命名空间,在下文中一共展示了XFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create an empty page
PdfPage page = document.AddPage();
//page.Contents.CreateSingleContent().Stream.UnfilteredValue;
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
// Create a font
XFont font = new XFont("Arial", 20, XFontStyle.Bold, options);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
// Save the document...
string filename = "HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
示例2: PdfTrueTypeFont
/// <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)FontDescriptorCache.GetOrCreateDescriptorFor(font);
FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
_fontOptions = font.PdfOptions;
Debug.Assert(_fontOptions != null);
//cmapInfo = new CMapInfo(null/*ttDescriptor*/);
_cmapInfo = new CMapInfo(ttDescriptor);
BaseFont = font.GlyphTypeface.GetBaseName();
if (_fontOptions.FontEmbedding == PdfFontEmbedding.Always)
BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);
FontDescriptor.FontName = BaseFont;
Debug.Assert(_fontOptions.FontEncoding == PdfFontEncoding.WinAnsi);
if (!IsSymbolFont)
Encoding = "/WinAnsiEncoding";
Owner._irefTable.Add(FontDescriptor);
Elements[Keys.FontDescriptor] = FontDescriptor.Reference;
FontEncoding = font.PdfOptions.FontEncoding;
}
示例3: RenderPage
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
}
示例4: PdfType0Font
public PdfType0Font(PdfDocument document, XFont font, 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)FontDescriptorCache.GetOrCreateDescriptorFor(font);
FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
_fontOptions = font.PdfOptions;
Debug.Assert(_fontOptions != null);
_cmapInfo = new CMapInfo(ttDescriptor);
_descendantFont = new PdfCIDFont(document, FontDescriptor, font);
_descendantFont.CMapInfo = _cmapInfo;
// Create ToUnicode map
_toUnicode = new PdfToUnicodeMap(document, _cmapInfo);
document.Internals.AddObject(_toUnicode);
Elements.Add(Keys.ToUnicode, _toUnicode);
BaseFont = font.GlyphTypeface.GetBaseName();
// CID fonts are always embedded
BaseFont = PdfFont.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;
}
示例5: BarCodeRenderInfo
public BarCodeRenderInfo(XGraphics gfx, XBrush brush, XFont font, XPoint position)
{
Gfx = gfx;
Brush = brush;
Font = font;
Position = position;
}
示例6: TableCell
public TableCell(string text, XFont font, int columnSpan, HorizontalAlignment alignment)
{
Text = text;
Font = font;
Alignment = alignment;
ColumnSpan = columnSpan;
}
示例7: RenderMeasureText
void RenderMeasureText(XGraphics gfx)
{
gfx.TranslateTransform(15, 20);
XFontStyle style = XFontStyle.Regular;
XFont font = new XFont("Times New Roman", 95, style);
string text = "Hello";
double x = 20, y = 100;
XSize size = gfx.MeasureString(text, font);
double lineSpace = font.GetHeight(gfx);
int cellSpace = font.FontFamily.GetLineSpacing(style);
int cellAscent = font.FontFamily.GetCellAscent(style);
int cellDescent = font.FontFamily.GetCellDescent(style);
int cellLeading = cellSpace - cellAscent - cellDescent;
// Get effective ascent
double ascent = lineSpace * cellAscent / cellSpace;
gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent);
// Get effective descent
double descent = lineSpace * cellDescent / cellSpace;
gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent);
// Get effective leading
double leading = lineSpace * cellLeading / cellSpace;
gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading);
// Draw text half transparent
XColor color = XColors.DarkSlateBlue;
color.A = 0.6;
gfx.DrawString(text, font, new XSolidBrush(color), x, y);
}
示例8: HelloWord
public void HelloWord()
{
document.Info.Title = "Created with 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);
// Create a font
XFont font = new XFont("Times New Roman", 20, XFontStyle.BoldItalic);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
// Save the document...
const string filename = "HelloWorld_tempfile.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
示例9: Export_to_Pdf
public Export_to_Pdf()
{
InitializeComponent();
//Create object for pdf.
document = new PdfDocument();
page = document.AddPage();
gfx = XGraphics.FromPdfPage(page);
//Set by default values.
font = new XFont("Arial", 12, XFontStyle.Regular);
header_font = new XFont("Arial", 12, XFontStyle.Regular);
page.Size = PageSize.A4;
page.Orientation = PageOrientation.Portrait;
//////////////////////////////////////////////////////////////////////
//Create a fake questionanire to test the print process to pdf.
if (questionaire != null)
{
List<Question> question_list = new List<Question>();
List<Answer> answer_list = new List<Answer>();
Answer ans = new Answer();
ans.Answer_descr = "einai to dsfgdsfgsd";
answer_list.Add(ans);
answer_list.Add(ans);
answer_list.Add(ans);
Question quest = new Question() { AnswerList = answer_list };
quest.Question_descr = "H ekfoonisi tis erotisis aytis einai blablbalbablbalblab";
for (int i = 0; i < 10; i++)
{
question_list.Add(quest);
}
questionaire = new Quastionnaire.Model.Questionaire() { Questionaire_descr = "sdfsakdfjdflshsadflkjashflasdfkh", QuestionList = question_list };
}
//////////////////////////////////////////////////////////////////////
}
示例10: RenderPage
public override void RenderPage(XGraphics gfx)
{
//base.RenderPage(gfx);
XFont font1 = new XFont("Times New Roman", 12);
XFont font2 = new XFont("Courier New", 10, XFontStyle.Bold);
gfx.WriteComment("Word 11");
gfx.DrawString("Word 11", font1, XBrushes.Black, new XPoint(50, 100));
gfx.WriteComment("Word 12");
gfx.DrawString("Word 12", font1, XBrushes.Black, new XPoint(100, 100));
gfx.WriteComment("Word 21");
gfx.DrawString("Word 21", font2, XBrushes.Black, new XPoint(50, 200));
gfx.WriteComment("Word 22");
gfx.DrawString("Word 22", font2, XBrushes.Black, new XPoint(100, 200));
gfx.WriteComment("Word 23");
gfx.DrawString("Word 22", font2, XBrushes.Red, new XPoint(150, 200));
gfx.WriteComment("Word 24");
gfx.DrawString("Word 24", font2, XBrushes.Red, new XPoint(200, 200));
}
示例11: RenderPage
public override void RenderPage(XGraphics gfx)
{
//base.RenderPage(gfx);
XFont font1 = new XFont("Arial", 9);
XFont font2 = new XFont("Arial", 9, XFontStyle.Italic);
XFont font3 = new XFont("Arial", 9, XFontStyle.Bold);
XSolidBrush brush = new XSolidBrush(XColors.Black);
gfx.DrawString("Page 5", font1, brush, 100, 100);
gfx.DrawString("Water Sports You've Done continued", font2, brush, 100, 200);
gfx.DrawString("Rowing", font1, brush, 100, 250);
gfx.DrawString("Snorkeling", font1, brush, 100, 300);
gfx.DrawString("WINTER SPORTS, SKIING, SKIING IN THE US", font3, XBrushes.Red, 100, 320);
gfx.DrawLine(XPens.Red, 100, 100, 200, 200);
gfx.DrawString("Resorts You've Skied in Vermont", font3, brush, 100, 400);
gfx.DrawString("Haystack", font1, brush, 100, 420);
// string text = "TgfÄÖÜWi9";
// if (this.properties.Font1.Text != "")
// text = this.properties.Font1.Text;
// float x = 100, y = 300;
// string familyName = properties.Font1.FamilyName;
// XFontStyle style = this.properties.Font1.Style;
// float emSize = this.properties.Font1.Size;
// XFont font = CreateFont(familyName, emSize, style);
// font = this.properties.Font1.Font;
// XSize size = gfx.MeasureString(text, font);
// double lineSpace = font.GetHeight(gfx);
// int cellSpace = font.FontFamily.GetLineSpacing(style);
// int cellAscent = font.FontFamily.GetCellAscent(style);
// int cellDescent = font.FontFamily.GetCellDescent(style);
// int cellLeading = cellSpace - cellAscent - cellDescent;
// double ascent = lineSpace * cellAscent / cellSpace;
// gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent);
// double descent = lineSpace * cellDescent / cellSpace;
// gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent);
// double leading = lineSpace * cellLeading / cellSpace;
// gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading);
// //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height);
// //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y);
// //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200);
//#if true_
// XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true);
// font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions);
// text = "Hallo";
// text = chinese;
//#endif
// gfx.DrawString(text, font, this.properties.Font1.Brush, x, y);
// gfx.DrawLine(XPens.Red, 0, 0, 100, 100);
// gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20);
}
示例12: GetCookBook
public Uri GetCookBook(string name)
{
var document = new PdfDocument();
document.Info.Title = name + "'s personalized cookbook";
document.Info.Author = "Pancake Prowler";
var page = document.AddPage();
var graphics = XGraphics.FromPdfPage(page);
var font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
graphics.DrawString(name + "'s personalized cookbook",
font,
XBrushes.Red,
new System.Drawing.PointF((float)page.Width / 2, (float)page.Height / 2),
XStringFormats.Center);
var saveStream = new MemoryStream();
document.Save(saveStream);
var memoryStream = new MemoryStream(saveStream.ToArray());
memoryStream.Seek(0, SeekOrigin.Begin);
var imageStore = new BlobImageRepository();
return imageStore.Save("application/pdf", memoryStream, "cookbooks");
}
示例13: InitializeFonts
public void InitializeFonts(string font)
{
//Regular
Font8 = new XFont(font, 8, XFontStyle.Regular);
Font10 = new XFont(font, 10, XFontStyle.Regular);
Font12 = new XFont(font, 12, XFontStyle.Regular);
Font14 = new XFont(font, 14, XFontStyle.Regular);
Font16 = new XFont(font, 16, XFontStyle.Regular);
Font18 = new XFont(font, 18, XFontStyle.Regular);
//Bold
Font8Bold = new XFont(font, 8, XFontStyle.Bold);
Font10Bold = new XFont(font, 10, XFontStyle.Bold);
Font12Bold = new XFont(font, 12, XFontStyle.Bold);
Font14Bold = new XFont(font, 14, XFontStyle.Bold);
Font16Bold = new XFont(font, 16, XFontStyle.Bold);
Font18Bold = new XFont(font, 18, XFontStyle.Bold);
//Italic
Font8Italic = new XFont(font, 8, XFontStyle.Italic);
Font10Italic = new XFont(font, 10, XFontStyle.Italic);
Font12Italic = new XFont(font, 12, XFontStyle.Italic);
Font14Italic = new XFont(font, 14, XFontStyle.Italic);
Font16Italic = new XFont(font, 16, XFontStyle.Italic);
Font18Italic = new XFont(font, 18, XFontStyle.Italic);
}
示例14: GetDescent
internal static XUnit GetDescent(XFont font)
{
XUnit descent = font.Metrics.Descent;
descent *= font.Size;
descent /= font.FontFamily.GetEmHeight(font.Style);
return descent;
}
示例15: CreatePdfPage
private static void CreatePdfPage(List<JiraTicket> issues, ref PdfDocument pdf)
{
PdfPage page = pdf.AddPage();
page.Size = PdfSharp.PageSize.A4;
page.Orientation = PdfSharp.PageOrientation.Landscape;
for (int j = 0; j < issues.Count; j++)
{
string text = issues[j].fields.issuetype.name + System.Environment.NewLine + issues[j].key
+ System.Environment.NewLine + issues[j].fields.summary + System.Environment.NewLine
+ issues[j].fields.customfield_10008;
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
XTextFormatter tf = new XTextFormatter(gfx);
XRect rect = new XRect();
if (j < 3)
{
rect = new XRect(15, 15 + j * 180, 400, 170);
}
else
{
rect = new XRect(430, 15 + (j - 3) * 180, 400, 170);
}
gfx.DrawRectangle(XBrushes.SeaShell, rect);
tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
gfx.Dispose();
}
}