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.
Hi,
I have a Word document with bookmarks. But while converting the document to pdf, it is missing. is there any option to include those bookmarks in PDF while converting from word?
Thanks
Jithin V P
@jithin.p Sure you can specify outline level where the bookmarks will be exported to PDF using OutlineOptions
properties.
Hi,
Thanks. I tried the below code, and the bookmark is coming now in PDF. But while selecting “Go to bookmark”, the cursor is not pointing to the bookmark point in PDF. Can you please help me to sort this?
Aspose.Words.Saving.PdfSaveOptions opt;
opt = new Aspose.Words.Saving.PdfSaveOptions();
opt.PageMode = PdfPageMode.UseOutlines;
opt.OutlineOptions.DefaultBookmarksOutlineLevel = 1;
opt.HeaderFooterBookmarksExportMode = HeaderFooterBookmarksExportMode.All;
Thanks
Jithin V P
@jithin.p Could you please attach your problematic input and output documents here for testing? We will check the issue and provide you more information.
Hi,
Due to company instructions, I am not able to share the documents. The only thing pending is the bookmark in converted PDF is not navigating to the destination. We have a licensed version of ASPOSE too.
Thanks
Jithin V P
@jithin.p If possible please create a simplified document without real data that will allow us to reproduce the problem. Unfortunately, it is impossible to tell what the problem is and how to resolve it without an ability to reproduce it on our side.