@jithin.p Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.
Hi,
Attached the Input PDF and Output word document. Due to data privacy i only published the data from the input PDF to the output word document. Rest of the appended data from another documents in the output word document is being deleted. Please guide me to fix this.
Output.docx (172.6 KB)
Input.pdf (129.9 KB)
Thanks
Jithin V P
@jithin.p To export fonts as embedded into the DOCX document you should set FontInfos.EmbedTrueTypeFonts
property.
Aspose.Pdf.Document myDocPdf = new Aspose.Pdf.Document(@"C:\Temp\in.pdf");
myDocPdf.Save(@"C:\Temp\tmp.docx", Aspose.Pdf.SaveFormat.DocX);
//Appending this converted Word to another Word document.
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.KeepSourceNumbering = true;
importFormatOptions.IgnoreHeaderFooter = false;
Document temp = new Document(@"C:\Temp\tmp.docx");
temp.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
Document doc = new Document();
doc.FontInfos.EmbedTrueTypeFonts = true;
doc.AppendDocument(temp, ImportFormatMode.KeepSourceFormatting, importFormatOptions);
doc.Save(@"C:\Temp\out.docx");
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.
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/
@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…
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