Convert HTML To Image in .NET Core - .net-core-2.0

Heading ##I want to convert HTML code to Image(png/jpg) on Web Server and then send image link in email in my .NET Core application. I don't want to purchase any third party library like NReco or EVo.
Is there any other way to convert HTML To Image in dotnet core 2.0?

I use net-core-html-to-image library that embeds wkhtmltoimage tool. The library is very simple to use. There is a nuget package:
Install-Package CoreHtmlToImage
If you want to convert HTML string to image:
var converter = new HtmlConverter();
var html = "<div><strong>Hello</strong> World!</div>";
var bytes = converter.FromHtmlString(html);
File.WriteAllBytes("image.jpg", bytes);
Or for URLs:
var converter = new HtmlConverter();
var bytes = converter.FromUrl("http://google.com");
File.WriteAllBytes("image.jpg", bytes);

I know this is old but I wanted to save some from headaches if you come across it. The wkhtmltopdf.exe file that this uses, uses an older rendering engine. I had to go all the way back to bootstrap v2 to make it render correctly.

There are number of free libraries on web to convert HTML to image/PDF/other formats.
I prefer TuesPechkin dll to export to image/pdf.
For image you need to use wkhtmltoimage dll. You can go through below links:
https://wkhtmltopdf.org/
Below is the Github link. You can find more details here:
https://github.com/tuespetre/TuesPechkin

Sharing you the solution, which might helps to others
I used wkhtmltopdf.exe and it worked.
Following post helped me
https://beeming.net/just-coding/2017/5/converting-html-to-pdf-using-c-and-magic

Related

Problem rendering µ and ³ with MigraDoc (PdfSharp) in Azure

I'm rendering a PDF using MigraDocCore, when I run my app locally these symbols render correctly:
But when I run it in Azure App Service the symbols are missing:
My default Style is defined as
Style style = Document.Styles["Normal"];
style.Font.Name = "Arial";
style.Font.Color = Colors.Black;
style.ParagraphFormat.SpaceAfter = Unit.FromMillimeter(5);
Why are these symbols not rendering correctly in Azure and how can I fix it?
---- Edit:
I've just noticed as I post this that the one of the m³ is rendering correctly in Azure, while others aren't.
The difference here is that the one's not working are hard coded strings while the one that does work is going through the Localizer.
e.g.
var tf = section.AddTextFrame();
// This works
var str = L("m³");
var para = tf.AddParagraph(str);
// This doesn't work
var para = tf.AddParagraph("m³");
If I check the character code of the hard coded ³ and the one in my localization json they're both char 179.
The only difference I can see here is the json file is UTF-8 without the BOM, while the .cs file is ~~UTF-8 with a BOM~~ Western European. (This is probably going to be the issue).
I've saved the .cs file as UTF-8 without the BOM and will report back...
To solve this problem, need to use the below steps:
Install the WPF build of PDFsharp 1.50 beta 2 from NuGet
Use a Font Resolver to select the font Using private fonts with PDFsharp 1.50 beta 2 or MigraDoc
Add the unicode font as an embedded resource in the project.
The similar type of font issue in PDFSharp refer here

CR2 Preview generation with Node.JS/Electron

I want to build a Node.JS/Electron ApplicationCache, that can show Previews for the following filetypes: DNG, CR2, JGP, TIFF.
I have accomplished all of that using an external library. Except for CR2.
I cant find anything (free) that can generate a preview image for CR2-Files and does not require installing exiftools or imagemagick on the machine. Does anybody have an idea waht it can use?
The solution to this problem is: dcraw

Skia buggy color blending

