/// <summary>Converts the current tag structure into an XML file with provided encoding.</summary> /// <param name="os">the output stream to save XML file to</param> /// <param name="charset">the charset of the resultant XML file</param> public virtual void ConvertToXml(Stream os, String charset) { @out = new StreamWriter(os, EncodingUtil.GetEncoding(charset)); if (rootTag != null) { @out.Write("<" + rootTag + ">" + Environment.NewLine); } // get the StructTreeRoot from the document PdfStructTreeRoot structTreeRoot = document.GetStructTreeRoot(); if (structTreeRoot == null) { throw new PdfException(PdfException.DocumentDoesntContainStructTreeRoot); } // Inspect the child or children of the StructTreeRoot InspectKids(structTreeRoot.GetKids()); if (rootTag != null) { @out.Write("</" + rootTag + ">"); } @out.Flush(); @out.Dispose(); }
public virtual void SeveralSameElementsInStructTreeRootTest() { String inFile = sourceFolder + "severalSameElementsInStructTreeRoot.pdf"; PdfDocument doc = new PdfDocument(new PdfReader(inFile), new PdfWriter(new MemoryStream())); PdfStructTreeRoot structTreeRoot = doc.GetStructTreeRoot(); IList <PdfStructElem> kidsOfStructTreeRootKids = new List <PdfStructElem>(); foreach (IStructureNode kid in structTreeRoot.GetKids()) { foreach (IStructureNode kidOfKid in kid.GetKids()) { if (kidOfKid is PdfStructElem) { kidsOfStructTreeRootKids.Add((PdfStructElem)kidOfKid); } } } structTreeRoot.Flush(); foreach (PdfStructElem kidsOfStructTreeRootKid in kidsOfStructTreeRootKids) { NUnit.Framework.Assert.IsTrue(kidsOfStructTreeRootKid.IsFlushed()); } }