Showing posts with label saved. Show all posts
Showing posts with label saved. Show all posts

Monday, March 19, 2012

Displaying RTF fields in a report

Hi,

I would appreciate it anyone could help. I've saved RTF formatted data to a text field in the sql server db. I want to display this formatted text in a report with. Any ideas?

shot

I have the same problem, but I think I'm reallllly close to the solution.

I'm rendering the RTF to an image file and trying to load it into an image control via a referenced class. I have the class returning either an image or a byte array. Reporting services image controls apparently only work with a byte array, but as of yet I can't get it to work.

Using the same assembly reference I am able to view the resulting image with the pictureBox control, and the byte array appears to be populated as intended, it just won't load up in reporting services.

I'll attach my code thus far in hopes that you'll be able to get further than I have (if you do, be sure to post the fix).

I'm setting the image source to database, the mime type to image\bmp and value to "=Code.GetImage()". Oh, and don't forget to add the dll to the assembly cache when you add the reference to the assembly dll in reporting services, it doesn't seem to play well otherwise.

In the code section I've added the following function:

Function GetImage() As Byte()
objRTFImage.Rtf = "This is a test"
return objRTFImage.PrintToByteArray(200, 100) ' Syntax PrintToByteArray(int32 width, int32 height)
End Function

The class code in my assembly is posted below.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using System.Drawing.Imaging;

using System.IO;

namespace RichTextRenderer

{

public partial class RTFImage : RichTextBox

{

public RTFImage()

{

}

protected override void OnPaint(PaintEventArgs pe)

{

// Calling the base class OnPaint

base.OnPaint(pe);

}

//Convert the unit used by the .NET framework (1/100 inch)

//and the unit used by Win32 API calls (twips 1/1440 inch)

private const double anInch = 14.4;

[StructLayout(LayoutKind.Sequential)]

private struct RECT

{

public int Left;

public int Top;

public int Right;

public int Bottom;

}

[StructLayout(LayoutKind.Sequential)]

private struct CHARRANGE

{

public int cpMin; //First character of range (0 for start of doc)

public int cpMax; //Last character of range (-1 for end of doc)

}

[StructLayout(LayoutKind.Sequential)]

private struct FORMATRANGE

{

public IntPtr hdc; //Actual DC to draw on

public IntPtr hdcTarget; //Target DC for determining text formatting

public RECT rc; //Region of the DC to draw to (in twips)

public RECT rcPage; //Region of the whole DC (page size) (in twips)

public CHARRANGE chrg; //Range of text to draw (see earlier declaration)

}

private const int WM_USER = 0x0400;

private const int EM_FORMATRANGE = WM_USER + 57;

[DllImport("USER32.dll")]

private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

// Render the contents of the RichTextBox for printing

// Return the last character printed + 1 (printing start from this point for next page)

public Image PrintToImage(String plainText, Int32 width, Int32 height)

{

this.Text = plainText;

return PrintToImage( width, height);

}

public Image PrintToImage(Int32 width, Int32 height)

{

Image image = new Bitmap(width, height);

Graphics g = Graphics.FromImage(image);

Int32 retVal = this.Print(0, this.Text.Length, g, new Rectangle(this.Location, new Size(width, height)));

return image;

}

public byte[] PrintToByteArray(String plainText, Int32 width, Int32 height)

{

return ConvertImageToByteArray(PrintToImage(plainText, width, height));

}

public byte[] PrintToByteArray(Int32 width, Int32 height)

{

return ConvertImageToByteArray(PrintToImage(width, height));

}

public int Print(int charFrom, int charTo, Graphics gr, Rectangle bounds)

{

//Calculate the area to render and print

RECT rectToPrint;

rectToPrint.Top = 0;// (int)(bounds.Top * anInch);

rectToPrint.Bottom = (int)(bounds.Height * anInch);// (int)(bounds.Bottom * anInch);

rectToPrint.Left = 0;// (int)(bounds.Left * anInch);

rectToPrint.Right = (int)(bounds.Width * anInch);// (int)(bounds.Right * anInch);

//Calculate the size of the page

RECT rectPage;

rectPage.Top = 0;//(int)(bounds.Top * anInch);

rectPage.Bottom = (int)(gr.ClipBounds.Height * anInch);//(int)(bounds.Bottom * anInch);

rectPage.Left = 0;//(int)(bounds.Left * anInch);

rectPage.Right = (int)(gr.ClipBounds.Right * anInch);//(int)(bounds.Right * anInch);

IntPtr hdc = gr.GetHdc();

FORMATRANGE fmtRange;

fmtRange.chrg.cpMax = charTo; //Indicate character from to character to

fmtRange.chrg.cpMin = charFrom;

fmtRange.hdc = hdc; //Use the same DC for measuring and rendering

fmtRange.hdcTarget = hdc; //Point at printer hDC

fmtRange.rc = rectToPrint; //Indicate the area on page to print

fmtRange.rcPage = rectPage; //Indicate size of page

IntPtr res = IntPtr.Zero;

IntPtr wparam = IntPtr.Zero;

wparam = new IntPtr(1);

//Get the pointer to the FORMATRANGE structure in memory

IntPtr lparam = IntPtr.Zero;

lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));

Marshal.StructureToPtr(fmtRange, lparam, false);

//Send the rendered data for printing

res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);

