我想使用 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();
}
}
如何使用 UTF-8?