I'm using Skia m62 with Open GL backend and getting the glitch while rendering png file.
To create SkBitmap I'm using the following code:
const auto codec = SkCodec::MakeFromStream(SkStream::MakeFromFile("test.png"));
const SkImageInfo imageInfo = codec->getInfo().makeColorType(kN32_SkColorType);
SkBitmap bm;
bm.allocPixels(imageInfo);
codec->getPixels(imageInfo, bm.getPixels(), bm.rowBytes());
The rest of the code is slightly modified (cannot find gl/GrGLUtil.h header) example found in Skia sources: https://github.com/google/skia/blob/master/example/SkiaSDLExample.cpp
The library is built with arguments: skia_use_freetype=true skia_use_system_freetype2=false skia_use_libpng=true skia_use_system_libpng=false skia_use_expat=false skia_use_icu=false skia_use_libjpeg_turbo=false skia_use_libwebp=false skia_use_piex=false skia_use_sfntly=false skia_use_zlib=true skia_use_system_zlib=false is_official_build=true target_os="mac" target_cpu="x86_64"
Here is the FULL EXAMPLE on GitHub illustrating the issue. It contains the png under observation and full setup to run on Mac OS x86_64.
UPD: Filed a bug in Skia tracker: https://bugs.chromium.org/p/skia/issues/detail?id=7361
I'll quote the answer from Skia's bugtracker:
Skia's GPU backend doesn't support drawing unpremultiplied images, but that is the natural state of most encoded images, including all .pngs. What you're seeing is an unpremultiplied bitmap being drawn as if it were a premultiplied bitmap. Pretty isn't it?
There are a couple easy ways to fix this. The simplest way to adapt the code you have there is to make sure to ask SkCodec for premultiplied output, e.g.
const SkImageInfo imageInfo = codec->getInfo().makeColorType(kN32_SkColorType)
.makeAlphaType(kPremul_SkAlphaType);
Or, you can use this simpler way to decode and draw:
sk_sp img = SkImage::MakeFromEncoded(SkData::MakeFromFileName("test.png"));
...
canvas->drawImage(img, ...);
That way lets SkImage::MakeFromEncoded() make all the choices about format for you.
This solves the issue.

android use the camera app and private storage

I am trying to use the sample code at
https://developer.android.com/training/camera/photobasics.html
to take pictures that WILL NOT show up in gallery or get shared. Google's example missed this part of the demo.
I followed the example: My code is at:
https://github.com/tomha2014/SecureCameraIntent/tree/master
Failed to ensure directory: /storage/sdcard1/Android/data/thackbarth.com.securecameraintent/files/Pictures
I have all the read/write external permissions in the manifest.
Make sure folders in this path exist.
thackbarth.com.securecameraintent/files/Pictures
YEA! I found it
In the google sample code found at
https://developer.android.com/training/camera/photobasics.html
There is a line of of code that looks like:
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
That create a file uri, the bitmap decode:
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
Wants a path to the file Take off the "file:" and it it works.....
That was a lot of hours wasted, if Google would have just provided that code in the sample linked to that page.
In any case, I am working on a sample that uses that code for Android 6
can be found at:
https://github.com/tomha2014/SecureCameraIntent

Using JavaScript API commands in ActionScript file

I am new to actionscript and jsfl programming. I am using Adobe Flash Professional CS5.5 and windows 7 operating system. I am trying to execute Javascript API commands in my .as file using the MMExecute() function. When publishing the swf file the statements before and after the 'MMExecute' statement are getting executed but the Javascript command string I am using in the MMExecute function doesn't seem to get executed. I am using a basic JSFL command to just trace to the output window in flash. Also, I am publishing the swf file to the WindowsSwf folder present in the Configuration folder. The fla file I have is a blank file with nothing added to it and the code I am using is as follows.
import flash.display.*;
import flash.text.*;
import flash.external.*;
import adobe.utils.MMExecute;
var str:String=new String();
str='fl.trace("Working..");';
MMExecute(str);
Please help me out.
Thanks in advance.
I'm not a real JS programmer, just an artist who got into JSFL, but:
var str:String=new String();
seems odd to me. I don't typically declare var types in JSFL.
(no idea if that's common or I'm just sloppy.)
I would typically just write
var str='fl.trace("Working..");';
it is also possible you may need to escape the first semicolon.

Resources