RTF document font substitution and create PDF DOM in-memory using memoryStream

Hi,
We (Financial Ombudsman Services) bought Aspose total licenses and we came across an issue with PDF conversions. Could you please help with this issue?

Problem: When converting RTF to PDF, some fonts were set to ArialMT, which is not available in font repository and Word substituting to Arial. So that looks fine in Office Word. In case of Aspose pdf conversion, the font substitution is happening and it is changing the font to default (i.e Times New Roman). Looking at your online documentation, we could set default font to be FontSettings.Default to Arial, but that causes issues where it shouldn't be Arial. We also tried, FontSettings font name to null/empty to find the right font for substitution but the font choosen is Raavi.

Solution we tried: We created a simple test app, that will tackle this problem in 2 phases, First find the all font substitutions Aspose trying to do when saving document to PDF. Second replace them with configured font ones. This worked fine, However when saving the document from Aspose.Words DOM to pdf memory stream and load to PDF DOM, and save it a PDF file, it is corrupting PDF.

What we are looking:
1) Why PDF is corrupted when saved using PDF DOM, but okay when saved using Words.
2) Is there any better solution to tackle this font substitution issue than the sample one attached

Hi Santosh,


Thanks for contacting support and sorry for the delayed response.

I have tested the scenario using Aspose.Pdf for .NET 9.3.0 and Aspose.Words for .NET 14.5.0 and I am unable to notice any problem. I am able to view the PDF file saved with Aspose.Pdf for .NET is Adobe Reader 11.0.2. For your reference, I have also attached the resultant PDF generated over my end.

Now concerning to your query related to Fonts issue with Aspose.Words, my fellow workers from respective team will further look into this matter and will reply accordingly.

Hi Nayyer,


Thank you for your reply.

I definitely confirm that you have not used the sample I attached in this thread to create the pdf. As it still shows fonts in Times New Roam(default). The sample program I attached will change it to Arial font. I used the same version of Aspose software(Latest) you mentioned in your reply.

1) Load the document to Words DOM -> Change Font -> Save to PDF file -> It works.
2) Load the document to Words DOM -> Change Font -> Save to PDF stream -> Load stream to PDF DOM -> Save to PDF file -> It is corrupted.

Scenario 1 is coded as ConverToPdf method in my sample.
Scenario 2 is coded as ConverToPdf2 method in my sample.

Could you please tell what did you try in reference to my sample?

Thanks
Santosh



Hi Santosh,


I have used the same code snippet which you have shared earlier in my sample project. Please note that I used Visual Studio 2010 application with target platform as .NET Framework 4.0 and running over Windows 7 (x64). Can you please share the sample project which can help us in further testing this scenario in our environment. We are sorry for this inconvenience.

Hi Nayyer,


Thank you for your quick reply.

Please find the code below:

public static void ConvertToPdf2(string source, string destination, IDictionary<string, string> fontSubstitutionConfig)
{
var doc = new Document(source);
var missingFonts = new List();
var pdfSaveOptions = new PdfSaveOptions { WarningCallback = new FindMissingFonts(missingFonts), SaveFormat = Aspose.Words.SaveFormat.Pdf};
var memoryStream = new MemoryStream();
doc.Save(memoryStream, pdfSaveOptions);

if (missingFonts.Count > 0)
{
doc.Accept(new SubstituteMissingFont(missingFonts, fontSubstitutionConfig));
doc.UpdatePageLayout();
memoryStream.Position = 0;
doc.Save(memoryStream, Aspose.Words.SaveFormat.Pdf);

memoryStream.Position = 0;
var pdfDocument = new Aspose.Pdf.Document(memoryStream);
pdfDocument.Save(destination);
pdfDocument.Dispose();
}
}

Kind Regards
Santosh

Hi Santosh,


Thanks for sharing the code snippet. In my earlier attempt, I have used the same code snippet as shared above and also used other classes referenced in above stated method (as specified in Program.cs shared earlier) and as per my observations, the contents are still appearing in ArialMT. I think the its happening because Arial MT is installed over my machine and during PDF conversion, the code finds it from repository and uses it in resultant file.

Besides this, when I have checked the C:/Windows/Fonts folder over my machine, I can see Arial Rounded MT Bold and collection of Arial font but I am afraid I cannot specifically find ArialMT font. Can you please share some further details so we can again try replicating the problem at our end. We are sorry for this inconvenience.

Hi Nayyer,


Thank you for your quick reply.

I understand that you are saying on your machine font substitution is not happening as Aspose pdf is finding the ArialMT from your machine font repository (C:\Windows\Fonts). Hence you are not able to replicate with the sample I provided.

You can change the font in rtf document from ArialMT to ArialXYZ (Unknown). In the sample, please change font mapping, ArialXYZ to Arial. Then you should be able to reproduce the issue.

I’ve attached the document where I used ArialXYZ font (hoping it would not exist in your font repository).

And the mapping you need to change in the sample:
Dictionary<string, string> dictionary = new Dictionary<string, string>() { {“ArialXYz”,“Arial”}};

Kind Regards
Santosh




Hi Santosh,


Thanks for sharing the details.

I have again tested the scenario using 0553668963_test2.rtf file and as per my observations, when saving the output with ConvertToPdf(…) method, the contents under Conclusions paragraph in resultant PDF are appearing Times New Roman and output is created with Aspose.Words 14.5.0 (see attached Scenario1_Aspose_Words_Conversion.pdf). When using this file, I have specified fonts directory as

Dictionary<string, string> dictionary = new Dictionary<string, string>() { { “ArialXYZ”, “Arial” } };<o:p></o:p>

and I am also getting following error.

Unable to find substitution for : ArialMTPlease try one of the following: 1) If MS Word does not have font substitution on the machine it was opened, most likely Font is missing on the machine it was converted to PDF.2) If MS Word has font substitution, please define the font substitution in PDF converter config.


However when calling ConvertToPdf2(…) method, no resultant file is being generated and I am getting above stated issue.

Hi Nayyer,


It does mean that Aspose is not able to find ArialMT in your font repository. in that case, you need a font substitution as follows:

Dictionary<string, string> dictionary = new Dictionary<string, string>() { { “ArialXYZ”, “Arial” }, { “ArialMT”, “Arial” }};

Note: Scenario 1 (ConvertToPdf) always worked for me with correct font substitution. So the
issue is with ConvertToPdf2 scenario only.

Thanks
Santosh

Hi Santosh,


Thanks for sharing the details.

I have again tested the scenario and have observed that Aspose.Pdf for .NET is generating a blank PDF file. For your reference, I have also attached the output being generated over my end. However when saving the file with Aspose.Words inside ConvertToPdf2(…), the file is correct and it contains the contents in ArialMT font.

Can you please confirm that you are also facing the same issue.

Hi Nayyer,


Yes. The converted PDF document is blank with Aspose pdf 9.3 version. However we got incidents where the document is corrupted with previous versions.

Thanks
Santosh

Hi Santosh,


Thanks for the acknowledgement.

I have logged it in our issue tracking system as PDFNEWNET-37124. We will
investigate this issue in details and will keep you updated on the status of a
correction. <o:p></o:p>

We apologize for your inconvenience.

The issues you have found earlier (filed as PDFNEWNET-37124) have been fixed in Aspose.Pdf for .NET 9.6.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(3)

Hi Santosh,


As stated above, you reported issue has been fixed in Aspose.Pdf for .NET 9.6.0. Please check details in your other related PS post.

Please feel free to contact us for any further assistance.

Best Regards,