Пример #1
0
        private void WriteBody(StreamInfo[] streams, string htmlBody)
        {
            var propertiesStream = streams.GetPropertiesStream();
            var bodyStream       = streams.GetRTFBodyStream();

            var rtfBody             = HtmlToRtfConverter.ConvertHtmlToRtf(htmlBody);
            var bodyBytes           = Encoding.ASCII.GetBytes(rtfBody);
            var bodyAndHeaderLength = BitConverter.GetBytes(bodyBytes.Length + 12); // 12 - {UncopressedSize:4}{Magic:4}{CRC32:4}
            var bodyLength          = BitConverter.GetBytes(bodyBytes.Length);
            var crc32 = CRC32.CalculateCRC32(bodyBytes);

            var bodyData = new List <byte>();

            bodyData.AddRange(bodyAndHeaderLength);
            bodyData.AddRange(bodyLength);
            bodyData.AddRange(new byte[] { 0x4D, 0x45, 0x4C, 0x41 }); // Magic number (0x414c454d) means RTF is not compressed
            bodyData.AddRange(BitConverter.GetBytes(crc32));
            bodyData.AddRange(bodyBytes);
            var bodyDataBytes = bodyData.ToArray();

            WriteBytesAndTruncate(bodyStream, bodyDataBytes);

            // Update stream info in properties
            var properties = GetBytes(propertiesStream);
            var bodyIndex  = properties.IndexOf(new byte[] { 0x09, 0x10 }); // BodyRTF tag

            if (bodyIndex == -1)
            {
                throw new ArgumentException($"Could not locate body index in properties stream. BIdx: {bodyIndex};");
            }

            var fullBodyLength = BitConverter.GetBytes(bodyDataBytes.Length);

            WriteBytes(propertiesStream, fullBodyLength, bodyIndex + StreamSizeOffset);
        }
Пример #2
0
        static void convertHtmlToRtf(object arg)
        {
            StringBuilder buffer = (StringBuilder)arg;
            string        rtf    = HtmlToRtfConverter.ConvertHtmlToRtf(buffer.ToString());

            buffer.Clear();
            buffer.Append(rtf);
        }
Пример #3
0
 private void ApplyQueryEditor(string text)
 {
     QueryEditor.Rtf = HtmlToRtfConverter.ConvertHtmlToRtf(text);
     QueryEditor.SelectAll();
     QueryEditor.SelectionFont = QueryFont;
     QueryEditor.DeselectAll();
     QueryEditor.SelectionStart = CursorPosition;
 }
Пример #4
0
        public static void Convert()
        {
            HtmlToRtfConverter converter = new HtmlToRtfConverter();

            string htmlContent = File.ReadAllText("sample.html");

            converter.Load(htmlContent);

            //Convert html to rtf, and save it to file stream
            using (var stream = File.OpenWrite("convert.rtf"))
            {
                converter.Save(stream);
            }
        }
Пример #5
0
        private void HomeDashboard_Load(object sender, EventArgs e)
        {
            var message = "<p style=\"font-family:verdana;font-size:6;\"><p>Welcome to eBatch Application.</p><br><br> hi User, Good Morning.<br><br>                    " +
                          "<p><strong>Messages:</strong></p> <br>                                                    " +
                          "<p><span style=\"text - decoration: underline; \">13 Nov 2018:</span></p>                  " +
                          "<p style=\"padding - left: 30px; \">3 Invoices been assigned to you by Admin.</p>          " +
                          "<p style=\"padding - left: 30px; \">10 Invoices been sent to disbursement</p> <br>             " +
                          "<p><span style=\"text - decoration: underline; \">12 Nov 2018:</span></p>                  " +
                          "<p style=\"padding - left: 30px; \">13 Invoices been assigned to you by Admin.</p>         " +
                          "<p style=\"padding - left: 30px; \">15&nbsp;Invoices been sent to disbursement</p>         " +
                          "<p>&nbsp;</p>" +
                          "<p>&nbsp;</p></p>";



            string rtfString = HtmlToRtfConverter.ConvertHtmlToRtf(message);

            richTextBox1.Rtf = rtfString;
            ManageTileColor();
        }
Пример #6
0
 public MarkupConverter(HtmlToRtfConverter aHtmlToRtfConverter)
 {
     _aHtmlToRtfConverter = aHtmlToRtfConverter;
 }
Пример #7
0
 public MarkupConverter(HtmlToRtfConverter aHtmlToRtfConverter)
 {
     _aHtmlToRtfConverter = aHtmlToRtfConverter;
 }