Rules for Font Substitutions to / from PDF when using SSRS / ReportViewer to create PDFs? - pdf

In an effort to reduce the size of the PDF files exported from SSRS and the ReportViewer control, one of the main contributors to the size of a PDF is full and subset font embedding.
Ultimately, we decided to standardise our reports using only variations (size, bold, italic etc) of the Arial and Times New Roman fonts - fortunately most of our reports are corporate death-by-spreadsheet fare and not requiring aesthetic appeal.
During PDF creation, these fonts seem to then be substituted by ReportViewer/SSRS for one of the 14 PDF 'standard permissable fonts' (since the standard fonts aren't usually installed on most Windows machines anyway).
So my question is, what exactly are the rules that the PDF renderer on ReportViewer uses during font substitution, rather than embedding a font in the PDF?
Based on this site, and with a bit of trial and error, the following substitutions do seem to be made (from RDL to PDF, list is incomplete):
Times New Roman => Times
Courier New => Courier
Arial => Helvitica
I had thought that the substitution was forced because of font embedding legalities, but Times New Roman and Arial are both "Editable" which I understand to be the least restrictive.

There are a few conditions to be met when the pdf is rendered.
I suspect one of the parameters set out here are not met and converting your fonths to the closest one that fits.
Ensure the font is installed correctly and that font embedding is granted font; and
The font must be a true type font.

Related

How to handle PDF font fallback perfectly when generating it?

I'm currently working on a project that can convert HTML canvas to PDF, user can select the font and draw the text in the canvas and export as a PDF(vector), but there's a problem that user can enter other language text that the font doesn't really support it. It's shown fine in the canvas because the browser did the font fallback mechanism maybe to grab the system font as a fallback, but in the exported PDF it's all corrupted. I've embedded the font in the PDF but the font doesn't have corresponding glyph, and the PDF reader like adobe doesn't have font fallback mechanism so it all become .nodef
I have two ideas but that aren't really satisfying.
1. Collect all glyph from each sentence and create a new font
Walk through each char and check if current font has corresponding glyph, if so, adding it to the new font list, if not, using an alternative font from the font stack #1 as the fallback to get the glyph and adding it to the new font list, then finally converting it as a new font and embedding it in the new PDF.
It seems good but in reality the performance of generating new font is terrible.
(I was using Opentype.js to load and write a new font, when we exported the font by using toArrayBuffer method, it took 10 mins for 6,000 words)
#1, Font stack is a stack like ['Crimson Text', 'Pt Sans', 'Noto Sans'], if the first font can't find corresponding glyph then go next until the end we give up.
2. If encountered any missing char, change the font-family of that sentence to Arial Unicode MS or Noto
It's pretty simple but it converts every word in the sentence to Arial Unicode MS or Noto, besides, it's hard to find a good font that contains most of language's glyph and we can't use font stack mechanism because we only can use one font in one sentence.
My goal is to make the exported PDF similar with the canvas that user drew, hoping someone can give me some direction 😥, many thanks
The usual solution would be to embed all four fonts in your stack plus noto (all suitably subsetted, preferably), and switch between them mid-word as required.
Building a new frankenfont from the fonts as you suggest is not required, though I admire the ambition!

Problem showing a font with license restriction to pdf

I'm programming to convert a file to pdf on mac, file contains a Chinese text
using a font STFangsong which has license restriction and is not embeddable, I
tried many CMaps to encode it, but it seems the root cause is because pdf viewer(both
mac previewer and acrobat reader) does not recognize the font, as shown in the pdf
file properties, Actual Font Unknown and there is a pop message says can't find or
create the font.
The PDF 32000-1:2008 9.6.6.4 tells a guideline that when encoding truetype font,
the font program should be embedded, though no specific explanation, from my
understanding, embedding can guarantee the pdf is readable everywhere, but I do not
need this since the font is licensed, I just want it can be shown on my computer.
So my question here is does those pdf viewer has limitation on those CJK characters
when embedding is forbidden?
By the way, I used Microsoft word to write a text with the font and save word to
pdf, and it shows the font is embedded subset, does it mean Microsoft have bought the
license?

How to get a font PostScript name?

I'm adding the possibility to embed Truetype fonts in the PDFs generated by my application, but the fonts "Sitka Text" (and it's variants "Sitka Banner", "Sitka small" and etc) and "Meiryo" don't embed.
I believe it is because I'm using the name from the LOGFONT object and to these fonts I should be using the PostScript name.
How can I obtain the Postscript name?
I obtained the 'name' table with GetFontData but the result didn't return any name I could use.
Is there any method on WINAPI that gives me that name?
Edit: I only show to my users fonts with the embedding permissions "Editable" and "Installable" which I obtain with the methods EnumFontFamiliesEx and it's CALLBACK function.
I also checked the NEWTEXTMETRIC ntmFlags that shows all my fonts are NTM_TT_OPENTYPE.
Edit2: By don't embed I mean that the PDF readers don't show my font as embedded (and Acrobat doesn't show any text)
An example of the error.
SOLVED
first, I'd like to thanks Michael Mckeough and mkl, You guys are Awesome and helped me a lot, I checked my original font and it wasn't damaged and I didn't change the font bytes, but then I finally noticed that if you call GetFontData to a (.ttc) file it will crop the ttcf part and no PDF reader will be able to understand what font it was.
Ideally, you would find this in the "name" table of the font. It would be nameId 0x0006, in a form useful for your platform. The format of the name table is a part of the TrueType and OpenType specifications. (You can find a copy here Microsoft Typography OpenType spec Name). There can be an awful lot of entries in the table, or there may be few. In particular, the Postscript name may or may not be present in any given font. You will need to look through the table for nameID of 0x0006, and a form (language, platform, encoding) that you can use. For postscript names, you most likely want them to be English, ASCII encoded, for any platform.
However, it is unlikely that the font is not embedding for this reason! A more common reason is that it is not legal to embed this font. In the Microsoft Typography OpenType Spec OS/2 you will see a field named fsType. This field contains flags indicating under what circumstances this font is licensed to be embedded. No Reputable tool will embed or subset this font is these flags indicate is it not licensed to be embedded.
I see that "Sitka Text" is a MS Windows 10 font, freely distributed by windows. It seems unlikely that It would not be licensed for embedding. Interestingly, the tool I usually use for "looking at" a font quickly (Font Validator, which used to be available from Microsoft Typography, but appears to no longer be) tells me that the OS/2 record is invalid. That it specifies a type of 5, and the spec says that type 4 is the latest. The correct response to a request to embed would require access to the fsType field, and if the record format was unknown, it should "fail safe", and refuse to embed the font.
So this is the most likely reason that the font will not embed for you.

Possible to edit PDF without embedded font installed?

I have a PDF and need to edit its text.
It has an embedded font and I'm not able to find the font to install. Is it possible to edit the text and maintain its embedded font when I don't have the font installed?
I'm editing with Acrobat X and its warning me that I don't have the font and forcing me to change the font of the text I want to edit to one that I have installed. I've Googled for a couple hours and found the font family, but not the variation that's embedded. Because the font is already in the document, I would have thought Acrobat or another software program could tap it to allow me to edit, though I'm guessing I'm missing something.
It depends...
1.
Most likely, your embedded font is a subset of the full font. That means that it contains only these glyphs (shapes that represent printable characters) which were required as representations for characters used by the original PDF.
If your edit wants to insert a character that wasn't present in the original PDF, Acrobat (or any other editing method) has to use a different font. The font embedded in the PDF simply doesn't have glyph that is suitable for your edit!
Also, your subsetted font's name is not exactly like the full set font's name: it uses has a randomly composed 6 uppercase character prefix with a +-sign to build the used font name, like ABCXYZ+Arial.
You could employ the free (as in beer) Acrobat Plugin FontReporter to generate a list of all glyphs contained in your font.
You can also use this answer:
"How can I extract embedded fonts from a PDF as valid font files?"
to extract the font in question.
Then open the extracted font (which will be the subset variant, mind you!) in FontForgehttp://fontforge.github.io/en-US/), and there check two things:
the original font's license
the original font's creator
With that knowledge you could then definitely find the variant of the family that is embedded (or rather: that was present when the PDF generating and font embedding software created the subset).
2.
If the (subsetted) font you are looking at uses a so called "custom encoding", it may be almost impossible to edit the PDF file with standard tools (even if you have the same font locally installed that was used to create the PDF file).

Create ttf with a set of chars from other font

Im programming an app that generates PDFs for several situations. In some of them there are greek letters that should be displayed. My Problem is that including a font like arial that provides these chars adds some mb to my pdfs because the whole font is included in the pdf.
Is there a way to include just the chars needed or to generate a "new" font that only includes the chars needed as another font?
The feature you are looking for is font subsetting. This is normally a function of the code making the pdf.