VB.NET WebBrowser Object Captures Remote Web Page At Low Resolution - asp.net

Background
I have an ASP.NET web application with a VB.NET back end. In this application users can create payment requests which must be approved by a manager before they are sent to accounts payable for further processing. Within my request page (the page where the user enters the request information) I have a button that links to a separate .aspx page which provides a print preview of the request. When the request is approved by all of the required approvers, I have a VB.NET function that contains a WebBrowser object that navigates to the print preview page behind the scenes and takes a snap shot of it, then saves it as a .tiff file to an internal file share which is then picked up by a internal process and imported into another internal application called OnBase to go through processing for accounts payable.
The Problem
My problem is that when the my function takes the snap shot of the print preview page, the saved tiff has a lower resolution than desired. In other words, it looks kind of crappy when it is viewed through OnBase and when it is printed out.
The Question
How do I increase the resolution of the generated .tiff file at the time that the snapshot of the webpage is generated?
The Code
Private Sub CaptureWebPage()
Try
Dim tiffFileName As String
tiffFileName = OnBasePath & "CheckRequest_" & CurrentRequestId & ".tiff"
Dim impersonateCode As New AliasAccount("TheUsername", "ThePassword")
impersonateCode.BeginImpersonation()
Dim browser As Windows.Forms.WebBrowser = New Windows.Forms.WebBrowser
browser.ScrollBarsEnabled = False
browser.ScriptErrorsSuppressed = True
browser.Navigate(OnBasePath & htmlFileName)
While browser.ReadyState <> Windows.Forms.WebBrowserReadyState.Complete
System.Windows.Forms.Application.DoEvents()
End While
System.Threading.Thread.Sleep(1500)
browser.ClientSize = New Size(950, 768)
Dim Height As Integer = browser.Document.Body.ScrollRectangle.Bottom
browser.ClientSize = New Size(950, Height)
Dim bmp As Bitmap = New Bitmap(browser.Bounds.Width, Height)
browser.DrawToBitmap(bmp, browser.Bounds)
If File.Exists(tiffFileName) Then
File.Delete(tiffFileName)
End If
If File.Exists(OnBasePath & htmlFileName) Then
File.Delete(OnBasePath & htmlFileName)
End If
bmp.Save(tiffFileName.ToString(), ImageFormat.Tiff)
bmp.Dispose()
impersonateCode.EndImpersonation()
Catch ex As Exception
Throw
End Try
End Sub
Additional Information
I have tried to use the .SetResolution method of my bitmap object, but it doesn't actually change the resolution of the generated .tiff file. I have tried to Google this numerous times find a solution, but haven't found anything useful.
Thanks In Advance

Screen "resolution" is much lower than print "resolution". Typically desktop monitors are around 100ppi, where a normal printer on a desk might be 600dpi.
The only suggestion I have for getting a higher resolution rendering of the web page would be configure what is grabbing the screenshot to use a resolution 3x what you are using now, and then set its zoom to 300%. Text elements and vector graphics will be rendered smoothly. Images will still be their web resolutions, and you may even lose image quality through interpolation when sizing up.

You could try and print the page to a virtual print driver in PDF format. I have found OnBase sometimes does strange things with image files, it doesn't like colour or grey scale TIFFs. Instead use JPEG for colour / grey scale.

Related

Buffering a New url which is navigated on other page using tosca in run time

There is an website called X, When u click on the particular button from website X, it navigates in another tab with new url & i want to buffer that new url at run time. How to do in tosca?
I was able to successfully buffer a URL from IE. Here's how I did it.
First, I found this article on tricentis: https://support.tricentis.com/community/article.do?number=KB0015575
Following the instructions in that article, I scanned a new module for IE itself by selecting UIA during the scan (in the article). I captured the editbox of the URL bar as a module element.
Then, in a test case, I just used action-mode Buffer to read and store the URL into a buffer.

Need change compression of images stored in SQLite database with XOJO but getting error during process

