public override void Write(PdfWriter writer, Document doc) { PdfDestination destination = new PdfDestination(PdfDestination.XYZ, 20, writer.GetVerticalPosition(false), 0); IDictionary <String, Object> memory = context.GetMemory(); HeaderNode tree = null; if (memory.ContainsKey(HtmlPipelineContext.BOOKMARK_TREE)) { tree = (HeaderNode)memory[HtmlPipelineContext.BOOKMARK_TREE]; } int level = header.GetLevel(tag); if (null == tree) { // first h tag encounter tree = new HeaderNode(0, writer.RootOutline, null); } else { // calculate parent int lastLevel = tree.Level; if (lastLevel == level) { tree = tree.Parent; } else if (lastLevel > level) { while (lastLevel >= level) { lastLevel = tree.Parent.Level; tree = tree.Parent; } } } if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.ADD_HEADER), title.ToString())); } HeaderNode node = new HeaderNode(level, new PdfOutline(tree.Outline, destination, title), tree); memory[HtmlPipelineContext.BOOKMARK_TREE] = node; }
public override void Write(PdfWriter writer, Document doc) { PdfDestination destination = new PdfDestination(PdfDestination.XYZ, 20, writer.GetVerticalPosition(false), 0); IDictionary<String, Object> memory = context.GetMemory(); HeaderNode tree = null; if (memory.ContainsKey(HtmlPipelineContext.BOOKMARK_TREE)) tree = (HeaderNode)memory[HtmlPipelineContext.BOOKMARK_TREE]; int level = header.GetLevel(tag); if (null == tree) { // first h tag encounter tree = new HeaderNode(0, writer.RootOutline, null); } else { // calculate parent int lastLevel = tree.Level; if (lastLevel == level) { tree = tree.Parent; } else if (lastLevel > level) { while (lastLevel >= level) { lastLevel = tree.Parent.Level; tree = tree.Parent; } } } if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.ADD_HEADER), title.ToString())); } HeaderNode node = new HeaderNode(level, new PdfOutline(tree.Outline, destination, title), tree); memory[HtmlPipelineContext.BOOKMARK_TREE] = node; }
/** * Constructor. * @param level the level * @param outline the PdfOutline for this HeaderNode * @param parent the parent HeaderNode * */ public HeaderNode(int level, PdfOutline outline, HeaderNode parent) { this.level = level; this.outline = outline; this.parent = parent; }