How to make PDF with any Font readable both on Win and Mac

I learned I can apply font setting using

Font fontobject = FontRepository.FindFont(“MS Gothic”);

But I suppose this fontobject does not suffice when I want output PDF file to be readable both on Windows and macOS.

As for CJK font, “Heisei Mincho” https://fonts.adobe.com/fonts/heisei-mincho-std sounds suitable for this purpose, which allows readers of output PDF files choose whatever compatible flexibly.

How can I apply font for output.pdf below, NOT embedding?

Aspose.PDF 19.6 .Net Core 2.0

using System;
using Aspose.Pdf;
using Aspose.Pdf.Text;
namespace font
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("Hello World!");
			Font fontobject = FontRepository.FindFont("MS Gothic");
			Document doc = new Document("input.pdf");

			TextFragmentAbsorber tfa = new TextFragmentAbsorber(".+");
			tfa.TextSearchOptions = new TextSearchOptions(true);
			tfa.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation;

			doc.Pages.Accept(tfa);
			foreach (TextFragment textFragment in tfa.TextFragments)
			{
				foreach (TextSegment textSegment in textFragment.Segments)
				{
					textSegment.Text = string.Empty;
					textSegment.Text = "日本語や中国語などの東アジアの言語の文字列";
					textSegment.TextState.Font = fontobject;
					textSegment.TextState.Font.IsEmbedded = false;
					break;
				}
				break;
			}
			doc.Save("output.pdf");
		}
	}
}

If I execute this on Windows, then I open output.pdf on macOS, the string “日本語や中国語などの東アジアの言語の文字列” can not be displayed correctly, naturally, because I explicitly configured the font to be “MS Gothic” which basically only on Windows.

@KDSSHO

Thank you for contacting support.

Please note that the PDF readers support a core of 14 fonts so that documents can be displayed the same way regardless of the platform the document is displayed on. When a PDF contains a font that is not one of the 14 core fonts, you would need to embed that font to the PDF file to avoid font substitution.

You may please visit Formatting PDF Document for further information.

Thank you for your reply.
But my purpose is NOT to avoid font substitution. I just want to make PDF file “readable” in any environment without embedding. As long as it is readable, it is OK to substitute fonts according to users’ environment. Is it possible with Aspose.Pdf ?

Another test:Please open 2 Japanese files.
I translated English input file English.pdf (95.7 KB)
Into Japanese output file (A) Japanese_Created_by_Other_Software.pdf (191.1 KB) and it is readable in any environment.

I used above strategy on Aspose and created Japanese output file (B) Japanese_Created_by_Aspose.pdf (121.4 KB)

I want to make (A) with Aspose. How can I do it?

P.S.
I can find some APIs/Properties related with “substitution” FontRepository.Substitutions | Aspose.PDF for .NET API Reference but I do not know how to use it for my purpose. I also read several tickets on this forum such as Fonts substitution and name

@KDSSHO

Thank you for elaborating further.

Please note that some text may appear garbled if required font does not exist on the system so the PDF readers try to substitute fonts, so you would need to embed fonts to make a document truly platform independent. Moreover, the PDF document Japanese_Created_by_Other_Software.pdf also has embedded subset of font.

If you are able to achieve it some other way with no embedded fonts then please elaborate the steps with reference to Adobe Acrobat so that we may further investigate.

Thank you very much for your support. My purpose should have been not quite clear
I want to ask you 2 more questions * starred * below.

I made 2 PDFs with Acrobat PDFMaker.
NotEmbedded.pdf (7.9 KB)

As you can see no fonts are embedded. I want to make PDF like this with Aspose. * How can I do it? *

Embedded.pdf (187.8 KB)

I DO understand this can be created with Aspose, but this way is lower priority for me, according to its licensing troublesome.

Formatting PDF Document taught me that we can set defaultfontname as follows, but I can not observe wheather it is set.

PdfSaveOptions pso = new PdfSaveOptions();
pso.DefaultFontName = "Courier";
doc.Save("output.pdf");
doc.Save("output_DefaultFontCourier.pdf", pso);

Property window on Adobe Reader DC only shows the same fonts as output.pdf.

input.pdf (86.8 KB)
output.pdf (462.0 KB)
output_DefaultFontCourier.pdf (497.0 KB)

  • How can I set default font? *

Quick Addition:

Is this page relevant to this font manipulation? I feel the need for deeper level operation such as encoding, etc.

@KDSSHO

We have logged an investigation ticket with ID PDFNET-47072 in our issue management system for further investigations and will let you know once detailed information is available regarding your questions and concerns.

However, is it feasible for you if another PDF document is generated which contains image of each respective page in original document? This way no font resources will be required in the document.

Thank you so much for your patiently supporting me.
Can I at least ask you this again? Default font name may meet my demand if it succeed.

Or, in other word, I’d like to know how PdfSaveOptions.DefaultFontName = “font name” is designed to behave?

As for your suggestion below, I’m afraid, no, it it not feasible for my solution.

@KDSSHO

This property gets or sets the font name used by default for the fonts which are absent on computer. When the PDF document that is saved into PDF contains fonts, that are not available in the document itself and on the device, API replaces this fonts with the default font provided that the font with DefaultFontName is found on device.

We hope this information will clarify how this property behaves. Please let us know if there is still any confusion.

Would you kindly share how to know whether it actually behaved as it should behave?
I have no idea for checking the difference on “default font” in 2 files I atatched above.
output.pdf (462.0 KB)
output_DefaultFontCourier.pdf (497.0 KB)

I have already read that explanation and I think I understand it, just as I mentioned as follows.

Formatting PDF Document taught me that we can set defaultfontname as follows, but I can not observe wheather it is set.

@KDSSHO

The API can generate warnings upon font replacements, with FontSubstitution event and FontSubstitutionHandler delegate.

static void OnFontSubstitution(Aspose.Pdf.Text.Font oldFont, Aspose.Pdf.Text.Font newFont)
{
    System.Console.WriteLine(string.Format("Font '{0}' was substituted with another font '{1}'",
    oldFont.FontName, newFont.FontName));
}

document.FontSubstitution += new Document.FontSubstitutionHandler(OnFontSubstitution);

You may also refer to this thread for reference.