How does font fallback work on a non-Windows OS? - c#

I have been reading a lot of documentation on how to create an internationalised ASP.NET application, using C# 3.5. They all seem to give the general impression that font fallback and font linking will make font choice a non-issue.
However, the documentation I have seems to imply that it will be fine on Windows, but doesn't mention other OSs, like for the Mac and Linux.
There is no font that supports all characters for all languages, but if your clients are using Windows 2000 or later, it is sufficient to use a single font throughout an application due to font linking and font fallback. This means that your system will determine a font appropriate for the machine's culture. (source)
Will this magically work on a Mac/Linux, or is there some extra legwork involved in supporting these platforms?

If your application isn't producing any sort of documents like PDFs, Excel files or whatnot ASP.Net isn't really responsible for font handling. CSS will be.

For web applications, you have to specify that font fallback yourself, in your CSS files using the font-family directive - documentation for which is available at W3

Related

Usage of CJK font in PDFsharp / Telerik RadPdfViewer

Some background:
I’m developing a WPF application used for measuring and comparing data that’s delivered of a balance attached to it. It will be installed on a Windows 10 system delivered together with the balance. The application currently has to support eleven languages including Japanese and Chinese. One feature of the application is, that the values measured can be shown as a PDF report. For the creation of the PDF we use the PDFsharp library, for displaying the Telerik RadPdfViewer.
As mentioned before the application supports Japanese and Chinese language, therefore the PDF also needs the ability to show Japanese and Chinese letters. Earlier versions of the application were delivered on older versions of Windows, which meant we could use either the Microsoft YaHei or Arial Unicode MS font for this case. Unfortunately PDFsharp does not support TrueType font collections, which means I can’t use the version of Microsoft Yahei installed on the System and Arial Unicode MS is not available anymore.
Problem:
Since these two aren’t an option anymore I searched the internet for an alternative. After a quick search I noticed that Google’s Noto Sans might be what I need, so I tried to use it. Unfortunately it resulted in a ton of IndexOutOfRange Exceptions from the Telerik.Windows.Documents.Fixed.dll (all internally caught by the library) and does not show any letters on the generated PDF. It shows the PDF and the lines of the generated table, so I assume it’s some problem with the font. I used “Noto Sans CJK SC Regular” for Chinese and “Noto Sans CJK JP Regular” for Japanese.
After a long search session I still did not find another suitable font for Chinese. For Japanese I could use “Gen Shin Gothic”, but I’d prefer to use a font with the same style for both languages. There is the additional problem that the font should be usable without an additional license needed.
Unfortunately I can’t add code, since it’s a running project of my employer.
Questions:
Is there something I need to set/adjust for the Noto fonts to work properly?
Is there another usable sans-serif font for Chinese, where no additional licensing is needed? (It has to be capable of showing Latin letters too, since some stuff, like the product name is written that way)
Alternatively:
Is there a tweak to the PDFsharp library, so it can use TTC fonts?
A user posted their changes for TTC support on the PDFsharp forum:
https://forum.pdfsharp.net/viewtopic.php?p=9039#p9039
Another user found a suitable TTF file that works with PDFsharp:
https://forum.pdfsharp.net/viewtopic.php?p=11874#p11874
There is one TTF and its font name is "標楷體".

Print PDF in server side to default printer

I created web application using ASP.NET CORE 2 and used DinkToPdf to create and download the PDF to target directory. It is working really well to create and save PDFs. Now I want to use server side and print the PDF to target printer in the office. I couldn't find any solution to do this. Please help me.
Are you looking to integrate this functionality into your software? If so, there are several PDF libraries on the market with printing capabilities, some more reliable and full-featured than others.
If you're looking for a Windows command line utility to print PDFs to a target printer, you may be interested in PDF2PRINT, which allows you to do exactly that, as well as set optional parameters like duplex, collation, custom page ranges, number of copies, etc.
For future reference, questions like these should be posted in the Software Recommendations forum.

how does font work in windows OS /browser?