//Free the block of memory allocated

Marshal.FreeCoTaskMem(lparam);

//Release the device context handle obtained by a previous call

gr.ReleaseHdc(hdc);

//Return last + 1 character printer

return res.ToInt32();

}

public static byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert)

{

byte[] Ret;

//try

//{

using (System.IO.MemoryStream ms = new MemoryStream())

{

imageToConvert.Save(ms,ImageFormat.Bmp);

ms.Position = 0;

Ret = ms.ToArray();

}

//}

//catch (Exception) { throw; }

return Ret;

}

}

}

|||

Hi

Thanks so much for your response, i luckily have the option of using Crystal....which supports RTF fields apparently - and which i'll def be using!!

Good luck with the RTF prob, i might pursue it in my personal time - please let me know if/when you have a solution and how you solved it.

thanks

Friday, March 9, 2012

Displaying HTML or other Rich Text Format content in Reporting Ser

For a report I am creating, I need to display rich text format content, that
will be saved in the database, on a reporting services report. This data
will include bolds, bullets, italics, indents, etc.
Is there a way to show this content formatted correctly in Reporting
Services? We were planning on storing the data as HTML in the database but
reporting services is displaying the actual HTML code and not the content.
Does anyone have any ideas? Any help is greatly appreciated! ThanksSSRS only prints plain text. You can't display HTML or RTF.
"giggleraz" <giggleraz@.discussions.microsoft.com> wrote in message
news:B5F25DF8-285F-4052-A159-74E4863A9829@.microsoft.com...
> For a report I am creating, I need to display rich text format content,
that
> will be saved in the database, on a reporting services report. This data
> will include bolds, bullets, italics, indents, etc.
> Is there a way to show this content formatted correctly in Reporting
> Services? We were planning on storing the data as HTML in the database
but
> reporting services is displaying the actual HTML code and not the content.
> Does anyone have any ideas? Any help is greatly appreciated! Thanks|||Does anyone know if this will be possible in SQL 2005 RS? Surely this is a
basic requirement in a reporting tool
"Brian Bischof" wrote:
> SSRS only prints plain text. You can't display HTML or RTF.
>
> "giggleraz" <giggleraz@.discussions.microsoft.com> wrote in message
> news:B5F25DF8-285F-4052-A159-74E4863A9829@.microsoft.com...
> > For a report I am creating, I need to display rich text format content,
> that
> > will be saved in the database, on a reporting services report. This data
> > will include bolds, bullets, italics, indents, etc.
> > Is there a way to show this content formatted correctly in Reporting
> > Services? We were planning on storing the data as HTML in the database
> but
> > reporting services is displaying the actual HTML code and not the content.
> > Does anyone have any ideas? Any help is greatly appreciated! Thanks
>
>|||Not sure if this helps but what I had to do to get bullets was to start the
old Windows character map...not sure if it still comes with XP but if you
have an older version of windows such as 95 or 98 or 2000 you can start
character map by "Start" RUN and typing charmap.exe
Go to the Time New Roman font, scroll down about half way and you'll find a
BULLET (code 2022), you can copy it then paste it into a Textbox object and
it will display fine.
"IWantItalics" wrote:
> Does anyone know if this will be possible in SQL 2005 RS? Surely this is a
> basic requirement in a reporting tool
> "Brian Bischof" wrote:
> > SSRS only prints plain text. You can't display HTML or RTF.
> >
> >
> > "giggleraz" <giggleraz@.discussions.microsoft.com> wrote in message
> > news:B5F25DF8-285F-4052-A159-74E4863A9829@.microsoft.com...
> > > For a report I am creating, I need to display rich text format content,
> > that
> > > will be saved in the database, on a reporting services report. This data
> > > will include bolds, bullets, italics, indents, etc.
> > > Is there a way to show this content formatted correctly in Reporting
> > > Services? We were planning on storing the data as HTML in the database
> > but
> > > reporting services is displaying the actual HTML code and not the content.
> > > Does anyone have any ideas? Any help is greatly appreciated! Thanks
> >
> >
> >

