Hi all,
I am trying to create a PDF where I need to insert a tagged table. I want to write the table directly manipulating the content, and then associate the tags using BDC. I can do everything, but I don’t understand why, in the end, it adds a blank page containing only the table marker (/Table << /MCID 15 >> BDC EMC).
Below my code :
var document = new Document();
ITaggedContent content = document.TaggedContent;
StructTreeRootElement structTreeRootElement = content.StructTreeRootElement;
StructureElement rootElement = content.RootElement;
rootElement.ClearChilds();
Page p = document.Pages.Insert(1);
p.SetPageSize(595.276, 841.8898);
BDC bdcTable = new BDC(“Table”, new BDCProperties(“en”));
BDC bdcTR1 = new BDC(“TR”, new BDCProperties(“en”));
BDC bdcTH1 = new BDC(“TH”, new BDCProperties(3, “en”));
BDC bdcTH2 = new BDC(“TH”, new BDCProperties(4, “en”));
BDC bdcTR2 = new BDC(“TR”, new BDCProperties(“en”));
BDC bdcTD1 = new BDC(“TD”, new BDCProperties(6, “en”));
BDC bdcTD2 = new BDC(“TD”, new BDCProperties(7, “en”));
BDC bdcPar1 = new BDC(“P”, new BDCProperties(8, “en”));
string insidefontName = “”;
var fonts = p.Resources.GetFonts(true);
if (fonts.Count == 0)
fonts.Add(FontRepository.FindFont(“ArialMT”), out insidefontName);
p.Contents.Add(new Aspose.Pdf.Operators.GSave());
p.Contents.Add(new Aspose.Pdf.Operators.BT());
p.Contents.Add(bdcTable);
p.Contents.Add(bdcTR1);
p.Contents.Add(bdcTH1);
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(bdcTH2);
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(bdcTR2);
p.Contents.Add(bdcTD1);
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(bdcTD2);
p.Contents.Add(bdcPar1);
p.Contents.Add(new Aspose.Pdf.Operators.SetRGBColor(0, 0, 0));
p.Contents.Add(new Aspose.Pdf.Operators.SelectFont(insidefontName, 12));
p.Contents.Add(new Aspose.Pdf.Operators.SetTextMatrix(1, 0, 0, 1, 50, 750));
p.Contents.Add(new Aspose.Pdf.Operators.ShowText(“hello hello”, fonts[1]));
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(new Aspose.Pdf.Operators.EMC());
p.Contents.Add(new Aspose.Pdf.Operators.ET());
p.Contents.Add(new Aspose.Pdf.Operators.GRestore());
TableElement table = content.CreateTableElement();
rootElement.AppendChild(table);
TableTHeadElement thead = table.CreateTHead();
var tbody = table.CreateTBody();
TableTRElement row1 = thead.CreateTR();
TableTHElement cellH1 = row1.CreateTH();
cellH1.Tag(bdcTH1);
TableTHElement cellH2 = row1.CreateTH();
cellH2.Tag(bdcTH2);
TableTRElement row2 = tbody.CreateTR();
TableTDElement cellD1 = row2.CreateTD();
cellD1.Tag(bdcTD1);
TableTDElement cellD2 = row2.CreateTD();
var par1 = content.CreateParagraphElement();
cellD2.AppendChild(par1);
par1.Tag(bdcPar1);
document.Save(output);
The result is a two-page PDF, where the first page contains the tagged logical table with only one paragraph in the last cell, and the second page is empty, containing only the table marker
Why is the second page created?