Convert a div and contents inside it to image - c#

I have a DIV container which has some text, background-image, image. I need to convert that whole DIV contents into image and save.
I have googled it around but could not find the perfect answer. some are giving answers that uses a windows application , but i need it on a web platform .
any help will be highly appreciated

From what I understood, you have to do that in the client side, so you should take a look at the toDataURL method of the canvas.
If you don't know, the canvas support text and image.
Example and little library at this link:
http://www.nihilogic.dk/labs/canvas2image/

http://html2canvas.hertzen.com/
Does't support IE though. Looks solid other than that.

This is possible, with modification to the code here http://html2canvas.hertzen.com/screenshots.html you could perform the required screenshot :)

Related

Converting a base64 encoded svg to a png

I am in need of converting a base64 encoded svg to a png and then returning it to the client to be rendered.
The idea is that I am drawing an svg on the client using d3.js and I need to convert it to png.
I tried taking the javascript root and writing the svg on the canvas and then converting it toDataUrl but IE has problems with this on all versions so this is not a viable option.
I have searched online a bit and all I could find is Inkscape.
This is not a viable solution for me because of limited access on the server and frankly I don't think it's a good idea to install an entire application for a simple functionality.
Is there any other solution that can take a base 64 encoded svg and return a png that can be displayed in an image?
I found that since I have to support IE 11 I instead went with canvas to blob to PNG using "canvas-toBlob.js" and "FileSaver.js"
$("#save-btn").click(function()
{
$("#myChart").get(0).toBlob(function(blob)
{
saveAs(blob, "chart_1.png");
});
});
https://jsfiddle.net/mfvmoy64/155
I am facing the same issue, however I been able to render the SVG into an image so your users could right click to download the image or right click on the canvas. There is also Canvg which has a library that appears to work with IE, however it is not accurate for complex SVG and so does not meet my needs. Perhaps it will help you.
I have code in my question that will work in IE, just use the IMG or Canvas object, you do not need to call toDataURI.
Checkout Canvg, it might be of help.
Good luck! If you find a better solution, please let me know. :-)

How to export data in Groupbox into PDF?

I have built a very simple windows form application using C#. But I am stuck here and could not find any help anywhere.
What my simple application does is that it queries out the information in the groupbox which has textboxes labels and buttons. I would like to export or convert the data from in the groupbox into the pdf.
Is there a way to implement that??
Thank you so much in advance~
You may want to have a look at http://www.pdfsharp.com/PDFsharp/. It's a pretty good framework for what you need.
Good luck
There are so many options, following SO Link provides the solution and it is working it seems
convert windows form to pdf file
Other Solution
Use following code to take screenshot
http://www.developerfusion.com/code/4630/capture-a-screen-shot/
Use PDFSharp to save as PDF
there's really a ton of different solutions for this, but you will almost absolutely need a 3rd party library for what you're trying to do. Google around for a pdf library for c#, as there are several.
EDIT: some possible solutions may be PDFjet, PDFsharp,ABCPDF (do note, if this is part of a commercial application, make sure that the licensing allows use for it)

asp.net screenshot

I need to work on a new feature where a user can make a screenshot of the content in the browser via asp.net page and save it automatically as jpeg. Is there a example or someone can give me some idea how I can do that?
I will really appreciate.
Thanks in advance, Lazile
The long and short of it is that you'll need to render the page on the server and take a picture of it. Depending on your format needs, there are a variety of ways to do this.
Here's a link to a tutorial for getting a snapshot in jpg, bmp, png, etc.
If you need to get it to pdf format, I would recommend either using a program like wkhtmltopdf, or using the information from the tutorial and then pasting that image into a pdf.
check this out. It's javascript on the client side. It might meet your needs with some tweaking.
Edit: caveat is that it doesn't work in <IE9 as it uses HTML 5 canvas.

Decoding a PCX image in c# to display as bitmap

I have been trying to create a decoder that will stream through a pcx file and display it on screen as a bitmap. I have managed to get the information from the image header by using a binary reader, but I have now reached the part that seems to take the least amount of code, yet is also the hardest: creating an array of pixels.
I understand that i may need to add two embeddded for loops to process the data. I have looked at some C and C++ examples, but struggle to understand them. I also need to get the array to display it. if you need more code then I will share it.
I have searched far and wide and read the spec, but I don't know how to approach this. If anyone could help me, I would be very grateful.
Regards.
The .NET does not support PCX images natively, you have two choices. Read the specification and decode the image by yourself or use some library.
As suggested on bytes.com you can use Dot Net Fireball (a Free Image wrapper) and load the image like this:
Fireball.Drawing.FreeImage freeImage = new FreeImage(#"c:\test.pcx");
Image image = freeImage.GetBitmap();
http://magick.codeplex.com/
a nice wrapper working with http://imagemagick.codeplex.com/
easy to setup and get going, see samples at the bottom of the page here:
http://magick.codeplex.com/documentation

Image cropping like facebook

For those that have been on facebook it allows you to upload an image to use as your avatar, and if that image is too large you can drag it around in a container to set the co-ordinates of the crop.
Can anyone Help me out to implement this functionality in c# ASP.NET
Probably this will do the job for you
http://webcropimage.codeplex.com/
For writing your own image cropper, study the source code of that.
This will be mostly client-side. You can take a look at something like Jcrop.
the best resource on this issue is here.
http://blog.mironabramson.com/blog/post/2009/04/Cropping-image-using-jQuery%2c-Jcrop-and-ASPNET.aspx
It does not provide exactly what the question asks for but I think Image Resizer is something you should look at.
http://www.imageresizing.net/

Categories

Resources