Displaying Encoded Characters

some special characters are saved in an encoded form. However reporting
services does not convert it back to the regular form when it retreives it
from the database, instead it would output get wierd characters.the code for keystrokes ALT 250 and others are whats being outputted not the
correct symbol.
"Marvin" wrote:
> some special characters are saved in an encoded form. However reporting
> services does not convert it back to the regular form when it retreives it
> from the database, instead it would output get wierd characters.

Friday, February 24, 2012

Display text as HTML?

Is it possible to display text saved with HTML tags as true HTML inside a text box? For example I have some text saved that displays in red when viewed on a web page, but in the report it actually prints the HTML tags that set the color to red. Any ideas? Thanks!
JeffNOPE. Reporting Services just prints out the text AS IS and is not parsed by the browser. I have spent a very good amount of time on this issue for one of the projects I worked on.
I even brought it up during one of the MSDN events with a Microsoft SQL Server MVP speaker. He asked me to email him in detail about it and when I did he never replied back.|||Thanks for the reply. That's what I was afraid of. Guess I'll probably end up using Active Reports for now. Thanks again!

Display RTF String

Hi,
I have a rtf string saved in a SQL Server Db which i want to display on the
report. The string is forumlated as:{\rtf1\ansi\ansicpg1252\uc1 aaa}
Is this possible in SSRS? If yes then kindly provide some help on the
implementation.Rich text and html is not supported in this release or Yukon, Html will be
supported in the next release after SQL 2005 but I do not know about rich
text...
You could create your own rich text textbox and in custom dll and add it to
the tools ...
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Afaq" <Afaq@.discussions.microsoft.com> wrote in message
news:51F23E7F-ACEE-4FD1-AA43-93F6EF0C86B0@.microsoft.com...
> Hi,
> I have a rtf string saved in a SQL Server Db which i want to display on
> the
> report. The string is forumlated as:{\rtf1\ansi\ansicpg1252\uc1 aaa}
> Is this possible in SSRS? If yes then kindly provide some help on the
> implementation.
>|||How do i add a custom control to the report? I created a rtf user control -
after adding it in the report designer toolbox - it is disabled for selection.
Pardon my ignorance here. I am using SSRS 2000.
--
Afaq
"Wayne Snyder" wrote:
> Rich text and html is not supported in this release or Yukon, Html will be
> supported in the next release after SQL 2005 but I do not know about rich
> text...
> You could create your own rich text textbox and in custom dll and add it to
> the tools ...
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Afaq" <Afaq@.discussions.microsoft.com> wrote in message
> news:51F23E7F-ACEE-4FD1-AA43-93F6EF0C86B0@.microsoft.com...
> > Hi,
> >
> > I have a rtf string saved in a SQL Server Db which i want to display on
> > the
> > report. The string is forumlated as:{\rtf1\ansi\ansicpg1252\uc1 aaa}
> >
> > Is this possible in SSRS? If yes then kindly provide some help on the
> > implementation.
> >
>
>|||You can't do this for RS 2000. I gather that this will be possible with RS
2005.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Afaq" <Afaq@.discussions.microsoft.com> wrote in message
news:1CA44862-75D4-4248-8EE5-11EE59995451@.microsoft.com...
> How do i add a custom control to the report? I created a rtf user
> control -
> after adding it in the report designer toolbox - it is disabled for
> selection.
> Pardon my ignorance here. I am using SSRS 2000.
> --
> Afaq
>
> "Wayne Snyder" wrote:
>> Rich text and html is not supported in this release or Yukon, Html will
>> be
>> supported in the next release after SQL 2005 but I do not know about rich
>> text...
>> You could create your own rich text textbox and in custom dll and add it
>> to
>> the tools ...
>> --
>> Wayne Snyder, MCDBA, SQL Server MVP
>> Mariner, Charlotte, NC
>> www.mariner-usa.com
>> (Please respond only to the newsgroups.)
>> I support the Professional Association of SQL Server (PASS) and it's
>> community of SQL Server professionals.
>> www.sqlpass.org
>> "Afaq" <Afaq@.discussions.microsoft.com> wrote in message
>> news:51F23E7F-ACEE-4FD1-AA43-93F6EF0C86B0@.microsoft.com...
>> > Hi,
>> >
>> > I have a rtf string saved in a SQL Server Db which i want to display on
>> > the
>> > report. The string is forumlated as:{\rtf1\ansi\ansicpg1252\uc1 aaa}
>> >
>> > Is this possible in SSRS? If yes then kindly provide some help on the
>> > implementation.
>> >
>>|||Uh Oh...
So to summarise- i cant display rtf in SSRS 2000
--
Afaq
"Bruce L-C [MVP]" wrote:
> You can't do this for RS 2000. I gather that this will be possible with RS
> 2005.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Afaq" <Afaq@.discussions.microsoft.com> wrote in message
> news:1CA44862-75D4-4248-8EE5-11EE59995451@.microsoft.com...
> > How do i add a custom control to the report? I created a rtf user
> > control -
> > after adding it in the report designer toolbox - it is disabled for
> > selection.
> >
> > Pardon my ignorance here. I am using SSRS 2000.
> >
> > --
> > Afaq
> >
> >
> > "Wayne Snyder" wrote:
> >
> >> Rich text and html is not supported in this release or Yukon, Html will
> >> be
> >> supported in the next release after SQL 2005 but I do not know about rich
> >> text...
> >>
> >> You could create your own rich text textbox and in custom dll and add it
> >> to
> >> the tools ...
> >>
> >> --
> >> Wayne Snyder, MCDBA, SQL Server MVP
> >> Mariner, Charlotte, NC
> >> www.mariner-usa.com
> >> (Please respond only to the newsgroups.)
> >>
> >> I support the Professional Association of SQL Server (PASS) and it's
> >> community of SQL Server professionals.
> >> www.sqlpass.org
> >>
> >> "Afaq" <Afaq@.discussions.microsoft.com> wrote in message
> >> news:51F23E7F-ACEE-4FD1-AA43-93F6EF0C86B0@.microsoft.com...
> >> > Hi,
> >> >
> >> > I have a rtf string saved in a SQL Server Db which i want to display on
> >> > the
> >> > report. The string is forumlated as:{\rtf1\ansi\ansicpg1252\uc1 aaa}
> >> >
> >> > Is this possible in SSRS? If yes then kindly provide some help on the
> >> > implementation.
> >> >
> >>
> >>
> >>
>
>|||Nope.
--
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Afaq" <Afaq@.discussions.microsoft.com> wrote in message
news:F1541CCC-4609-4BCF-8684-FD8C553AB6AD@.microsoft.com...
> Uh Oh...
> So to summarise- i cant display rtf in SSRS 2000
> --
> Afaq
>
> "Bruce L-C [MVP]" wrote:
>> You can't do this for RS 2000. I gather that this will be possible with
>> RS
>> 2005.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Afaq" <Afaq@.discussions.microsoft.com> wrote in message
>> news:1CA44862-75D4-4248-8EE5-11EE59995451@.microsoft.com...
>> > How do i add a custom control to the report? I created a rtf user
>> > control -
>> > after adding it in the report designer toolbox - it is disabled for
>> > selection.
>> >
>> > Pardon my ignorance here. I am using SSRS 2000.
>> >
>> > --
>> > Afaq
>> >
>> >
>> > "Wayne Snyder" wrote:
>> >
>> >> Rich text and html is not supported in this release or Yukon, Html
>> >> will
>> >> be
>> >> supported in the next release after SQL 2005 but I do not know about
>> >> rich
>> >> text...
>> >>
>> >> You could create your own rich text textbox and in custom dll and add
>> >> it
>> >> to
>> >> the tools ...
>> >>
>> >> --
>> >> Wayne Snyder, MCDBA, SQL Server MVP
>> >> Mariner, Charlotte, NC
>> >> www.mariner-usa.com
>> >> (Please respond only to the newsgroups.)
>> >>
>> >> I support the Professional Association of SQL Server (PASS) and it's
>> >> community of SQL Server professionals.
>> >> www.sqlpass.org
>> >>
>> >> "Afaq" <Afaq@.discussions.microsoft.com> wrote in message
>> >> news:51F23E7F-ACEE-4FD1-AA43-93F6EF0C86B0@.microsoft.com...
>> >> > Hi,
>> >> >
>> >> > I have a rtf string saved in a SQL Server Db which i want to display
>> >> > on
>> >> > the
>> >> > report. The string is forumlated as:{\rtf1\ansi\ansicpg1252\uc1 aaa}
>> >> >
>> >> > Is this possible in SSRS? If yes then kindly provide some help on
>> >> > the
>> >> > implementation.
>> >> >
>> >>
>> >>
>> >>
>>|||Actually you can, but it requires code in an external assembly.
Here is one option:
1. Create a ClassLibrary project in C# or VB.NET.
2. Add a reference to the System.Windows.Forms.dll
3. Create a class such as ConversionUtility
4. Add the appropriate import/using statement using
System.Windows.Forms; to your class.
5. Create a method that uses the RichTextBox WinForms control to do the
heavy-lifting:
public static string ConvertRTFToText(string RTF)
{
RichTextBox richTextBox = new RichTextBox();
richTextBox.Rtf = richText;
return richTextBox.Text;
}
6. Compile this assembly, and deploy it to your ReportServer folder or
the GAC
7. Reference the Assembly from the Report and call this method.
The result is a text version of the RTF. It will not include any
formatting, embedded pictures, or markup, however the text will show up
just fine. I use this approach with J.D. Edwards XE One World software
because they have a "Media Objects" table containing key information
input by the users.
Note: This approach is a bit of a hack because of its abuse of the
RichTextBox control. Another route would be to buy or find an RTF
Conversion class library so you don't have the overhead of the windows
forms control.
Hope this gives you another option.
Lance
http://www.lance-hunt.net/|||Lance,
Thanks for the reply. The RTF string if converted to text is useless to me
as it loses its formatiing.
Can we parse it to html and display it?
Afaq Choonawala
"Lance" wrote:
> Actually you can, but it requires code in an external assembly.
> Here is one option:
> 1. Create a ClassLibrary project in C# or VB.NET.
> 2. Add a reference to the System.Windows.Forms.dll
> 3. Create a class such as ConversionUtility
> 4. Add the appropriate import/using statement using
> System.Windows.Forms; to your class.
> 5. Create a method that uses the RichTextBox WinForms control to do the
> heavy-lifting:
> public static string ConvertRTFToText(string RTF)
> {
> RichTextBox richTextBox = new RichTextBox();
> richTextBox.Rtf = richText;
> return richTextBox.Text;
> }
> 6. Compile this assembly, and deploy it to your ReportServer folder or
> the GAC
> 7. Reference the Assembly from the Report and call this method.
> The result is a text version of the RTF. It will not include any
> formatting, embedded pictures, or markup, however the text will show up
> just fine. I use this approach with J.D. Edwards XE One World software
> because they have a "Media Objects" table containing key information
> input by the users.
> Note: This approach is a bit of a hack because of its abuse of the
> RichTextBox control. Another route would be to buy or find an RTF
> Conversion class library so you don't have the overhead of the windows
> forms control.
> Hope this gives you another option.
> Lance
> http://www.lance-hunt.net/
>|||Not likely. Any HTML would end up encoded so it would only show the
literal HTML tags on the page.
At this point, I'm out of ideas. Frankly the only other options are a
bit too extreme and painful. Such as writing your own custom
RenderingExtension so that it will "properly" handle your RTF. Even
with this approach it would be a chore.
Good luck...
Lance