/// <summary> /// Escapes the string. /// </summary> /// <param name="buf">The buf.</param> /// <param name="encoding">The encoding.</param> /// <returns></returns> internal static byte[] EscapeString(byte[] buf, PdfEncodingBase encoding) { List <byte> list = new List <byte>(); for (int i = 0; i < buf.Length; i++) { byte item = buf[i]; switch (item) { case 8: { list.AddRange(encoding.GetBytes(@"\b")); continue; } case 9: { list.AddRange(encoding.GetBytes(@"\t")); continue; } case 10: { list.AddRange(encoding.GetBytes(@"\n")); continue; } case 12: { list.AddRange(encoding.GetBytes(@"\f")); continue; } case 13: { list.AddRange(encoding.GetBytes(@"\r")); continue; } case 40: case 0x29: case 0x5c: { list.AddRange(encoding.GetBytes(@"\")); list.Add(item); continue; } } list.Add(item); } return(list.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="T:Dt.Pdf.PdfStreamWriter" /> class. /// </summary> /// <param name="stream">The stream.</param> /// <param name="encoding">The encoding.</param> public PdfStreamWriter(System.IO.Stream stream, PdfEncodingBase encoding) { if (stream == null) { throw new PdfArgumentNullException("stream"); } if (encoding == null) { throw new PdfArgumentNullException("encoding"); } if (!stream.CanWrite) { throw new PdfArgumentException("stream"); } this.stream = stream; this.encoding = encoding; }