I have a template document that have placeholder field that can be replaced with my value. But after conversion to Pdf, it will make the replaced text into Arial.
There are several issues / constraints for this:
- The template file is dynamic, so the font will be different for each file
- It will be installed in another machine, so the other machine might not have the actual font installed and it will be hard to install that every time the template change
How to ensure, the format do not change for this?
Hi Dionisius,
If the specified font doesn’t exist on the machine converting the document to PDF, a fallback font will be used. This is the expected behavior of all Word applications (including Microsoft Word).
In other words, if the font specified in the Word document doesn’t exist on the machine rendering/displaying the document’s content, another font must be used to draw that content.
Unfortunately, there may be differences in what fallback font is picked between different versions of Word applications.
So in short, if the font file doesn’t exist the fallback font will be used which can result in some noticeable format change.
You can control what fallback font is used using the following event:
FontSettings.FontSelection += (sender, e) =>
{
if (e.Font is null)
{
// Set "e.Font" to one of the fonts from FontSettings.Fonts collection.
}
};
var document = DocumentModel.Load("input.docx");
document.Save("output.pdf");
I hope this helps, let me know if you have any questions.
Regards,
Mario