/// <summary> /// Renders a MigraDoc document to the specified file. /// </summary> public void Render(Document doc, string file, string workingDirectory) { StreamWriter strmWrtr = null; try { _document = doc; _docObject = doc; _workingDirectory = workingDirectory; string path = file; if (workingDirectory != null) path = Path.Combine(workingDirectory, file); strmWrtr = new StreamWriter(path, false, System.Text.Encoding.Default); _rtfWriter = new RtfWriter(strmWrtr); WriteDocument(); } finally { if (strmWrtr != null) { strmWrtr.Flush(); strmWrtr.Close(); } } }
/// <summary> /// Renders a MigraDoc document to the specified file. /// </summary> public void Render(Document doc, string file, string workingDirectory) { StreamWriter strmWrtr = null; try { _document = doc; _docObject = doc; _workingDirectory = workingDirectory; string path = file; if (workingDirectory != null) { path = Path.Combine(workingDirectory, file); } strmWrtr = new StreamWriter(path, false, System.Text.Encoding.Default); _rtfWriter = new RtfWriter(strmWrtr); WriteDocument(); } finally { if (strmWrtr != null) { strmWrtr.Flush(); strmWrtr.Close(); } } }
/// <summary> /// Renders a MigraDoc to Rtf and returns the result as string. /// </summary> public string RenderToString(Document document, string workingDirectory) { if (document == null) { throw new ArgumentNullException("document"); } if (document.UseCmykColor) { throw new InvalidOperationException("Cannot create RTF document with CMYK colors."); } _document = document; _docObject = document; _workingDirectory = workingDirectory; StringWriter writer = null; try { writer = new StringWriter(); _rtfWriter = new RtfWriter(writer); WriteDocument(); writer.Flush(); return(writer.GetStringBuilder().ToString()); } finally { if (writer != null) { writer.Close(); } } }
/// <summary> /// Initializes a new instance of the RendererBase class. /// </summary> internal RendererBase(DocumentObject domObj, RtfDocumentRenderer docRenderer) { if (enumTranslationTable == null) CreateEnumTranslationTable(); this.docObject = domObj; this.docRenderer = docRenderer; if (docRenderer != null) this.rtfWriter = docRenderer.RtfWriter; this.useEffectiveValue = false; }
/// <summary> /// Renders a MigraDoc document to the specified stream. /// </summary> public void Render(Document document, Stream stream, bool closeStream, string workingDirectory) { if (document == null) { throw new ArgumentNullException("document"); } if (document.UseCmykColor) { throw new InvalidOperationException("Cannot create RTF document with CMYK colors."); } StreamWriter strmWrtr = null; try { #if !NETCORE strmWrtr = new StreamWriter(stream, System.Text.Encoding.Default); #else strmWrtr = new StreamWriter(stream); #endif _document = document; _docObject = document; _workingDirectory = workingDirectory; _rtfWriter = new RtfWriter(strmWrtr); WriteDocument(); } finally { if (strmWrtr != null) { strmWrtr.Flush(); if (stream != null) { if (closeStream) { #if !NETCORE strmWrtr.Close(); #else strmWrtr.Dispose(); #endif } else { stream.Position = 0; // Reset the stream position if the stream is kept open. } } } } }
/// <summary> /// Renders a MigraDoc document to the specified stream. /// </summary> public void Render(Document document, Stream stream, bool closeStream, string workingDirectory) { if (document == null) throw new ArgumentNullException("document"); if (document.UseCmykColor) throw new InvalidOperationException("Cannot create RTF document with CMYK colors."); StreamWriter strmWrtr = null; try { strmWrtr = new StreamWriter(stream, System.Text.Encoding.Default); _document = document; _docObject = document; _workingDirectory = workingDirectory; _rtfWriter = new RtfWriter(strmWrtr); WriteDocument(); } finally { if (strmWrtr != null) { strmWrtr.Flush(); if (stream != null) { if (closeStream) strmWrtr.Close(); else stream.Position = 0; // Reset the stream position if the stream is kept open. } } } }
/// <summary> /// Renders a MigraDoc to Rtf and returns the result as string. /// </summary> public string RenderToString(Document document, string workingDirectory) { if (document == null) throw new ArgumentNullException("document"); if (document.UseCmykColor) throw new InvalidOperationException("Cannot create RTF document with CMYK colors."); _document = document; _docObject = document; _workingDirectory = workingDirectory; StringWriter writer = null; try { writer = new StringWriter(); _rtfWriter = new RtfWriter(writer); WriteDocument(); writer.Flush(); return writer.GetStringBuilder().ToString(); } finally { if (writer != null) writer.Close(); } }