/** * Writes the RtfInfoGroup and its RtfInfoElement elements. * * @return A byte array containing the group and its elements */ public override byte[] Write() { MemoryStream result = new MemoryStream(); try { result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(INFO_GROUP, 0, INFO_GROUP.Length); byte[] t; for (int i = 0; i < infoElements.Count; i++) { RtfInfoElement infoElement = (RtfInfoElement)infoElements[i]; result.Write(t = infoElement.Write(), 0, t.Length); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); result.WriteByte((byte)'\n'); } catch (IOException) { } return(result.ToArray()); }
/** * Writes the RTF information group and its elements. */ public override void WriteContent(Stream result) { result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(INFO_GROUP, 0, INFO_GROUP.Length); for (int i = 0; i < infoElements.Count; i++) { RtfInfoElement infoElement = (RtfInfoElement)infoElements[i]; infoElement.WriteContent(result); } // handle document protection if (document.GetDocumentSettings().IsDocumentProtected()) { byte[] t; result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(INFO_PASSWORD, 0, INFO_PASSWORD.Length); result.Write(DELIMITER, 0, DELIMITER.Length); result.Write(t = document.GetDocumentSettings().GetProtectionHashBytes(), 0, t.Length); result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); this.document.OutputDebugLinebreak(result); }
/// <summary> /// Writes the RTF information group and its elements. /// </summary> public override void WriteContent(Stream result) { result.Write(OpenGroup, 0, OpenGroup.Length); result.Write(_infoGroup, 0, _infoGroup.Length); for (int i = 0; i < _infoElements.Count; i++) { RtfInfoElement infoElement = (RtfInfoElement)_infoElements[i]; infoElement.WriteContent(result); } // handle document protection if (Document.GetDocumentSettings().IsDocumentProtected()) { byte[] t; result.Write(OpenGroup, 0, OpenGroup.Length); result.Write(_infoPassword, 0, _infoPassword.Length); result.Write(Delimiter, 0, Delimiter.Length); result.Write(t = Document.GetDocumentSettings().GetProtectionHashBytes(), 0, t.Length); result.Write(CloseGroup, 0, CloseGroup.Length); } result.Write(CloseGroup, 0, CloseGroup.Length); Document.OutputDebugLinebreak(result); }
/** * Adds an RtfInfoElement to the list of RtfInfoElements * * @param rtfInfoElement The RtfInfoElement to add */ public void AddInfoElement(RtfInfoElement rtfInfoElement) { this.infoGroup.Add(rtfInfoElement); }
/** * Adds an RtfInfoElement to the RtfInfoGroup * * @param infoElement The RtfInfoElement to add */ public void Add(RtfInfoElement infoElement) { this.infoElements.Add(infoElement); }
/* (non-Javadoc) * @see com.lowagie.text.rtf.direct.RtfDestination#handleGroupEnd() */ public override bool HandleCloseGroup() { if (this.text.Length > 0) { Document doc = this.rtfParser.GetDocument(); if (doc != null) { if (this.elementName.Equals("author")){ doc.AddAuthor(this.text); } if (this.elementName.Equals("title")){ doc.AddTitle(this.text); } if (this.elementName.Equals("subject")){ doc.AddSubject(this.text); } } else { RtfDocument rtfDoc = this.rtfParser.GetRtfDocument(); if (rtfDoc != null) { if (this.elementName.Equals("author")){ Meta meta = new Meta(this.elementName, this.text); RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta); rtfDoc.GetDocumentHeader().AddInfoElement(elem); } if (this.elementName.Equals("title")){ Meta meta = new Meta(this.elementName, this.text); RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta); rtfDoc.GetDocumentHeader().AddInfoElement(elem); } if (this.elementName.Equals("subject")){ Meta meta = new Meta(this.elementName, this.text); RtfInfoElement elem = new RtfInfoElement(rtfDoc, meta); rtfDoc.GetDocumentHeader().AddInfoElement(elem); } } } this.SetToDefaults(); } return true; }
/// <summary> /// Adds an RtfInfoElement to the RtfInfoGroup /// </summary> /// <param name="infoElement">The RtfInfoElement to add</param> public void Add(RtfInfoElement infoElement) { _infoElements.Add(infoElement); }
/** * Takes an Element subclass and returns the correct IRtfBasicElement * subclass, that wraps the Element subclass. * * @param element The Element to wrap * @return A IRtfBasicElement wrapping the Element * @throws DocumentException */ public IRtfBasicElement MapElement(IElement element) { IRtfBasicElement rtfElement = null; if (element is IRtfBasicElement) { rtfElement = (IRtfBasicElement) element; rtfElement.SetRtfDocument(this.rtfDoc); return rtfElement; } switch (element.Type) { case Element.CHUNK: if (((Chunk) element).GetImage() != null) { rtfElement = new RtfImage(rtfDoc, ((Chunk) element).GetImage()); } else if (((Chunk) element).HasAttributes() && ((Chunk) element).Attributes.ContainsKey(Chunk.NEWPAGE)) { rtfElement = new RtfNewPage(rtfDoc); } else { rtfElement = new RtfChunk(rtfDoc, (Chunk) element); } break; case Element.PHRASE: rtfElement = new RtfPhrase(rtfDoc, (Phrase) element); break; case Element.PARAGRAPH: rtfElement = new RtfParagraph(rtfDoc, (Paragraph) element); break; case Element.ANCHOR: rtfElement = new RtfAnchor(rtfDoc, (Anchor) element); break; case Element.ANNOTATION: rtfElement = new RtfAnnotation(rtfDoc, (Annotation) element); break; case Element.IMGRAW: case Element.IMGTEMPLATE: case Element.JPEG: rtfElement = new RtfImage(rtfDoc, (Image) element); break; case Element.AUTHOR: case Element.SUBJECT: case Element.KEYWORDS: case Element.TITLE: case Element.PRODUCER: case Element.CREATIONDATE: rtfElement = new RtfInfoElement(rtfDoc, (Meta) element); break; case Element.LIST: rtfElement = new RtfList(rtfDoc, (List) element); break; case Element.LISTITEM: rtfElement = new RtfListItem(rtfDoc, (ListItem) element); break; case Element.SECTION: rtfElement = new RtfSection(rtfDoc, (Section) element); break; case Element.CHAPTER: rtfElement = new RtfChapter(rtfDoc, (Chapter) element); break; case Element.TABLE: try { rtfElement = new TB.RtfTable(rtfDoc, (Table) element); } catch (InvalidCastException) { rtfElement = new TB.RtfTable(rtfDoc, ((SimpleTable) element).CreateTable()); } break; } return rtfElement; }