@jithin.p You should use PdfSaveOptions.EmbedAttachments property. But please note this is not supported when saving to PDF/A and PDF/UA compliance.
A post was merged into an existing topic: Get EmbedAttachment from a document and replace values using mail merge
Hi,
Thank you very much. It worked. I have one more question. Is there any option to get the EmbedFonts frpm PDF while appending the PDF document to a word document?
We are using the code to convert from PDF to word document then this word document is appending to another main word document. Because the PDF contains EmbedFonts, it is causing the formatting and alignment issues for this particular word document only. Can you please help me? Below are my codes.
//Convert PDF to Word
Aspose.Pdf.Document myDocPdf = GetDocumentByPathPDF(docPath);
string[] _fileNamArr = docPath.Split('.');
myDocPdf.Save(template_path + _fileNamArr[0] + ".docx", Aspose.Pdf.SaveFormat.DocX);
//Appending this converted Word to another Word document.
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.KeepSourceNumbering = true;
importFormatOptions.IgnoreHeaderFooter = false;
temp.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
cloneBuildinPropeerties(temp, OutPut);
OutPut.AppendDocument(temp, ImportFormatMode.KeepSourceFormatting, importFormatOptions);
Thanks
Jithin V P
@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.