粗体显示后将BaseFont参数设置回默认值 [英] Setting BaseFont parameters back to default after bold

查看:140
本文介绍了粗体显示后将BaseFont参数设置回默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用iTextSharp在PDF文档中编写文本时,我使用的是绝对定位.它只能处理BaseFont,并且不能在基本字体上设置 Bold 装饰.

I am using absolute positioning when writing text in a PDF document using iTextSharp. It can only deal with BaseFont and it is not possible to set a Bold decoration on a base font.

我在一篇帖子中读到,这是将字体设置为粗体的方法:

I read in a post that this was the way to set the font to bold:

 pdfContentByte.SetCharacterSpacing(1);
 pdfContentByte.SetRGBColorFill(66, 00, 00);  
 pdfContentByte.SetLineWidth((float)0.5);                   
 pdfContentByte.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);

那行得通,但又产生了另一个问题.我不知道如何将这些参数设置回原来的默认设置(无粗体字体).

That worked but created a another problem. I don't know how to set these parameters back to my old default (none-bolded font).

你知道吗?

TIA 索伦·D.

推荐答案

答案很简单:更改状态之前,您需要保存,然后恢复添加文本后的状态:

the answer is very simple: you need to save the state before you change it, and restore the state after you've added the text:

pdfContentByte.SaveState();
pdfContentByte.SetCharacterSpacing(1);
pdfContentByte.SetRGBColorFill(66, 00, 00);  
pdfContentByte.SetLineWidth((float)0.5);                   
pdfContentByte.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
// add the text using the changed state
pdfContentByte.RestoreState();

您对字符间距,颜色,行宽和渲染模式所做的更改仅在SaveState()RestoreState()序列之间有效.

The changes you make to the character spacing, color, line width and rendering mode will only be valid between the SaveState() and RestoreState() sequence.

这篇关于粗体显示后将BaseFont参数设置回默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