Hi,
Thanks. I tried this. But while converting this generated word document to PDF, it is causing formatting issues. Can you please check? Attached the document and code.
Output.pdf (2.3 MB)
Input.docx (172.7 KB)
Aspose.Words.Saving.PdfSaveOptions opt;
opt = new Aspose.Words.Saving.PdfSaveOptions();
opt.ExportDocumentStructure = true;
opt.CustomPropertiesExport = Aspose.Words.Saving.PdfCustomPropertiesExport.Standard;
opt.SaveFormat = Aspose.Words.SaveFormat.Pdf;
opt.Compliance = Aspose.Words.Saving.PdfCompliance.Pdf20;
opt.EmbedAttachments = true;
doc.Save(filepath, opt);
Thanks
Jithin V P
@jithin.p The following fonts are not available on my side:
- âVCEFIJ+FrutigerLTPro-Condensedâ
- âJLNNHU+FrutigerLTPro-LightCnâ
- âETMKLU+FrutigerLTPro-Boldâ
- âLVNWRS+FrutigerLTPro-BoldCnâ
- âFAPVWH+FrutigerLTPro-Lightâ
- âWIPSPU+FrutigerLTPro-LightCnâ
They are substituted and most likely this causes layout issues.
Could you please elaborate your ultimate goal? Do you need to merge PDF and MS Word documents keeping their original layout? If so it will be more correct convert MS Word document to PDF and then merge PDF documents.
A post was split to a new topic: Removing annotations from PDF
Thanks. I copied these fonts to my local machine and opened the PDF. But the same formatting and alignment issue exists. Is there anything need to do from my side apart from copying the fonts.
Thanks
Jithin V P
@jithin.p The fonts must be available on the machine where document is converted to PDF. Please see our documentation to learn how to specify the fonts location:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/
If the problem still persists, please attach the fonts here for testing.
The following article also might be useful for you:
https://docs.aspose.com/words/net/manipulating-and-substitution-truetype-fonts/
Thanks. I will try. Attached the fonts.
frutiger-lt-pro.zip (581.2 KB)
Thanks
Jithin V P
@jithin.p Thank you for additional information. Font names specified in your document does not match actual font names, so they are substituted improperly. If add correct substitution rules, the document is rendered fine:
FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource(@"C:\Temp\fonts", true) });
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("VCEFIJ+FrutigerLTPro-Condensed", "FrutigerLTPro-Condensed");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("JLNNHU+FrutigerLTPro-LightCn", "FrutigerLTPro-LightCn");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("ETMKLU+FrutigerLTPro-Bold", "FrutigerLTPro-Bold");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("LVNWRS+FrutigerLTPro-BoldCn", "FrutigerLTPro-BoldCn");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("FAPVWH+FrutigerLTPro-Light", "FrutigerLTPro-Light");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("WIPSPU+FrutigerLTPro-LightCn", "FrutigerLTPro-LightCn");
Document doc = new Document(@"C:\Temp\in.docx");
doc.WarningCallback = new FontSubstitutionWarningCallback();
doc.Save(@"C:\Temp\out.pdf");
out.pdf (498.1 KB)
Thanks. I tried and the below âFontSubstitutionWarningCallback()â is not found. Can you please help me?
doc.WarningCallback = new FontSubstitutionWarningCallback();
@jithin.p FontSubstitutionWarningCallback
is mu implementation of IWarningCallback
, that is used to get notification about font substitution:
internal class FontSubstitutionWarningCallback : IWarningCallback
{
public void Warning(WarningInfo info)
{
if (info.WarningType == WarningType.FontSubstitution)
Console.WriteLine(info.Description);
}
}
So you are saying that it is not necessary. So may i know how the below font substitution will relate to the current doc like âdoc.FontSettings = fontSettingsâ?
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("WIPSPU+FrutigerLTPro-LightCn", "FrutigerLTPro-LightCn");
@jithin.p When you use FontSettings.DefaultInstance
the font setting are set globally. When you use doc.FontSettings
font setting are set for the Document
instance only. So if you need to set substitution rules for a particular Document
instance you can set them in doc.FontSettings
.
Ok thank you very much. Let me try like thatâŚ
1 Like
Hi,
I tried using the below code. But the formatting is not correct. Can you please help me? Attached the pdf document. I can see the below fonts are not embedded.
Aspose.Words.Saving.PdfSaveOptions opt;
opt = new Aspose.Words.Saving.PdfSaveOptions();
opt.ExportDocumentStructure = true;
opt.CustomPropertiesExport = Aspose.Words.Saving.PdfCustomPropertiesExport.Standard;
opt.SaveFormat = Aspose.Words.SaveFormat.Pdf;
opt.Compliance = Aspose.Words.Saving.PdfCompliance.Pdf20;
opt.EmbedAttachments = true;
FontSettings.DefaultInstance.SetFontsSources(new Aspose.Words.Fonts.FontSourceBase[] { new SystemFontSource(), new Aspose.Words.Fonts.FolderFontSource(@"C:\MyFonts\", true) });
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("VCEFIJ+FrutigerLTPro-Condensed", "FrutigerLTPro-Condensed");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("JLNNHU+FrutigerLTPro-LightCn", "FrutigerLTPro-LightCn");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("ETMKLU+FrutigerLTPro-Bold", "FrutigerLTPro-Bold");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("LVNWRS+FrutigerLTPro-BoldCn", "FrutigerLTPro-BoldCn");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("FAPVWH+FrutigerLTPro-Light", "FrutigerLTPro-Light");
FontSettings.DefaultInstance.SubstitutionSettings.TableSubstitution.AddSubstitutes("WIPSPU+FrutigerLTPro-LightCn", "FrutigerLTPro-LightCn");
doc.Save(filepath, opt);
TestDoc.pdf (557.9 KB)
Thanks
Jithin V P
@jithin.p Please try using IWarningCallback
as shown in my code example and check whether there are any warnings.