我正在构建一个使用Bootstrap和iTextSharp的.NET / C#/ MVC系统。
在使用iTextSharp生成PDF文档时,我还想使用两个字形字体图标。
我知道在PDF中包含和图像的唯一方法是为图像指定一个流:
Stream imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Onlineeksamen.Web.Resources.ios7-phone1-icon.png");
Image image = Image.GetInstance(imageStream);
Glyph图标可在以下文件中找到:
fonts\glyphicons-halflings-regular.eot
fonts\glyphicons-halflings-regular.svg
fonts\glyphicons-halflings-regular.ttf
fonts\glyphicons-halflings-regular.woff
我现在根据jme的评论有以下示例,但它不起作用 - 我假设图标是字体中的字符:
outputStream = new MemoryStream();
document = new Document(PageSize.A4, margin, margin, margin, margin);
pdfWriter = PdfWriter.GetInstance(document, outputStream);
document.Open();
pdfContentByte = pdfWriter.DirectContent;
PageHeight = document.PageSize.Height;
pdfContentByte.SetColorStroke(BaseColor.BLACK);
string fontFile = String.Format("{0}fonts\\glyphicons-halflings-regular.ttf", HostingEnvironment.ApplicationPhysicalPath);
BaseFont customfont = BaseFont.CreateFont(fontFile, BaseFont.CP1252, BaseFont.EMBEDDED);
pdfContentByte.SetFontAndSize(customfont, 12);
pdfContentByte.BeginText();
pdfContentByte.SetTextMatrix(100, PageHeight.Value - 100);
pdfContentByte.ShowText("This should be glyphs");
pdfContentByte.EndText();
document.Close();
return outputStream.ToArray();
提前谢谢
Soeren D。