Hello,
I would like to be able to print the contents of an UltraFormattedTextEditor.In the knowledge base article http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=8278under the UltraPrintDocument section it says there is a sample custom printdocument.
If anyone could tell me where to find this sample, or better yet if there is already support for printing UFTE contents, I would be very greatful.
Okay, after playing around I've discovered something interesting. The UltraFormattedTextEditor creates HTML, but not every tag that it creates is supported by the AddRichContent method. This is definately something that needs submitted as a feature request. Here was the code I used to play around in my testing:
// MBS 1/11/08 - BR29211
report.Preferences.Printing.PaperOrientation = Infragistics.Documents.Report.Preferences.Printing.PaperOrientation.Auto;
Infragistics.Documents.Report.Section.ISection section = report.AddSection();
section.PageMargins.All = 35;
section.PageNumbering.Style = new Infragistics.Documents.Report.Text.Style(Infragistics.Documents.Graphics.Fonts.Arial, Infragistics.Documents.Graphics.Brushes.Black);
section.PageNumbering.Continue = true;
section.PageNumbering.OffsetX = -10;
Infragistics.Documents.Report.Text.IText text = section.AddText();
text.Style = normalStyle;
System.Diagnostics.Process.Start("thereport.pdf");
If it's really an emergency I'm sure you could take the manual route and further parse that formatted text editor value to replace the tags with supported tags or even capture the hotkeys to place the support tags instead of the SPAN tag it creates, then you'd be all set. These are the tags that the AddRichContent method supports:
You actually don't need to parse out the formatted tags yourself, since much of this logic already needed to be written for the WinGridDocumentExporter to handle exporting cells that have formatted text. Instead, you can use the Infragistics.Win.UltraWinGrid.DocumentExport.Utilities.BuildFormattedText method, within the DocumentExport assembly, such as:
string formattedText = @"<span style=""font-weight:bold;"">Here </span><span style=""font-style:italic;"">is </span><span style=""font-size:16pt;"">some </span><span style=""font-family:Arial Black;"">formatted </span><a href=""http://es.infragistics.com"">text</a>";AppearanceData appearance = new AppearanceData();appearance.ForeColor = Color.Black;string documentsFormattedText = Infragistics.Win.UltraWinGrid.DocumentExport.Utilities.BuildFormattedText(formattedText, this.ultraFormattedTextEditor1.Size, this.Font, ref appearance);Report report = new Report();report.AddSection().AddText().AddRichContent(documentsFormattedText);report.Publish("Test.pdf", FileFormat.PDF);Process.Start("Test.pdf");
To answer the original question of this thread, the approach mentioned here and by Torrey implies that you must created a Report object through the Infragistics.Documents assembly. To my knowledge, there is not any existing functionality that lets you provide an UltraFormattedTextEditor and have it render into a PrintDocument. However, the base Control class has a DrawToBitmap method that lets you render the display to an image so that you can then use that as you see fit, i.e.:
Bitmap bmp = new Bitmap(this.ultraFormattedTextEditor1.Width, this.ultraFormattedTextEditor1.Height);this.ultraFormattedTextEditor1.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));this.pictureBox1.Image = bmp;
-Matt
That is insanely awesome Matt! In addition, you gave me some new areas of the documentation to dig through for more cool features. :)