I know there are .ttf files.
I'm guessing this is the file that OS uses to display fonts?
Does the browser uses the same font files to display fonts?
If not, where does it stores it's own font files?
what's the difference between the .ttf font and Unicode font?
I mean how/where does Unicode fit into .ttf file format?
Starting with the last question first, asking about the difference between TTF and Unicode Fonts is a bit like asking about the difference between "JPG files" and "Images". One is kind of a version of the other:
A modern .ttf file is not so much a "truetype font" as it is an OpenType font that uses the TrueType format for the part that needs to encode shapes and specify where inside the fonts those shapes can be found. Perhaps surprisingly, that's only a small part of what makes a modern font, and the important part here is that it's an OpenType font, not really that it uses the TrueType format.
The vast majority of modern fonts are OpenType fonts, with two common formats: .ttf for OpenType fonts that use TrueType format, and .otf for OpenType fonts that use the CFF format. There are a few more formats that OpenType can use (bitmaps and SVG, for instance), but you won't run into those a lot.
OpenType fonts also specify which character mappings they support, and they can support multiple mappings: it's entirely possible for a font to support a Unicode mapping as well as Windows-specific and Mac-specific non-unicode mappings, for several different languages, or not support Unicode's mapping, but be able to typeset text in tens of scripts that are also found in Unicode, just using different, unicode-incompatible mappings.
So, on to the first question:
Browsers get their default fonts from the OS. There is a set of "safe fonts" that all Operating Systems come with, and Browsers rely on that set for the default text rendering. Browsers, much like any big application, are compiled separately for each target platform, so they simply know which fonts are available on those platforms, and how to ask the OS for them.
In addition to this, CSS can be used to specify that there is content that needs to be styled by a non-default system font, or even by a font that is explicitly pointed to by a URL (using #font-face rule). For system fonts, the browser will simply ask the OS for the font reference, for fonts-by-URL the browser downloads the font, and then uses that. But, in both cases, only provided that the font passes a few security checks to make sure it's not (sometimes subtly) corrupt or internally inconsistent.

.NET graphic libraries to display images (pdf, .docx and any other format of image) in the browser

I am developing a ASP .NET MVC application where users are able to upload files to a repository. Those files could be pdf, doc, any type of image and so on.
When the user select a file to be imported I would like to display this file in the browser so they can review its contents before the upload.
I know I could use some sort of IFrame to display pdf but I am looking for some specific class or .net libraries to implement this feature.
I just need a north.
This is an extremely difficult problem. There are some libraries that can help. For instance PDF files might be rendered to images with ghostscript. Word and Excel files might be converted to PDF or image with a number of libraries. None of them, AFAIK, are very good at it so I can not recommend one.
You could automate MSO to perform the conversion to PDF, but that is decidedly not safe for server code. Another possibility is convert source documents to SWF files (like flexpaper) and display in flash. There are some great libraries out there, but it will limit your supported clients. Sharepoint has support for providing some of this capability as well. Others have used OpenOffice to convert MSO documents but also at a loss of quality.
I can't really advise any specific direction as it is highly dependent on what you/your company is willing to spend and the desired results. Good luck.
You could try to rely on Windows and the explorer thumbnails for it, like here, but then you'd have to make sure that:
You can abuse the server in the most elaborate way (install stuff, talk to the shell from ASP.NET)
You have a thumbnail provider installed on the server for every type that you want to preview. I guess from the moment you can see the thumbnail in explorer, you're set. So for pdf, you might need to install PDF Reader from Adobe.
Docx files should be saved with thumbnail checked (see link). There seems to be no other easy, free way to convert a docx to a thumbnail. The "best" solution I came across, was saving it automatically again somehow, and making sure the thumbnail option is checked.
I don't want to say that's impossible, but it can't be done with finite effort.
What you are asking for is a browser-based solution, because you want the user to be able to "review" the document before uploading.
Therefore you cannot use a server side solution, which is essentially what is being asked by referring to a ".Net library".
.Net libraries are dependent on an installed version of .Net, which does not exist in all versions for all operating systems for which graphical browsers exist.
Next, recent changes in browser security do not allow to read the full client-side file name of the selected file in the input field.
You'd have to rely on HTML5 and its FileReader to access the file's byte stream, but even then you can only retrieve image from image files. (see sample)
Excluding browser-based solutions in Flash, ActiveX, Java, due to browser and platform support, this leaves JavaScript as the only "reasonable" solution: you'd need a library for each supported format to either convert a file into an image in an image format supported by browsers, or extract the text(+image) representation of a file.
Great awnsers... Just want to share the result of my research and I found a nice client-based solution supported by Mozilla Labs. This is a framework based on HTML5 and Javascript with no native code needed.
Here the project website:
https://github.com/mozilla/pdf.js
This is what you are capable of:
http://mozilla.github.com/pdf.js/web/viewer.html
And for the last a great video explaning how everthing works
http://www.youtube.com/watch?v=Iv15UY-4Fg8&noredirect=1
Reguarding my question we are going to converter every possible file to PDF on the server and then render this PDF using this framework.

How to change font in word document

I'm wondering how can I change the font (+ color and some font style) for the whole word document (excluding the page headers, if it's possible) by using C# ?
If You know any libraries (also commercial) feel free to let me know.
(After changing the font, I'll convert that word document to PDF using ABCPdf)
Depending on the library you would loop through the content (Pages/Paragraphs etc.) and change whatever font attribute you want...
Since you don't say which type of application you build - in case it is a pure desktop application and Word is guranteed to be installed locally you can use Office Interop. BEWARE that Office Interop is NOT supported by MS in server-scenarios (like IIS, ASP.NET. Windows Service, WCF etc.).
IF Word is not guaranteed to be installed and/or your application is not a desktop application and your Word documents are always DOCX files you could use OpenXML SDK V 2 from MS (free).
Otherwise I can recommend Aspose.Words (commercial) - works with old DOC and current DOCX and is usable in any type of application (desktop, ASP.NET, Windows Service etc.).
Handling Office documents in .NET is a quite straight forward task. Have a look at Microsoft.Office.Interop.Word, it is pretty well documented. Here is another link on to how you can change a word document font style using .NET (the example is in VB but is easily convertible to C#)
Start by reading on Microsoft.Office.Interop.Word
(You can google some user-friendly examples, there are tons)
Later on, read about Text Formatting
Easy, isn't it?

Categories