生成重用PdfTemplate的标记pdf时,会出现以下异常:
带有标记内容的模板不能多次使用。
标记的pdf中是否无法生成可重复使用的内容,或者这仅仅是iText的限制?
void Main()
{
using (var ms = new MemoryStream())
{
var doc = new Document(PageSize.LETTER, 72, 72, 72, 72);
var writer = PdfWriter.GetInstance(doc, ms);
writer.SetTagged();
doc.Open();
var canvas = writer.DirectContent;
PdfTemplate t = canvas.CreateTemplate(6, 6);
var disc = Image.GetInstance(t);
var ol = new iTextSharp.text.List(false);
var li = new iTextSharp.text.ListItem("List Item 1");
var symbol = new Chunk(disc, 0, 0);
li.ListSymbol = symbol;
ol.Add(li);
li = new iTextSharp.text.ListItem("List Item 2");
symbol = new Chunk(disc, 0, 0);
li.ListSymbol = symbol;
ol.Add(li);
doc.Add(ol);
doc.Close();
ms.Flush();
File.WriteAllBytes("d:\\list.pdf", ms.ToArray());
}
}