简体   繁体   English

如何将System.Drawing.Font转换为Itextsharp Basefont

[英]How to convert System.Drawing.Font into Itextsharp Basefont

I want to get the font of a textbox into itextsharp basefont in winform c#. 我想在winform c#中将文本框的字体放入itextsharp basefont中。 I also want to align the text in a PDF according to alignment of the textbox in winform. 我也想根据winform中文本框的对齐方式来对齐PDF中的文本。

Use FontFactory.RegisterDirectories() to read your fonts. 使用FontFactory.RegisterDirectories()读取字体。 Get the font name from System.Drawing.Font and call FontFactory.GetFont() with that name. System.Drawing.Font获取字体名称,然后使用该名称调用FontFactory.GetFont()

You can use iTextSharp.text.Font instead as the following: 您可以使用iTextSharp.text.Font代替,如下所示:

Font font = FontFactory.GetFont("Segoe UI", 18.0f, BaseColor.Black);

if you have System.Drawing.Font use the following: 如果您具有System.Drawing.Font使用以下命令:

System.Drawing.Font systemDrawingFont = new System.Drawing.Font("Segoe UI", 12);
Font font = FontFactory.GetFont(systemDrawingFont.Name, systemDrawingFont.Size, BaseColor.Black);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM