I have an SSRS 2008 report with a field that contains and is configured to render as HTML. Some of the text in this field may contain IMG tags, and the IMG tag is not among the tags SSRS natively supports within its HTML rendering extension.
I am trying to find a way to write a custom handler to hook into the processing of this field that will let me look at the raw HTML before the SSRS handler processes it, in the hopes of grabbing IMG tags, extracting the SRC URL and getting the raw bytes of an image to insert on the fly in a way SSRS will accept, yet retaining the HTML SSRS will render.
From what I've read and seen so far, if a field is marked to render as HTML, the SSRS processor grabs it and parses it entirely before any handler could modify it, meaning the IMG tag is (would be) discarded before I could do anything with it (or even know it was present). The only option I see is to turn off the HTML rendering entirely, thus losing the benefit of the tags SSRS can recognize.
EDIT: Per Jamie's response below, I'm beginning to think the "2nd half" of this issue may prove harder than I realized: Is it even possible to programmatically add an Image to an SSRS Report at runtime (obviously through code/custom assembly)? That is, I'd like to write some code that might look something like this (pseudocode)
'Conceptual Pseudocode I'd like to be able to write
'for dynamic addition of Image element in SSRS report
'Is this even possible?? Is there a documented Report
'object model??
Public Function AddImage(imageBytes() as Byte) as Image
Dim newImage as New Image()
newImage.SetBytes(imageBytes)
Report.Add(newImage)
return newImage
End Function
I'm hoping I'm just overlooking something simple that prevents me from grabbing the raw, unprocessed HTML, and someone else might be able to point me in the right direction on how to grab it.
EDIT: I have created and implemented this solution within the SSRS development environment and it works. WOOHOO :) It did require some hoop-jumping with creating a Single-Threaded Apartment thread to host the WebBrowser control, and to create a message pump, but it does work! **
As I was literally typing up the message to a co-worker that this issue was a non-starter, I did have a bit of an inspiration on a way to solve this problem. I know this post hasn't generated a great deal of response, but just in case someone else finds themselves in a similar problem, I'm going to share what I've implemented in a "petri dish" scenario that, provided I get all the code permission issues resolved, should allow me a decent solution to this problem.
With SSRS inability to handle an IMG tag insurmountable, I actually thought of an idea that took the HTML rendering away from SSRS entirely. To do this, I created custom code that hands off the HTML rendering to a WebBrowser control, then copies the rendered result as an image. It does the following:
Instantiates a WebBrowser control of a given width and height.
Sets the DocumentText property of that control to the HTML from TinyMCE
Waits for the DocumentText to completely render.
Creates a bitmap equal to the size of the control.
Uses the undocumented and presumably unsupported DrawToBitmap method of the WebBrowser to draw the rendered HTML to a bitmap.
Copies the Bitmap to an Image
Saves the Image as a .png file
Returns the path to the .png as the result of the function.
In SSRS, I plan to replace the erstwhile HTML text field with an external Image control that will then call the above method and render the image file. I may alter that to simply draw the image to the SSRS Image control directly, but that's a final detail I'll resolve later. I think this basic design is going to work. Its a little kludgey, but I think it will work.
I have some permissions issues to work out with the code that SSRS will allow me to call at runtime, but I'm confident I'll get those sorted out (even if I end up moving the code to a separate assembly). Once this is tested and working, I plan to mark this as the answer.
Thanks to those who offered suggestions.
I've done something similar with success: We had an HTML "Comment" field that was collected on a web form. For a particular report we wanted to truncate this field to the first 1000 characters or so, but preserve valid HTML.
So I created a C# .dll & class with a public function:
public static string TruncateHtml(string html, int characters)
{
...
}
(I used the HtmlAgilityPack for most of the HTML parsing, and to create and close off my new HTML string, while I kept track of the content length.)
Then I could call that code with the fully qualified path to the function in an SSRS expression:
=ReportHtmlHandler.HtmlTruncate.TruncateHtml(Fields!Comment.Value, 1000)
I could have added a calculated field to my dataset with this, but I was only using this value for one field, so I kept it at the field expression level.
All of this code gets called well before the HTML is processed or rendered by SSRS. I'm sure that any original IMG tag will be in the string.
This approach might work for you, possibly create a ExtractImg function which could be set as the source of an img on the report. I think some of the tricky bits for your requirement will be to handle multiple images as well as embedding the extracted img. But you might be able to do this simply with a external reference to an image. I haven't done much with external images in SSRS.
An MSDN blog entry on calling a custom dll from SSRS: http://support.microsoft.com/kb/920769
Related
According to this Microsoft dev guidance, it should be possible to have a element on a web page do a POST via the method=POST attribute of the form. It shows an example of HTML needed in order to open a report viewer to a report and render the HTML viewer. I have that working. I would like to use the exact same technique to create a PDF or Excel file, but it doesn't work when I update the Format parameter to either PDF or EXCELOPENXML. Instead it ignores that parameter and provides the HTML viewer anyway. I would like to stick to one technique for both opening the HTML viewer and for downloading the various file formats. Does anyone know a workaround? I have considered a generic function to take the hidden elements and tack them on to the action URL, and open a new window with that. Does anyone have the code to do that?
I would still be curious to know if there's an issue with the POST action for file exports, but in the meantime, I solved it with this:
$("form").find(":input[name]").map(function(val, key) {
return encodeURIComponent($(this).attr('name'))
+ '='
+ encodeURIComponent($(this).val()).replace(/%2C/g,',').replace(/%20/g,' ');
//unencode space and comma characters for convinience and shorter URLs
}).get().join("&")
I'm making a form letter in SSRS 2012 that will be delivered by email. I had it working fine but now the powers that be have requested a much more dynamic aspect to it based on the individual recipient... Different paragraphs now need to be included/excluded based on the target.
With that, I pulled the body of the email out of SSRS and am now assembling it in SQL Server and passing it over to SSRS as a parameter (so that I don't wind up making a dozen SSRS reports to handle the need).
I have that part working too now, but hit a snag... There were a few bullet points as well as URL's that could look nicer. I'd like to force an indention before the bullet points and replace www.mysite.com with something prettier like "Click Here". On the SSRS side of the fence, I currently just have a single text box (and ideally would keep it that way) which contains an expression that references my "EmailBody" parameter.
So far, I have not found the right combination of words to send to Google to see if this is possible, so I figured I'd go straight to the pros here. I did try formatting the output in a similar manner to what an expression would look like ( ="This is the body of my email" ) and it just passed that straight on through to the final output.
Any ideas would be appreciated!
Jason
In case it helps anyone else, I figured out the secret.
Change your text box in SSRS to expect HTML by right-clicking on the placeholder (<< EXP >>) inside the text box, selecting Placeholder Properties, and change the Markup Type to "HTML - Interpret HTML tags as styles".
After that, go back to the SQL Server side of the fence and change the text you are sending as a parameter to HTML with whatever styling properties you desire.
Sounds like you're on the right track with the HTML markup. I also wanted to suggest that you can use a data-driven subscription. Have the query generate the HTML you want. Then have that populate the body of the email. That way there's no need for any attachments. This has come in handy when I wanted to display a small table of data for viewing on a mobile device rather than having to open an Excel attachment.
We have a web application that creates a web page. In one section of the page, a graph is diplayed. The graph is created by calling graphing program with an "img src=..." tag in the HTML body. The graphing program takes a number of arguments about the height, width, legends, etc., and the data to be graphed. The only way we have found so far to pass the arguments to the graphing program is to use the GET method. This works, but in some cases the size of the query string passed to the grapher is approaching the 2058 (or whatever) character limit for URLs in Internet Explorer. I've included an example of the tag below. If the length is too long, the query string is truncated and either the program bombs or even worse, displays a graph that is not correct (depending on where the truncation occurs).
The POST method with an auto submit does not work for our purposes, because we want the image inserted on the page where the grapher is invoked. We don't want the graph displayed on a separate web page, which is what the POST method does with the URL in the "action=" attribute.
Does anyone know a way around this problem, or do we just have to stick with the GET method and inform users to stay away from Internet Explorer when they're using our application?
Thanks!
One solution is to have the page put data into the session, then have the img generation script pull from that session information. For example page stores $_SESSION['tempdata12345'] and creates an img src="myimage.php?data=tempdata12345". Then myimage.php pulls from the session information.
One solution is to have the web application that generates the entire page to pre-emptively
call the actual graphing program with all the necessary parameters.
Perhaps store the generated image in a /tmp folder.
Then have the web application create the web page and send it to the browser with a "img src=..." tag that, instead of referring to the graphing program, refers to the pre-generated image.
I have graphs in an html page. The graphs are generated by a call to a cgi-bin program in an IMG tag:
<IMG src="http://myserver.com/cgi-bin/StatBarChart.cgi?data=1,2,&data=3,5,1&legend=EC,ER">
Currently, the data for the graphs is passed as GET args (in the URL itself.)
Everything’s working OK, but te GET arguments are too long. I want to pass the data via POSTDATA. All the books I have (and discussions on the web that I’ve found) talk about using POSTDATA in forms that include a Submit button. I just want the graphs to appear as part of the page, without a Submit. Can this be done? Can it be done in HTML4, or does it require javascript?
I would require javascript, as you would have to get the resource yourself and set it to the img tag. This is not possible in html4.
Also, I don't see the problem with a long url. Your user will never see it (unless he looks in the sourcecode, which I don't consider as simple "user" anymore) so there is no problem with that either.
I've got an MS-Access app (1/10th MS-Acccess, 9/10ths MS-SQL) that needs to display photographs of some assets along with their specifications. Currently the images are stored in an MS-Access table as an OLE Object (and copy-n-pasted into the field by the users).
For various reasons, I would like to do is store the original .jpgs in a folder on the network drive, and reference them from the application portion. I have considered moving into MS-SQL's image data type (and its replacement varbinary), but I think my user population will more easily grasp the concept of the network folder.
How can I get MS Access to display the contents of a .jpg?
Another option is to put an image control on your form. There is a property of that control (Picture) that is simply the path to the image. Here is a short example in VBA of how you might use it.
txtPhoto would be a text box bound to the database field with the path to the image
imgPicture is the image control
The example is a click event for a button that would advance to the next record.
Private Sub cmdNextClick()
DoCmd.GoToRecord , , acNext
txtPhoto.SetFocus
imgPicture.Picture = txtPhoto.Text
Exit Sub
End Sub
Have you looked at Stephen Lebans' solutions? Here's one:
Image Class Module for Access
Check out the list of other great code along the left-hand side of that web page. You may find something that fully matches what you need.
I found that this article by Microsoft with full VBA worked very well for me.
How to display images from a folder in a form, a report, or a data access page
The easiest way is probably to plop an Internet Explorer onto one of your forms. Check out this site: http://www.acky.net/tutorials/vb/wbrowser/
Since you can reference that object in Access, you will only need to point the webbrowser control to the path of the .jpg (NavigateTo() if I remember correctly).
EDIT: The above link was just googled and picked from the results (first one that opened quickly). I do not think it is a very good tutorial, it just has all the pointers you need... Check out msdn etc. if you need more information!
You can try an ActiveX control called AccessImagine, makes adding images to database more convenient - you can load from file, scan, paste from buffer or drag-n-drop. You can crop image right inside the database and resample it automatically. It handles external image storage automatically if you need it.
Note that in Access 2010 (and later) this is dead simple to do because the Image control can be bound to a field in the table that contains the path to the image file (.jpg, .png, ...). No VBA required.
For more details see my other answer here.
Do you mean something like this?
Display images in MS-Access Form tabular view.
Here's the original post from microsoft:
https://learn.microsoft.com/en-us/office/troubleshoot/access/display-images-using-custom-function
You just need to modify something in the form events:
Modify this part of the form code
Image Control
Name: ImageFrame
Picture: "C:\Windows\Zapotec.bmp"
Control Source: txtImageName
Note that the Control Source named "txtImageName" is the field name in your table which has the name and path of your images.
Everything get's fine after you modify that part.