Nim*_*oud 1 c# pdf utf-8 itext itextsharp
我想使用UTF-8而不是CP1250来显示国家字符.我找到了支持UTF-8的AddParagraph方法,但我找不到任何压模示例.
这是CP1250的代码片段:
PdfReader reader = new PdfReader(templatePath);
byte[] bytes;
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
PdfContentByte cb = stamper.GetOverContent(1);
BaseFont bf = BaseFont.CreateFont(
BaseFont.COURIER_BOLD,
BaseFont.CP1250,
true);
//Begin text command
cb.BeginText();
//Set the font information
cb.SetFontAndSize(bf,12f);
//Position the cursor for drawing
cb.MoveText(field.X, field.Y);
//Write some text
cb.ShowText(field.Text);
//End text command
cb.EndText();
//Flush the PdfStamper's buffer
stamper.Close();
//Get the raw bytes of the PDF
bytes = ms.ToArray();
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能使用UTF-8?
如果您需要单个字体的各种字符,则最有可能使用IDENTITY_H(或垂直文本时为IDENTITY_V)作为编码.
例如:
public const string FONT = "c:/windows/fonts/arialbd.ttf";
BaseFont bf = BaseFont.CreateFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Run Code Online (Sandbox Code Playgroud)
参看 的Web化iTextSharp的实施例 UnicodeExample.cs用于上下文中的使用.
| 归档时间: |
|
| 查看次数: |
10086 次 |
| 最近记录: |