Convert BitMap Image to string or jpeg - c#

I am trying to convert a Bit map image in my windows 8 app (C#), to a string or a regular jpeg.
I am doing thins because I am trying to print the image in some html.
The image is stored in variable itemImage.
When I try to print in in the HTML using the image tag it doesn't show up.
"<img src=" +itemImage + "/>"
When I print in in the html in shows up as Windows.UI.Xaml.Media.Imaging.BitmapImage
How do I show the Image in the html?

You need to write the image out as a separate file, and then point the <img href=""> tag at that file. Alternatively, set the href to a callback line which calls your program with arguments that cause the program to emit the image data.
OR, you can embed the image data directly in the HTML, but that is a very EVIL hack and you absolutely should not under any circumstances do this. I did not mention this option. :)

Related

Using base64 images in pdfsharp html to pdf conversion

I am trying to embed base64 images in HTML which will then be converted to PNG, normal images work fine but if I set the src to a base64 string is shows the broken image in my pdf:
https://gyazo.com/7c86e05373b165840225e931cf5975c9
Here is an example of an image string I would send, works fine in the html, broken after converting to pdf.
<img id="fmacttcChartPNG-PullUps" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAgMAAACd/+6DAAAAAXNSR0IArs4c6QAAAAlQTFRF7QA07QA0////wRtPhQAAAAF0Uk5TAEDm2GYAAAABYktHRAJmC3xkAAAACW9GRnMAAAORAAAJpwDTb3gUAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH4AoEBBQC2OsgcQAAABBJREFUCNdjYIAC1lDsGAgAIgICHfAWayEAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTYtMTAtMDRUMDQ6MjA6MDIrMDI6MDAcnXh7AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE2LTEwLTA0VDA0OjIwOjAyKzAyOjAwbcDAxwAAACl0RVh0ZGM6Zm9ybWF0AGFwcGxpY2F0aW9uL3ZuZC5hZG9iZS5waG90b3Nob3DkrZ9UAAAAOHRFWHRpY2M6Y29weXJpZ2h0AENvcHlyaWdodCAoYykgMTk5OCBIZXdsZXR0LVBhY2thcmQgQ29tcGFueflXeTcAAAAhdEVYdGljYzpkZXNjcmlwdGlvbgBz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U5ErkJggg==">
Does anyone know if this is supported or have any ideas on the correct direction to proceed on this?
Thanks,
Sam

PDF doesn't wrap text lines automatically & respect line position

I'm trying to generate a PDF via code because not all actual PDF .NET libraries support the new Windows Runtime for Windows/Windows Phone 8.1.
The PDF is saved correctly, with only a bug of stream position count that I can fix easily, but, as you can see, the text doesn't wrap if line is too long.
I tried with PDF NewLine char (\n), but C# automatically convert it in the input string
Also, I can't understand the position of lines or objects to put into the document, because I follow this guide online that talk about a reversing axis disposition (x for height and y for width), but seems I didn't catch the right methodology (I put in my code a constant left position, at 40, and a variable top descreasing value (from 600, I'm not manage now the multipage if the value is less than 0).
This is the code of PDF generated:
http://pastebin.com/ZkZmbJdM
(Sorry if I use Pastebin, but using this editor Code function the code seems to be unformatted for special characters used for it)
Where am I doing wrong?
PDF is a graphical format trying to make you think it's a document format. But nope, it's just like drawing with GDI+ for instance. This is the reason why it can achieve the same rendered output across many platforms/programs/etc as opposed to text flow formats like doc/docx. And also, this is why it can really render anything.
So, as opposed to document formats, it is the responsibility of the program that generates the PDF to get the layout right. Think of it just as if you'd draw with GDI+.
In documents like docx or html, it's the rendering program that has to do the layout work. With such document, you just write text and the viewer will take care of laying it out.
Your PDF library certainly has the necessary code to measure the text length. Maybe even it has some code to provide some layout capabilities. You'll have to use these functions to do the layout.

How to convert Text containing Images into pdf using iText#

I have a richtextbox and by far, i have been successful in converting plain text into pdf using iTextsharp. Now, the situation is, when i copy some text from any source let's say a website and along text, it contains images. Now when i try to convert the content (text + images) into pdf, resulting pdf doesn't show images. I know that there would be some property to be set for the richtextbox or using itextsharp so to have images as well. I also know that we can insert images by giving path to that image but this is not what i want. I want to have plain text along with images while direct conversion from richtextbox to pdf. Forexample i have,![Im resulting pdf i want the same as in richtextbox][1]: http://i.stack.imgur.com/ts0ec.jpg
How can i have the same as in richtextbox? How can i specify orientation for text and image to be justified?

How can I save an HTML string to a Bitmap \ Image?

I made a program that converts an image to ASCII based webpage.
http://postimage.org/image/2pi49sa4k/
That image was rendered using Chrome, on 50% size (miminal).
Obviously, I can make it myself because the code is only based on the FONT tag,
but I believe that it'll make things more complicated, as I'm not too good with graphics etc.
I would like to know how I can convert that string to a Bitmap or Image, with some parameters.(like size etc)
Thank you !

Replace text in PDF

I'm trying to replace a section of a PDF with different text. From research on all major PDF libraries for .NET, it seems this is complicated and not a trivial task. I think it may be easier to convert the PDF to an image, replace the text (always in the same place), then convert it back to a PDF (or leave it as an image if converting back isn't possible). Is it possible to extract an image from a PDF page with .NET?
If your text is in a known location, you can simply cover it with a rectangle filled with the background color, and then draw your text over top.
Note that the text will still be there, it simply won't be visible. Someone selecting text will still pick up the old stuff. If that's acceptable, it's quite trivial.
If the PDF was created from image, you can import it into Photoshop to edit it as an graphic. Or you can use screenshot program like "Snagit" to capture pdf page as image and use snagit's editor to erase old text and replace new one.
But this method may bring you problem is that the new added text may not the same font as text around it. Personally, I use pdf editor to replace text in pdf since the added text will be automatically fit with the original font and size.

Categories