Unusable extracted embedded font in this PDF

Hello,

In this pdf, the embedded font GastonDemo (used by the 2 cursive “X” on upper right) saved using Aspose.Pdf is not usable by Aspose.Fonts
La lettre X.pdf (1.7 MB)

Can you fix it or give a workaround ?
Thanks

@tfipsrd

Can you please explain the requirements in more detail with us so that we may help you further in this regard.

@mudassir.fayyaz : the saved font is not loadable by Aspose.fonts.
Here is the extracted font : AAAAAC+GastonDemo.zip (9.4 KB)

Extacted using Aspose.Font code sample :

var fonts = pdfDocument.FontUtilities.GetAllFonts();
	foreach (var font in fonts)
	{
		if (font.IsEmbedded)
		{
			string baseFont = null;
			try
			{
				baseFont = font.BaseFont;
			}
			catch (Exception)
			{
				baseFont = font.FontName;
			}
			
			var fontPath = Path.Combine(@"c:\temp", baseFont + ".ttf");
			FileStream fs = new FileStream(fontPath, FileMode.OpenOrCreate, FileAccess.Write);
			fs.Position = 0;
			font.Save(fs);
			fs.Close();
			fs.Dispose();
		}
	}

On real TTF file it is working well but with this font GastonDemo, i can’t load it in Aspose.Font and I don’t know the fonttype of it.

@tfipsrd

We were able to observe in our environment that the extracted font was not readable by Aspose.Font. For the sake of further investigation, we have logged an investigation ticket as PDFNET-49972 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali : I could get the font format (Try each FontType of Aspose.Font) and this font is a CFF one.
I need to convert this CFF font into a TTF. But Aspose.Font Convert or SaveToFormat method is not working. I get an exception : String reference not set to an instance of a String. (Parameter ‘s’) at System.Text.Encoding.GetBytes(String s).

I’ll open thread in Aspose.Font support forum

@tfipsrd

Could you please share the sample code snippet that you have tried to so far to convert the font along with sample file (if any). We will further test the scenario in our environment and address it accordingly.

@asad.ali :

Here is the code snippet (using Aspose.Pdf and Aspose.Font) to identify the font and convert the font :

var fonts = pdfDocument.FontUtilities.GetAllFonts();

foreach (var font in fonts)
{
	if (font.IsEmbedded)
	{
		string baseFont = null;
		try
		{
			baseFont = font.BaseFont;
		}
		catch (Exception)
		{
			baseFont = font.FontName;
		}


		var fontPath = Path.Combine(@"d:\temp", baseFont + ".ttf");
		FileStream fs = new FileStream(fontPath, FileMode.OpenOrCreate, FileAccess.Write);
		fs.Position = 0;
		font.Save(fs);
		fs.Close();
		fs.Dispose();

		bool isTtfFont = false;
		bool isType1Font = false;
		bool isCffFont = false;
		bool isOtfFont = false;

		FontUtility.InitLicense();
		try
		{
			FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fontPath)));
			var ttfFont = Font.Open(fd) as TtfFont;
			isTtfFont = !(ttfFont.CffFont != null);
			if (ttfFont.CffFont != null)
			{
				var cffFont = ttfFont.CffFont;
				var realTTF = (TtfFont) cffFont.Convert(FontType.TTF);
				realTTF.Save(fontPath+"realttf.ttf");
			}
		}
		catch (Exception e)
		{
			isTtfFont = false;
		}

		if (!isTtfFont)
		{
			try
			{
				FontDefinition fd = new FontDefinition(FontType.Type1, new FileSystemStreamSource(fontPath));
				var type1Font = Font.Open(fd) as Type1Font;
				isType1Font = true;
			}
			catch (Exception e)
			{
				isType1Font = false;
			}
		}

		if (!isTtfFont && !isType1Font)
		{
			try
			{
				FontDefinition fd = new FontDefinition(FontType.CFF, new FileSystemStreamSource(fontPath));
				var cffFont = Font.Open(fd) as CffFont;
				isCffFont = true;

				TtfFont realTTFFont = (TtfFont) cffFont.Convert(FontType.TTF);
				realTTFFont.Save(fontPath + ".realTTFFont.ttf");

				
			}
			catch (Exception e)
			{
				isCffFont = false;
			}
		}

		if (!isTtfFont && !isType1Font && !isCffFont)
		{
			try
			{
				FontDefinition fd = new FontDefinition(FontType.OTF, new FileSystemStreamSource(fontPath));
				var otfFont = Font.Open(fd) as TtfFont;
				isOtfFont = true;
			}
			catch (Exception e)
			{
				isOtfFont = false;
			}
		}
	}

Using the attached pdf “La lettre X.pdf” in first port of this thread.

Thanks

Hello,

Using Aspose.Font .NET, i would like to convert CFF font to a TTF one.
Based on documentation, the Font.Convert or Font.SaveAsFormat can do that (only to TTF format).

But when i try to convert this CFF font AAAAAC+GastonDemo.zip (9.4 KB)
i get an exception :

String reference not set to an instance of a String. (Parameter ‘s’) at System.Text.Encoding.GetBytes(String s).

using this code snippet :

FontDefinition fd = new FontDefinition(FontType.CFF, new FileSystemStreamSource(fontPath));
var cffFont = Font.Open(fd) as CffFont;
TtfFont realTTFFont = (TtfFont) cffFont.Convert(FontType.TTF);
realTTFFont.Save(fontPath + ".realTTFFont.ttf");

The same on this TTF font (with OpenType outline), i want to save it as a real TTF file : Generic0-Regular.zip (6.1 KB)

using this code snippet :

FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fontPath)));
var ttfFont = Font.Open(fd) as TtfFont;
if (ttfFont.CffFont != null)
  {
   var cffFont = ttfFont.CffFont;
   var realTTF = (TtfFont) cffFont.Convert(FontType.TTF);
   realTTF.Save(fontPath+"realttf.ttf");
  }

Can you help me on this ?
Thanks

This issue can be linked with the Aspose.Pdf issue :

@tfipsrd

Another issue as FONTNET-239 has been logged in our issue tracking system for the sake of investigation from perspective of Aspose.Font for .NET. We have linked both issue to this forum thread and will surely notify you as soon as some significant progress is made towards their resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.