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.
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.
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.
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.
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.
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.
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);
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.