本篇文章将介绍如何使用Spire.PDF在PDF文档中绘制上标和下标文本。
【下载Spire.PDF最新试用版】
本篇文章将介绍如何使用Spire.PDF在PDF文档中绘制上标和下标文本。
绘制上标
//创建PdfDocument实例PdfDocument pdf = new PdfDocument();//添加一个页面PdfPageBase page = pdf.Pages.Add();//设置x,y坐标初始值float x = 0;float y = 50;//设置字体PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 11f), true);//绘制文本string text = "示例文本";page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x,y));//计算文本的尺寸SizeF size = font.MeasureString(text);//设置上标的X坐标x += size.Width;//创建PdfStringFormat实例PdfStringFormat format = new PdfStringFormat();//设置格式为上标format.SubSuperScript = PdfSubSuperScript.SuperScript;//绘制上标text = "上标";page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x,y), format);//保存文档pdf.SaveToFile("SuperScript.pdf");

绘制下标
//创建PdfDocument实例PdfDocument pdf = new PdfDocument();//添加一个页面PdfPageBase page = pdf.Pages.Add();//设置x,y坐标初始值float x = 0;float y = 50;//设置字体PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 11f), true);//绘制文本string text = "示例文本";page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x, y));//计算文本的尺寸SizeF size = font.MeasureString(text);//设置下标的X坐标x += size.Width;//创建PdfStringFormat实例PdfStringFormat format = new PdfStringFormat();//设置格式为下标format.SubSuperScript = PdfSubSuperScript.SubScript;//绘制下标text = "下标";page.Canvas.DrawString(text, font, PdfBrushes.Black, new PointF(x, y), format);//保存文档pdf.SaveToFile("SubScript.pdf");

想要购买正版授权,或者获取更多Spire.PDF相关信息的朋友可以点击” 咨询在线客服 “~
标签:文档管理PDFOffice文档处理
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!