I am currently working on a DOCX to PDF conversion project using Syncfusion on AWS Lambda. I want to load custom fonts from a Lambda layer to use in my conversion process.
Times New Roman, Arial, etc.) in a directory /opt/fonts./opt/fonts/.FontSettings_SubstituteFont event is fired, indicating that Syncfusion cannot find the fonts.How can I make sure Syncfusion can properly read and use the fonts from the Lambda layer during the conversion? Any additional configurations or modifications needed?
Hi Mohammad,
To check and ensure all fonts are properly installed in the environment, you
can use the font substitution event to handle any missing fonts. In this
event, you can detect which fonts are unavailable and provide the path to the
appropriate font file to preserve formatting during the conversion process.
Please refer to the GitHub sample below, which
demonstrates how to use the font substitution event and reference fonts stored
in the Data directory of your application.
Convert-Word-document-to-PDF-MyLamdaProject
Similarly, if you're using a custom font directory like opt/fonts, you can
specify the path in the font substitution event as shown below:
|
private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args) { if (args.OriginalFontName == "Calibri") args.AlternateFontStream = new FileStream(Path.GetFullPath(@"opt/fonts/calibri.ttf"), FileMode.Open, FileAccess.Read); else if (args.OriginalFontName == "Arial") args.AlternateFontStream = new FileStream(Path.GetFullPath(@"opt/fonts/arial.ttf"), FileMode.Open, FileAccess.Read); else args.AlternateFontStream = new FileStream(Path.GetFullPath(@"opt/fonts/times.ttf"), FileMode.Open, FileAccess.Read); } |
If you still encounter an issue, kindly modify and share the GitHub sample
as issue reproducible sample. This will help us analyze and replicate the
issue on our side for further investigation.
Regards,
Sindhu Ramesh.
Hi Sindhu,
I'm already handling the fonts in the font substitution event, following the GitHub link you shared. The only difference is that instead of bundling the fonts within the package, I’m reading them from a Lambda layer.
However, my question is:
Is there a way to check if the required fonts are present in the Lambda layer before the substitution event is triggered? Similar to how it works on a server — where we install fonts and they are picked up by default — can we do something like that with fonts from the Lambda layer?
Thanks & Regards,
Taha
Mohammad,
We are currently setting up a similar environment where fonts are loaded from
the Lambda layer. We will check and share further details within two days.
Mohammad,
|
Regarding: |
Syncfusion detects fonts that are available in the current production environment; it does not automatically access fonts directly from the AWS Lambda layer. To use fonts from a Lambda layer, you can manually specify the path to the layer within the FontSubstitution event. We prepared an AWS sample that uses fonts from Lambda layer. Kindly refer to the attached sample. |
|
Regarding “Is
there a way to check if the required fonts are present in the Lambda layer before
the substitution event is triggered?” |
No,
it is not feasible directly check whether the corresponding font is available
in the Lambda layer, as the file name may differ from the font name used in
the document. We suggest to get the list of fonts used in the Word document
and create a custom Lambda layer containing those fonts. To ensure consistent font preservation, we recommend the following solutions:
|