I have a table that stores instruction book pages.
while working on the app and finished adding an instuction book, I found that that the table was over 200MB, however the PDF containing the pages was only 70MB 438 Pages.
The problem is that it saves the images as max quality. now i want to make a script that goes over every record opens the images and saves it again as medium compression.
I've made a record set and a loop to go through each record to change the compression, but but the app crashes half way the process.
No matter how i Change the code, it always crashes.
So i took an other approach and make a for loop of 200 records.
This wend well, but it didn't change the file size of the database???
The runtime error is an UnsupportedOperationException, as shown here:
This is the code:
dim rs as RecordSet
rs=lego.LegoData.SQLSelect("SELECT * FROM Books")
dim resize as Picture
while not rs.EOF
resize = picture.FromData(rs.Field("intructions").StringValue)
rs.Edit
rs.Field("intructions").StringValue = resize.GetData(Picture.FormatJPEG, Picture.QualityMedium)
rs.Update
rs.MoveNext
wend
Somehow it reads NIL after 200 records, but it's not NIL.
The error is not happening every time at the same record, it has its own will?
Any suggestions? I want to build-in a book image compression function as well so people can make the exported manual smaller.
The database file does not automatically get smaller if you remove or compact data inside it. You have to issue the VACCUM command (e.g. with SQLExecute("VACUUM")). You can issue that command only after committing, so first do a SQLExecute("COMMIT"). Or use a SQLite tool such as SQLVue to do that by hand.
If resize.GetData returns nil, it means that it can't read the data as JPEG. Maybe it's not in JPEG data but a GIF or something else. Try loading the data into a string first and look at it in the debugger, using the Binary (hex bytes) view to see what's up with it.
If you get an exception, wrap the code in an try block to keep the app from stopping, like this:
try
resize = picture.FromData(rs.Field("intructions").StringValue)
catch exc as RuntimeException
// The image could not be loaded - let's skip it
rs.MoveNext
continue
end try
I've found a solution to make the code faster, still having the crash
OutofMemorry exception
dim rs as RecordSet
dim pic as RecordSet
rs=lego.LegoData.SQLSelect("SELECT ID, SETID, Page FROM Books")
dim resize as Picture
dim count as Integer = 0
while not rs.EOF
pic = LegoData.SQLSelect("Select ID, Intructions FROM Books WHERE ID = " + Str(rs.Field("ID").IntegerValue))
if pic <> nil then
if len(pic.Field("intructions").StringValue) > 0 then
resize = picture.FromData(pic.Field("intructions").StringValue)
pic.Edit
pic.Field("intructions").StringValue = resize.GetData(Picture.FormatJPEG, Picture.QualityMedium)
pic.Update
if count = 100 then
LegoData.SQLExecute("COMMIT")
LegoData.SQLExecute("VACUUM")
count = 0
else
count = count + 1
end if
end if
end if
rs.MoveNext
wend
LegoData.SQLExecute("COMMIT")
LegoData.SQLExecute("VACUUM")
Before the crash its start updating my images with Nil
like 15 images before it crash

Gzoom subgurim asp.net donĀ“t work

we're using a subgurim gmaps for show to the users maps in a web application in asp.net web forms. Now in the map we're loading a kml and after with information of the database create a polyline that represent a route of a employee.
Using map.GZoom = 15 for example for apply a zoom this don't work, always appear in the same zoom independent of the value. It's strange because when loading the map if you see zooming, but then this is not maintained.
This is the method used in the page load
Private Sub cargarMapa()
Try
GMapTrampas.GZoom = 10 ' Zoom
GMapTrampas.Height = 600
GMapTrampas.enableHookMouseWheelToZoom = True
'Load the kml save in google sites
Dim rutaMapa As String = implementacionMapa.listarRutaMapaGeneral()
GMapTrampas.Add(New GGeoXml(rutaMapa))
GMapTrampas.DataBind()
Catch ex As Exception
End Try
End Sub

log in to a webpage and capture screenshot in vb6

I have a visual basic 6 application that needs to get pictures from a particular website but the problem is that the users have to open the webpage on the browser and log in to the webpage then download the picture and upload it in the vb6 app. Is it possible to have the vb6 go to that webpage and log in and capture the screenshot and save it in a particular folder without opening the browser?
The url opens the login page by default and you have to log in first, to access the picture page, which we just have to take a screen shot and crop it.
Is this possible in pure VB6?
Here is some VERY generic code that will log you into a website. It is basically a matter of finding the controls in the browser document and filling in the correct values. Since you have provided no code to build on it's up to you to fill in all the correct values. This is using Microsoft Internet Controls to add a browser control to a form.
Private Sub Form_Load()
Dim i As Integer
WebBrowser1.Navigate ("http://URL of the page you want to go to")
Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
If InStr(WebBrowser1.LocationURL, "http://targetwebsite/login.aspx") Then
On Error Resume Next
For i = 0 To WebBrowser1.Document.Forms(0).length - 1
' Uncommenting the MsgBox method will display the control names and help find the controls you are looking for
'MsgBox WebBrowser1.Document.Forms(0)(i).Type & ", " & WebBrowser1.Document.Forms(0)(i).Name
If WebBrowser1.Document.Forms(0)(i).Type = "text" Then
WebBrowser1.Document.Forms(0)(i).Value = "user name"
End If
If WebBrowser1.Document.Forms(0)(i).Type = "password" Then
WebBrowser1.Document.Forms(0)(i).Value = "user password"
End If
Next i
' now find and click the submit button
For i = 0 To WebBrowser1.Document.Forms(0).length - 1
If WebBrowser1.Document.Forms(0)(i).Type = "submit" Then
WebBrowser1.Document.Forms(0)(i).Click
End If
Next i
End If
' You should now be logged in and loading the page you want
End Sub

Get updated image in flex image control after changing source not name of file(image)?

I am changing image through flex every time i change it saved into server directory with same name(which i am referring to show). So when i refresh my page my browser didn't send new request to server since it's already in request.so didn't getting new image.Tip:- when i clear browser history it will come with new image
You can try adding an additional time-stamp to the image source each time u make a new request, which would make the request look different for the browser.
Example :
var src:String = "image.png";
src = src + "?" + new Date().getTime().toString();
Since you mentioned that you're refreshing the browser, then I assume that your embedded SWF file will also need to be refreshed.
When you embed your SWF, you need to add a parameter that would be random across all time (i.e. datetime stamp, etc.)
var mySWF = "swf/YourEmbeddedFlashFile.swf?guid=" + rnd();
and declare a js function:
function rnd()
{
return String((new Date()).getTime()).replace(/\D/gi, '')
}

Resources