Problem rendering µ and ³ with MigraDoc (PdfSharp) in Azure - azure-web-app-service

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

Related

Convert HTML To Image in .NET Core

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

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.

Deploy and load a picture to use as a texture in a holographic app

I created a sample holographic application in Visual Studio 2015 with C++/CX (or whatever they call that fancy C++ with hats and ref new). It builds, deploys and runs fine, rendering a rotating colored cube, just as it's supposed to. Now I am trying to add a jpeg image and use it as a texture on the cube. The question is, where shall I put the image, how do I add it to the project, how do I make VS to deploy it along with the rest of the project, and how do I load it in my application?
I have literally zero experience with both DirectX and UWP. I've done this tutorial on textures on my desktop Windows 10 (a regular C++ app, not managed, not UWP), although the way they load a file into a texture in the tutorial didn't work for me. After some googling I downloaded this library, built it for desktop Windows 10 (DirectXTex_Desktop_2015_Win10.sln) and used in my project as follows:
DirectX::ScratchImage image;
LoadFromWICFile(L"myimage.jpg", DirectX::WIC_FLAGS_NONE, nullptr, image);
CreateShaderResourceView(d3d11Device, image.GetImages(), image.GetImageCount(), image.GetMetadata(), &CubesTexture);
It worked. Now, for Hololens I built their DirectXTex_Windows10.sln solution (assuming that if the other one was for desktop, this one must be for non-desktop) and tried (unsuccessfully) using it like this:
DirectX::ScratchImage image;
HRESULT hr = LoadFromWICFile(L"ms-appx:///myimage.jpg", DirectX::WIC_FLAGS_NONE, nullptr, image);
CreateShaderResourceView(m_deviceResources->GetD3DDevice(), image.GetImages(), image.GetImageCount(), image.GetMetadata(), &m_cubesTexture);
I also tried ms-appdata instead of ms-appx. In both cases LoadFromWICFile does not return S_OK. It gives ERROR_INVALID_NAME: The filename, directory name or volume label syntax is incorrect. As for myimage.jpg, I put it into the Assets subfolder and added to the solution through Add->Existing Item. Is that enough to get it deployed to Hololens? How do I check if it gets deployed? Where on the device is it going to be located, if deployed?
It seems I over-complicated things.
To add a file like that into a project, simply use right click (on the Assets sub-folder in the solution explorer) -> Add -> Existing Item. To get it deployed on the device or emulator, right click on the file -> Properties, set Content to Yes and Item Type to Image or Does not participate in build (for something that doesn't get recognized correctly, for example, Wavefront .OBJ file, which VS would otherwise try and fail to link).
To check if (and where) the file is going to be on the device or emulator, you can build an actual package: right click on the project, choose Store->Create App Packages... It creates an .appx file, which is actually a zip-archive. You can explore it with an archiver like 7zip, or rename it from .appx to .zip and open with Windows File Explorer. In my case the image file was there, in the Assets subfolder. I was able to read it by its simple relative path, like this (no ms-appx:/// or other such prefixes):
HRESULT hr = LoadFromWICFile(L"Assets/myimage.jpg", DirectX::WIC_FLAGS_NONE, nullptr, image);
For some other functions (std::fopen, std::ifstream etc.) this relative path didn't work, I had to use the full path as follows:
Platform::String^ appInstallFolder = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;
std::wstring folderNameW(appInstallFolder->Begin());
std::string folderNameA(folderNameW.begin(), folderNameW.end());
std::string fname = folderNameA + std::string("/Assets/model.obj");
std::FILE *f = std::fopen(fname.c_str(), "r");
This textured cube project might give you some insight. I think is based on the C# VS2015 Holographic template.
https://github.com/dngoins/HololensDXTutorials

Gifs on Sailfish-os

I came here with a little problem, i can't use any local .gif in my code.
I work on Linux with QtCreator and the Sailfish VM to make a Sailfish-os application.
I tried first this example, without any success.
Rectangle {
width: animation.width
height: animation.height
AnimatedImage { id: animation; source: "../images/animatedimageitem.gif"}
}
The execution return :
QML AnimatedImage: Error Reading Animated Image File file:///bla/bla/.....
Same problem with other permissions on the gif and with an other gif.
After some researches I found this page where someone indicate to download a plugin, but Qt declare (I wish i could put a link but i'm new -_-', see comments) that gifs are already support by default.
The plugin was finally unobtainable and I found this Sailfish/bin/plugins/imageformats/libqgif.so in my directories.
So what can i do to show a gif on this damn thing ?
The error you are seeing is probably related to filepaths. Gifs are supported, AFAIK.
Instead of coding the path that way, consider the usage of a resource file to improve portability and platform independence.
Create a new resource file (File -> New File or project -> Qt -> Qt Resource File)
The property editor opens, click Add in the bottom then Add prefix and set a prefix such as / (or whatever you like!)
Click again to select Add files and insert your image
Right-click the newly added image entry and copy resource path to Clipboard
Build -> Run qmake (fundamental to ensure correct compilation)
The path you copied in the clipboard should be of the form:
://PATH_TO_IMAGE.gif
Now, given your QML code, I can guess the image folder is inside source code at the same level as the QML folder. Hence, if you added the .gif file from that folder you would have the following path in the clipboard:
://images/name.gif
This can be prepended with the prefix to obtain the final path. If your prefix is set to /, as we did above, the final string to be set in the source property of your AnimatedImage would be:
"qrc:///images/name.gif"
Obviously, a different prefix or a different path would result in a different final path.
Well..... I just put it on my phone (Jolla) and the gif works well. So this is the VM who doesn't seems to like gifs ...
Thanks for help though,
Psycho.

TeeChart C# .Net Chart Transparency

I have downloaded the TeeChart for .Net 2012 Evaluation version.
I have worked for 2 days trying to get transparency to work on the pie chart, circular gauge, and line chart. Everything I try does not change the black color.
Here is some of the sample code I have used in my attempt to make it transparent.
pieChart.Series.Clear();
pieChart.Header.Visible = true;
pieChart.Header.Text = "Pie Chart"; //At top on the chart
pieChart.Aspect.View3D = false;
pieChart.Walls.Back.Transparent = true;
pieChart.Walls.Back.Gradient.Visible = false;
pieChart.Panel.Transparent = true;
pieChart.Panel.Gradient.Visible = true;
pieChart.Panel.Brush.Transparency = 50;
pie.Add(10,Color.Red);
pie.Add(15, Color.Green);
pie.Add(10, Color.PowderBlue);
pie.Add(15, Color.DarkGoldenrod);
pie.Add(10, Color.Bisque);
pie.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Percent;
pieChart.Series.Add(pie);
The colors in the slices work as expected. I have tried changing the colors of Palettes, background color, canvas, and wall and nothing seems to work. I cannot find any documentation that give any explanation of what these objects are either to know if I am using each correctly. Please note that in each attempt only 1 was used as a time.
I am exporting the image to a PNG if that makes a difference - both to the stream and to a file. Is transparency a feature of the full version or something that can be done in the trial version? Please confirm as transparent charts are a requirement for our decision to buy this version.
Thanks
PS - It would be nice to also have access to the .Net documentation (The Java version, via the documentation, does not seem to be a direct comparison http://www.steema.com/files/public/teechart/java/v1/docs/JavaDoc/overview-summary.html)
I get a transparent chart using the code you posted in a WinForms application. They key is Panel.Transparent property. You can check that painting the form in a very visible color, eg.:
this.BackColor = Color.Red;
Exporting this chart to PNG also creates a transparent image for me. At run-time you need to set BufferStyle to BufferStyles.None before exporting, for example:
Steema.TeeChart.Drawing.BufferStyle buffer = chart1.Graphics3D.BufferStyle;
chart1.Graphics3D.BufferStyle = Steema.TeeChart.Drawing.BufferStyle.None;
chart1.Export.Image.PNG.Save(#"C:\temp\TransparentWebChart.png");
chart1.Graphics3D.BufferStyle = buffer;
Does this work fine for you? Which kind of application are you developing (WinForms, WebForms, WFP, Silverlight, WP7, etc.)?
Regarding the documentation, both evaluation and registered installerse include help file and tutorials shortcuts at the program group TeeChart entry and also in the Docs folder created by the installer.

Resources