这几天在做套打的方案,最终决定用PDF做。用Acrobat做PDF表单文件,再使用itextsharp填表功能完成。
但是出现多语言(中日韩)填表的情况,查了很多方法,做了不少测试,最后解决。示例代码如下:
var reader =
new PdfReader(
/*
Form File
*/);
var stamper = new PdfStamper(reader, new FileStream(result, FileMode.Create));
var query = from property in type.GetProperties()
join field in stamper.AcroFields.Fields
on property.Name equals field.Key
select new
{
field.Key,
Value = property.GetValue(model, null) as string
};
BaseFont font = BaseFont.CreateFont( " c:\\windows\\fonts\\ARIALUNI.TTF ", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
foreach ( var item in query)
{
stamper.AcroFields.AddSubstitutionFont(font);
stamper.AcroFields.SetField(item.Key, item.Value);
}
stamper.FormFlattening = true;
var stamper = new PdfStamper(reader, new FileStream(result, FileMode.Create));
var query = from property in type.GetProperties()
join field in stamper.AcroFields.Fields
on property.Name equals field.Key
select new
{
field.Key,
Value = property.GetValue(model, null) as string
};
BaseFont font = BaseFont.CreateFont( " c:\\windows\\fonts\\ARIALUNI.TTF ", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
foreach ( var item in query)
{
stamper.AcroFields.AddSubstitutionFont(font);
stamper.AcroFields.SetField(item.Key, item.Value);
}
stamper.FormFlattening = true;
stamper.Close();