How to save the second web page in browser using vb.net - javascript

I am opening a new tab in the browser and i want to save the page in html format.
My code is :
Page.ClientScript.RegisterStartupScript(Me.[GetType](), "OpenWindow", "window.open('https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=stack+overflow','_newtab');", True)
Here am opening a new window.Now i want to save the new web page in the html format. Please help me how to save the web page in new opened tab.

If you want to capture the response from a given URL server-side and save it to a file on the server, you can do something like this, using the WebRequest class:
Dim request As WebRequest = WebRequest.Create("http://www.example.com")
Using response As WebResponse = request.GetResponse()
Using reader As New StreamReader(response.GetResponseStream())
Dim html As String = reader.ReadToEnd()
File.WriteAllText("test.html", html)
End Using
End Using

Related

Script File is not executed in PDF file

I am still new to Syncfusion. Currenly I've done a table with a script (document.ready) function to merge the table cells with similar values. The table have been displayed on Google Chrome successfully with my localhost and the columns of the table containing similar values have been merged successfully as well. A function of generating the webpage to PDF works successfully, but the columns of the table displayed on the PDF file do not merge, so I assume that the script file is not rendered in my PDF function.
This is my PDF Function:
private void printpdf()
{
//printpdf
//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = Server.MapPath("~/QtBinaries");
settings.EnableJavaScript = true;
settings.AdditionalDelay = 5000;
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Get the current URL
string url = HttpContext.Current.Request.Url.AbsoluteUri;
//Convert URL to PDF
Syncfusion.Pdf.PdfDocument document = htmlConverter.Convert(url);
//Save the document
document.Save("Output.pdf", HttpContext.Current.Response, HttpReadType.Save);
}
This is my Script Function on aspx file:
$(document).ready(function () {
-
-
-
};
The webKit rendering engine will preserve the PDF document like how the input HTML file displayed on WebKit (example, safari) based web browsers. So, kindly ensure the preservation of your webpage on WebKit based browser. If it is not possible, kindly share with us the complete HTML file (save the webpage from a web browser and share the complete HTML file with styles, scripts, etc.,) to us. So, that it will be helpful for us to analyze and assist you further on this.
If your web page is rendering properly in the chrome browser, kindly try our latest Blink rendering engine for the conversion. It will preserve the output PDF document like how the input HTML is displayed on chromium-based browsers. Please refer below link for more information,
https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/blink
https://www.syncfusion.com/kb/10258/how-to-convert-html-to-pdf-in-azure-using-blink

Data logging issue

I have a web server set up from my arduino and the web page is loaded from it. I use ajax to print the data in the web page.
Similarly I need to store the data in a local pc as a text file. I was successful initially in storing a text file, but the issue is that the data dosent get appended in the same file, there are multiple files created per instance.
Can someone help me in solving this issue. I'm restricted to use only javascript.
client.println("document.getElementById(\"flux_values_1\").innerHTML = this.responseText;");
client.println("var textToSave =[this.responseText]");
client.println("var textToSaveAsBlob = new Blob([textToSave], {type:'text/plain'});");
client.println("var textToSaveAsURL = URL.createObjectURL(textToSaveAsBlob);");
client.println("var fileNameToSaveAs = \"as\";");
client.println("var downloadLink = document.createElement(\"a\");");
client.println("downloadLink.download = fileNameToSaveAs;");
client.println("downloadLink.href = textToSaveAsURL;");
client.println("document.body.appendChild(downloadLink);");
client.println("downloadLink.click();");
Actually you are downloading the file in browser, you cannot append data in a file via browser, you have to do this in backend. Browser will always create a new file and download a new file. This is expected behaviour and cannot be changed.

PDF not working with List Int array passed to Browser

Hi I have a defined variable contentAll from where I am writing to server as a PDF and mailing it to users. They want to see it open in a browser.
Server C# code is as below
List<int> contentAll = new List<int>();
contentAll = [01,02, 03,.....] etc. - Just a sample
byte[] base64EncodedStringBytes = Encoding.ASCII.GetBytes(Convert.ToBase64String(contentAll.SelectMany<int, byte>(BitConverter.GetBytes).ToArray()));
return Ok(base64EncodedStringBytes);
Jquery Code is as below
var pdfWin = window.open("data:application/pdf;base64," + response, "_blank", 'height=650,width=840');
Where response is the returned base64EncodedStringBytes
I am able to write the PDF and send it so no issues with content.
However Chrome is not opening it. The Error in PDF window . Can someone assist

Java Download file from url with download dialog

I want to download a file from a url which initially shows some html, then displays a download dialog after 2-3 seconds. Obviously if I do this:
try {
URL url = new URL("http://my.url");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Content-Length",
Integer.toString(Integer.MAX_VALUE));
con.setReadTimeout(Integer.MAX_VALUE);
con.setConnectTimeout(Integer.MAX_VALUE);
con.connect();
bis = new BufferedInputStream(con.getInputStream(), 4096);
byteArray = IOUtils.toByteArray(bis);
FileUtils.writeByteArrayToFile(new File("myFile"), byteArray);
} catch (Exception e) {
}
I will save the displayed .html rather than the file that is displayed in the save dialog.
How should I change the code in order to do this?
I'm guessing the dialog just has some javascript which waits a couple seconds and requests the file download embedded in the dialog somewhere.
If this is the case, if you figure out what element the 'real download' is contained in, you can use JSoup, or any other html parser library to scrape the link out of the page.
You obviously only have to do that if the download link is generated dynamically.
After doing what rossa suggests, I'd suggest setting javascript breakpoints in the dialog window to figure out how exactly the real url is getting requested.
Are you sure the url is the exact location of the file you want to download? I mean, is there any redirect - you can check in your browser and use HTTP headers extension for instance to check what's going on behind the scene.

Open a new window on response with pdf attachment

jqGrid('navButtonAdd',"#pager2",{caption:"Save All",title:"Save & Create Receipt",onClickButton:function () {
var s;
s = jQuery("#list2").jqGrid('getDataIDs');
alert("selected");
$.ajax({
type: 'POST',
url:'http://localhost:3000/order/receipt',
data: {ids: s},
});
}});
With above code, I'm able to submit data to server and the on server side it will generate a pdf as attachment, now I want to view the pdf on response via a new window/tab on browser.
Anyway to do it?
thanks,
lupind
If you return a URL to the just generated PDF then you can call window.open with that URL. But I wouldn't use an Ajax call if you want to open a new window to display the PDF anyway. In this case I would either:
Use Javascript's window.open passing
through the data in the URL to the
page that generates the PDF and let
it output to the browser's window
(but it might be too much data in the
URL)
Create a special form to hold
the data from your page and submit
that form. This special form would
have a target attribute set
(target="_blank") to open it in a new
window/tab.
For me, using two HTTP calls for one result (the generation and viewing of a PDF) is a waste.
You can use window.open() to open a new window with a specified URL. Be careful, though, only to do this when necessary.
Excerpt from this link.
Use an iframe with visibility:hidden, then change the iframe location to a downloadable file in javascript on the success callback.
var iFrame = document.getElementById('hiddenIFrame');
iFrame.src = theurlThatWillProduceTheFile;

Categories