在PDF文档的使用过程中,很多时候文档里有些公式或者特殊符号带有上标和下标,那么怎么在PDF文档中添加这类文本呢?
PDFOne .NET可以很好地帮助开发人员解决该问题,使用该产品开发人员可以进行PDF文件的创建、编辑、浏览、打印、加密、数字签名、合并分割以及添加书签、注释、水印等,下面的代码讲述了如何在PDF文档中添加使用带上标和下标的文本,具体如下:
// Create a font instance
PDFFont fntConsolas = new PDFFont("Courier New", FontStyle.Underline, 15);
// Create a text formatter instance
PDFTextFormatter tf = new PDFTextFormatter();
// Create a new document and add a page to it
PDFDocument doc = new PDFDocument(PDFOne_License.KEY);
PDFPage pg = new PDFPage(System.Drawing.Printing.PaperKind.A4, 1, 1, 1, 1);
doc.AddPage(pg);
// Write text in regular style
tf.TextRise = 0f;
doc.WriteText("Dettol® = C8H9ClO or Dettol", fntConsolas, tf);
// Write superscript text
tf.TextRise = 4f;
doc.WriteText("®", fntConsolas, tf);
tf.TextRise = 0f;
doc.WriteText(" = C", fntConsolas, tf);
// Write subscript textxt
tf.TextRise = -3f;
doc.WriteText("8", fntConsolas, tf);
// reset
tf.TextRise = 0;
doc.WriteText("H", fntConsolas, tf);
// subscript again
tf.TextRise = -3f;
doc.WriteText("9", fntConsolas, tf);
// res... all right, you get the idea!
tf.TextRise = 0;
doc.WriteText("ClO", fntConsolas, tf);
doc.Save(@"test.pdf");
doc.Close();