Hi,
Is it possible to create PDF File from rict text box text using infragistics control.?
Thanks in Advance
Hi Kalees,
I think it is necessary that you find the Infragistics samples, e.g. download a new version and install "NetAdvantage WinForms Samples 20091.exe"
Regards, Werner
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Collections.Generic
Namespace Infragistics.Guidance.Documents
Public Class RTFExample
Implements Infragistics.Documents.RTF.ICallback
Private _reader As Infragistics.Documents.RTF.Reader
Private _container As Infragistics.Documents.Report.IContainer
Private _text As Infragistics.Documents.Report.Text.IText
Private _textPattern As Infragistics.Documents.Report.Text.TextPattern
Private _style As Infragistics.Documents.Report.Text.Style
Private _brushHash As Dictionary(Of Integer, Infragistics.Documents.Graphics.Brush)
Private _fontHash As Dictionary(Of Infragistics.Documents.Graphics.FontHashKey, Infragistics.Documents.Graphics.Font)
Private _styleHash As Dictionary(Of Infragistics.Documents.Report.Text.ShortStyleHashKey, Infragistics.Documents.Report.Text.Style)
Public Sub New()
_brushHash = New Dictionary(Of Integer, Infragistics.Documents.Graphics.Brush)(25)
_fontHash = New Dictionary(Of Infragistics.Documents.Graphics.FontHashKey, Infragistics.Documents.Graphics.Font)(25)
_styleHash = New Dictionary(Of Infragistics.Documents.Report.Text.ShortStyleHashKey, Infragistics.Documents.Report.Text.Style)(25)
_textPattern = New Infragistics.Documents.Report.Text.TextPattern()
_textPattern.Margins.All = 5
_textPattern.Interval = 2
End Sub
Public Sub Load(ByVal container As Infragistics.Documents.Report.IContainer, ByVal stream As FileStream)
_container = container
_reader = New Infragistics.Documents.RTF.Reader(stream, Me)
_reader.Read()
Public Sub OnStart() Implements Infragistics.Documents.RTF.ICallback.OnStart
Public Sub OnEnd() Implements Infragistics.Documents.RTF.ICallback.OnEnd
Public Sub OnInfo(ByVal info As Infragistics.Documents.RTF.Info) Implements Infragistics.Documents.RTF.ICallback.OnInfo
Public Sub OnKeyword(ByVal keyword As Infragistics.Documents.RTF.Keyword) Implements Infragistics.Documents.RTF.ICallback.OnKeyword
If (keyword.Symbol = Infragistics.Documents.RTF.Defs.Symbols.PAR) OrElse (keyword.Symbol = Infragistics.Documents.RTF.Defs.Symbols.CELL) OrElse (keyword.Symbol = Infragistics.Documents.RTF.Defs.Symbols.SECT) Then
If Not _text Is Nothing Then
_text = Nothing
End If
Public Sub OnChar(ByVal ch As Char) Implements Infragistics.Documents.RTF.ICallback.OnChar
If _text Is Nothing Then
_text = _container.AddText()
_textPattern.Apply(_text)
UpdateParagraph()
CheckState()
_text.AddContent(ch, _style)
Public Sub OnImage(ByVal image As Infragistics.Documents.Graphics.Image, ByVal width As Integer, ByVal height As Integer) Implements Infragistics.Documents.RTF.ICallback.OnImage
image.Preferences.Compressor = Infragistics.Documents.Graphics.ImageCompressors.JPEG
_text.AddContent(image, New Infragistics.Documents.Graphics.Size(Infragistics.Documents.Utils.Converter.TwipsToPoints(width), Infragistics.Documents.Utils.Converter.TwipsToPoints(height)))
Private Sub CheckState()
If _reader.State.Changed Then
UpdateDocument()
UpdateSection()
UpdateCharacter()
_reader.State.Changed = False
Else
If _reader.State.Document.Changed Then
If _reader.State.Section.Changed Then
If _reader.State.Paragraph.Changed Then
If _reader.State.Character.Changed Then
Private Sub UpdateDocument()
Dim document As Infragistics.Documents.RTF.Document = _reader.State.Document
document.Changed = False
Private Sub UpdateSection()
Dim section As Infragistics.Documents.RTF.Section = _reader.State.Section
section.Changed = False
Private Sub UpdateParagraph()
Dim paragraph As Infragistics.Documents.RTF.Paragraph = _reader.State.Paragraph
_text.Alignment = Infragistics.Documents.Report.TextAlignment.Left
Select Case paragraph.Alignment
Case Infragistics.Documents.RTF.ParagraphAlignment.LeftAligned
Case Infragistics.Documents.RTF.ParagraphAlignment.RightAligned
_text.Alignment = Infragistics.Documents.Report.TextAlignment.Right
Case Infragistics.Documents.RTF.ParagraphAlignment.Centered
_text.Alignment = Infragistics.Documents.Report.TextAlignment.Center
Case Infragistics.Documents.RTF.ParagraphAlignment.Justified
_text.Alignment = Infragistics.Documents.Report.TextAlignment.Justify
Case Infragistics.Documents.RTF.ParagraphAlignment.Distributed
End Select
_text.Indents.First = Infragistics.Documents.Utils.Converter.TwipsToPoints(paragraph.FirstIndent)
_text.Indents.Left = Infragistics.Documents.Utils.Converter.TwipsToPoints(paragraph.LeftIndent)
_text.Indents.Right = Infragistics.Documents.Utils.Converter.TwipsToPoints(paragraph.RightIndent)
If _text.Indents.First < 0 Then
_text.Indents.First = 0
If _text.Indents.Left < 0 Then
_text.Indents.Left = 0
If _text.Indents.Right < 0 Then
_text.Indents.Right = 0
paragraph.Changed = False
Private Sub UpdateCharacter()
Dim character As Infragistics.Documents.RTF.Character = _reader.State.Character
Dim fontStyle As Infragistics.Documents.Graphics.FontStyle = Infragistics.Documents.Graphics.FontStyle.Regular
If character.Bold Then
fontStyle = fontStyle Or Infragistics.Documents.Graphics.FontStyle.Bold
If character.Italic Then
fontStyle = fontStyle Or Infragistics.Documents.Graphics.FontStyle.Italic
If character.Underline Then
fontStyle = fontStyle Or Infragistics.Documents.Graphics.FontStyle.Underline
_style = GetStyle(GetFont(character.FontIndex, character.FontSize / 2F, fontStyle), GetBrush(character.ColorIndex))
character.Changed = False
Private Function GetStyle(ByVal font As Infragistics.Documents.Graphics.Font, ByVal brush As Infragistics.Documents.Graphics.Brush) As Infragistics.Documents.Report.Text.Style
Dim key As Infragistics.Documents.Report.Text.ShortStyleHashKey = New Infragistics.Documents.Report.Text.ShortStyleHashKey(font, brush)
If _styleHash.ContainsKey(key) Then
Return _styleHash(key)
Dim style As Infragistics.Documents.Report.Text.Style = New Infragistics.Documents.Report.Text.Style(font, brush)
_styleHash.Add(key, style)
Return style
End Function
Private Function GetBrush(ByVal index As Integer) As Infragistics.Documents.Graphics.Brush
If index = -1 Then
index = _reader.DefaultColorIndex
If _brushHash.ContainsKey(index) Then
Return _brushHash(index)
If _reader.Colors.ContainsKey(index) Then
Dim color As Infragistics.Documents.RTF.Color = _reader.Colors(index)
Dim brush As Infragistics.Documents.Graphics.Brush = New Infragistics.Documents.Graphics.SolidColorBrush(New Infragistics.Documents.Graphics.Color(color.R, color.G, color.B))
_brushHash.Add(index, brush)
Return brush
Return Infragistics.Documents.Graphics.Brushes.Black
Private Function GetFont(ByVal index As Integer, ByVal size As Single, ByVal style As Infragistics.Documents.Graphics.FontStyle) As Infragistics.Documents.Graphics.Font
index = _reader.DefaultFontIndex
Dim name As String = Nothing
If _reader.Fonts.ContainsKey(index) Then
name = _reader.Fonts(index).Name
If String.IsNullOrEmpty(name) OrElse name.Equals("Symbol") OrElse name.Equals("System") Then
name = "Arial"
If size <= 0 Then
size = 12
Dim key As Infragistics.Documents.Graphics.FontHashKey = New Infragistics.Documents.Graphics.FontHashKey(name, size, style)
If _fontHash.ContainsKey(key) Then
Return _fontHash(key)
Dim font As Infragistics.Documents.Graphics.Font = New Infragistics.Documents.Graphics.Font(name, size, style)
_fontHash.Add(key, font)
Return font
End Class
End Namespace
Thanks for the reply.
I am unable to find the sample. Please send that attachment.
Regards
Kalees
It is absolutely possible, but it seems that even Infragistics people do not know about. Please look up your Infragistics document samples, and there you will find an RTF print sample under "Converters", or find the RTFExample.vb in ...\Samples\Documents\VB\Code
Werner
No, there is no support in the Documents engine for adding RTF text. There are ways to have formatted text through the AddRichContent method on an IText element, but this more like a primitive form of HTML. There should be an example of using this method in the Documents sample that ships with the NetAdvantage SDK.
-Matt