Is there a way to write PDF to a div from DataBase i.e. Retrieve a Byte[] from Database and Reponse.BinaryWrite to a div.
We do similar thing for Images using src = "anotherpage.aspx" where image is written on anotherpage.
Is it possible with PDF without using IFrame?
If what you're trying to do is show a PDF file inside a DIV, you're going down the wrong path. You either need to:
Convert the PDF to Flash (ala Flash Paper)
or
Convert the PDF to HTML (like Scribd does using HTML 5).
Then you can embed the PDF inside a DIV. But no browser I know of supports directly embedding PDFs.
Otherwise you have to put the PDF in an IFRAME, but how this is shown is PDF plug-in dependent.
No. The reason it works with a src=otherpage.aspx request is that the src attribute results in the user's web browser making a completely separate request for the other resource. You're serving up an additional page to make that happen. Writing a PDF file directly is trying to inject the PDF into the same request as your page - not really "similar" to your img src at all. In fact, what is most similar to the "src=otherpage.aspx" method is the iframe approach that you mentioned.
As a side note, you our "AnotherPage.aspx" example should really be changed to "AnotherPage.ashx". Note the letter 'h' in there. That means you're using a handler rather than a page, which will perform better.
Related
I have a FileUpload control in my aspx page and I want to display the image selected before postback so that user confirms the image to upload.
You can use this AJAX Control Toolkit Control for Image Confirmation.
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AsyncFileUpload/AsyncFileUpload.aspx
What you're looking for would require a pure client-side solution, which I do not think is possible since they do not have access to the file system(under normal circumstances).
Note that using AJAX requires actually sending the file to the server first.
This Can be done VIA HTML5 now,
http://www.html5rocks.com/en/tutorials/file/dndfiles/
When the upload is selected you want to read the file with
readAsBinaryString
Then you would need to turn that binary to Base64 so you could display it on the page,
http://www.webtoolkit.info/javascript-base64.html
Then you will need to put it into an img tag on the in the src E.G
<img src="data:{image/mime_type};base64,{base64_binary_data}" width="100" height="100" />
Where {image/mime_type} is the mime type of the image they have uploaded E.G image/png, image/jpg
And {base64_binary_data} is the readAsBinaryString after it's gone though the base64 conversion
It's not possible through HTML. But it may be possible using flash/silverlight.
I say this because I remember coming across an issue when I wanted to know up front how big a file was before the user uploaded it. Html doesn't give you the ability to know this, the user must upload the whole file before you can say how big it is.
However, the workaround was to use flash because flash seems to have permissions to grab data about a file from the local disk before sending it to the server (after the user selects the file of course). Since it can grab the filename, size, etc then I imagine you'll be able to grab the image data too and then display it.
You're going to need to use flash or silverlight to do that.
Here's an article where it's explained how to do that with flash:
http://blog.flexexamples.com/2008/08/25/previewing-an-image-before-uploading-it-using-the-filereference-class-in-flash-player-10/
I am trying to obtain html from the WebBrowser control, but it must include the value attributes of input elements on the page as well.
If I use webBrowser.DocumentText, I get the full HTML of the page as it was initially loaded. The input field values are not included.
If I use webBrowser.Document.Body.OuterHtml, I get the values, but not the other contents of (), which I need so I can get the stylesheet links, etc.
Is there a clean dependable way to obtain the full HTML of the DOM in its current state from the WebBrowser? I am passing the HTML to a library for it to be rendered to PDF, so suggestions for programmatically saving from the WebBrowser control to PDF will also be appreciated.
Thanks
There are some undocumented ways (changing registry, undocumented dll export) to print the document to XPS or PDF printers without parsing the page, that is, if your can afford to roll out required printer drivers to your customer's network.
If you want to parse the web page, documentElement.outerHTML should give you the full canonicalized document, but not the linked image, script or stylesheet files. You need to parse the page, enumerate elements and check element types and get resource urls before digging the WinInet cache or downloading for additional resources. To get the documentElement property, you need to cast HtmlDocument.DomDocument to mshtml.IHTMLDocument2 if you use Windows Forms, or cast WebBrowser.Document to mshtml.IHTMLDocument2 if you use WPF. If you need to wait before the Ajax code finishes execution, starting a timer when the DocumentComplete event is raised.
At this stage, I would parse the HTML DOM and get the necessary data in order to generate a report via a template, so you always have the option to generate other formats supported by the report engine, such as Microsoft Word. Very rarely I need to render the HTML as parsed, for example, printing a long table without adding customized header and footer on each page. That said, you can check Convert HTML to PDF in .NET and test which one of the suggested software/components works best with your target web site, if you do not have long tables.
I have a web app that displays the profile of over 600 people, and each profile displays a word cloud. the word cloud is rendered using html.
The client has requested that the same word cloud to appear in an excel macro that pretty much does the same thing as the web app.
I have seen a few solutions that saves image from rendered page but is there a way to create images from the html programatically, without selecting each of the 600 profiles manually.
Since rendering html is a browser's job, you could take a look at doing it by javascript.
Write a nice little program in jQuery (or your favorite js framework) that renders the word cloud of every profile on a canvas, and then use this:
http://www.nihilogic.dk/labs/canvas2image/
to take an image of the rendered html.
I know it has been a while since I asked this question but I'll answer it for the benefit of others. I ended up using something called IECapt to capture rendering of a web page into a BMP, JPEG or PNG image file;
http://iecapt.sourceforge.net/
I then wrote a unit test to iterate over the various urls, passing it as an argument to the IECapt utility. Was able to render over 600 images in a few seconds.
On the server that my application is being run on, a virtual PDF printer is being installed (don't know much about this yet, except it's from Adobe), and my application needs to use this 'printer' to create PDF's from HTML pages (a GridView mostly), and then redirect the user to the URL of the where the PDF is stored.
I've been looking at the PrintDocument object in System.Drawing.Printing, however I've read that you can't simply feed this a HTML page. What are my choices? The easiest option would be to be able to 'print' a given HTML page (choosing what and what not to print using CSS), but from what I've read this is fairly difficult, so I'm thinking about somehow constructing whatever object PrintDocument needs programatically, if that makes sense.
Any ideas on how I should do this?
there are some free/cheap libs for creating pdfs on the fly. I've used itextsharp before and it worked pretty well. Takes a bit of time to get up to speed in how it works but I'd suggest checking it out.
There are also printing services like Neevia DocConverter that will monitor a folder and auto convert whatever you put in the folder to a pdf, jpg, etc. you can set it up so that if you drop a url shortcut in the folder it will render the webpage at that url to pdf. it's a bit more of a pain if you want to do realtime rendering but works excellent for generating mass reports in batches that you want to post up to a website or email later.
How do I save an HTML page with all styles and images in C#? I need to make a programmatic implementation of a browser's 'Save' feature which doesn't rely on Internet Explorer (WebBrowser component).
I do not think this is very easy.
Download all the HTML for the page using webclient and write the text to an HTML-file. Then use an html-parser to find all linked images and save them in their sub-directory. Do the same for the CSS.
If you do not want to save all the images you can just add the URL of the page to the beginning of all links to images. Also, note that some URL:s are not relative and you will have to compensate for that. And don't forget to scan the css-file for all linked images
I have a similar thing to solve. Biggest problems for you will be the images that come from CSS, they are very difficult to parse.
So, I chose to use FiddlerCore to achieve that.
Might help you too.
The difficult part of your task is to create your own structure, and change image paths accordingly.