110 lines
4.2 KiB
C#
110 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Documents;
|
|
using HtmlToXamlDemo;
|
|
using Microsoft.VisualBasic;
|
|
|
|
namespace JRCookbookBusiness
|
|
{
|
|
public static class Utility
|
|
{
|
|
public static string ConvertHTLMLToRTF(string strInputHTML)
|
|
{
|
|
try
|
|
{
|
|
string objXAML = HtmlToXamlConverter.ConvertHtmlToXaml(strInputHTML, false);
|
|
|
|
TextWriter asdf;
|
|
|
|
if (File.Exists("C:\\ReussData\\DeleteMe.html"))
|
|
{
|
|
File.Delete("C:\\ReussData\\DeleteMe.html");
|
|
}
|
|
asdf = new StreamWriter("C:\\ReussData\\DeleteMe.html");
|
|
asdf.Write(strInputHTML);
|
|
asdf.Close();
|
|
asdf.Dispose();
|
|
asdf = null;
|
|
|
|
if (File.Exists("C:\\ReussData\\DeleteMe.xaml"))
|
|
{
|
|
File.Delete("C:\\ReussData\\DeleteMe.xaml");
|
|
}
|
|
asdf = new StreamWriter("C:\\ReussData\\DeleteMe.xaml");
|
|
asdf.Write(objXAML);
|
|
asdf.Close() ;
|
|
asdf.Dispose();
|
|
asdf = null;
|
|
|
|
if (File.Exists("C:\\ReussData\\DeleteMe.rtf"))
|
|
{
|
|
File.Delete("C:\\ReussData\\DeleteMe.rtf");
|
|
}
|
|
asdf = new StreamWriter("C:\\ReussData\\DeleteMe.rtf");
|
|
asdf.Write(ConvertXamlToRtf(objXAML));
|
|
asdf.Close();
|
|
asdf.Dispose();
|
|
asdf = null;
|
|
|
|
return ConvertXamlToRtf(objXAML);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
|
|
}
|
|
private static string ConvertXamlToRtf(string xamlText)
|
|
{
|
|
var richTextBox = new RichTextBox();
|
|
MessageBox.Show("Before:" + ControlChars.CrLf + "width = " + richTextBox.Width.ToString() + ControlChars.CrLf
|
|
+ "ActualWidth = " + richTextBox.ActualWidth.ToString() + ControlChars.CrLf
|
|
+ "ExtentWidth = " + richTextBox.ExtentWidth.ToString() + ControlChars.CrLf
|
|
+ "MaxWidth = " + richTextBox.MaxWidth.ToString() + ControlChars.CrLf
|
|
+ "ViewportWidth = " + richTextBox.ViewportWidth.ToString());
|
|
|
|
richTextBox.Width = 10000;
|
|
|
|
MessageBox.Show("Width:" + ControlChars.CrLf + "width = " + richTextBox.Width.ToString() + ControlChars.CrLf
|
|
+ "ActualWidth = " + richTextBox.ActualWidth.ToString() + ControlChars.CrLf
|
|
+ "ExtentWidth = " + richTextBox.ExtentWidth.ToString() + ControlChars.CrLf
|
|
+ "MaxWidth = " + richTextBox.MaxWidth.ToString() + ControlChars.CrLf
|
|
+ "ViewportWidth = " + richTextBox.ViewportWidth.ToString());
|
|
|
|
if (string.IsNullOrEmpty(xamlText)) return "";
|
|
var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
|
|
using (var xamlMemoryStream = new MemoryStream())
|
|
{
|
|
using (var xamlStreamWriter = new StreamWriter(xamlMemoryStream))
|
|
{
|
|
xamlStreamWriter.Write(xamlText);
|
|
xamlStreamWriter.Flush();
|
|
xamlMemoryStream.Seek(0, SeekOrigin.Begin);
|
|
textRange.Load(xamlMemoryStream, DataFormats.Xaml);
|
|
}
|
|
}
|
|
using (var rtfMemoryStream = new MemoryStream())
|
|
{
|
|
textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
|
|
textRange.Save(rtfMemoryStream, DataFormats.Rtf);
|
|
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
|
|
using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
|
|
{
|
|
return rtfStreamReader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|