Hello,
Having a weird issue while converting HTML to PDF on AWS Lambda.
This is my code block running on the Lambda. It basically converts an HTML string to PDF file and returns the bytes:
But the issue is, blink engine on AWS just ignores the font styles specified in the sample HTML. I used 'Arial' and 'Times New Roman' for the different spans, but they are displayed in some other font. And that font doesn't probably support arabic characters, so this is the output I am getting.
My project file looks like this:
Is there anybody experienced the same issue before? I really appreciate any tip to make this work.
Thanks.
Currently we re checking the reported issue on our end and will update the further details on Aug 8th,2023.
The reported text preservation
issue occurs due to the required font is not available in the AWS lambda
environment. The converter will automatically fallbacks to the system's
available font. So the text may be rendered differently based on the fallback
font. We have to include the required supported font file in our AWS
environment. The arialunicodems.ttf font supports to handle most of
unicode characters, so we have included the fonts to render the characters
correctly. Kindly please include the required supported font files to your AWS
environment like below steps on your end and let us know the result.
Please create a /fonts folder in your project and placed all the needed
font files (in our case arialunicodems.ttf). Then create a config file for font
configuration by using below commands and placed inside that fonts folder,
|
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <dir>/var/task/fonts/</dir> <cachedir>/tmp/fonts-cache/</cachedir> <config></config> </fontconfig> |
|
|
And include the below environment variable in your AWS lambda function,
|
FONTCONFIG_FILE = /var/task/fonts.conf |
|
|
We
have attached the runnable AWS Lambda sample with this solution for your
reference, please find the below link,
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AWSLambdaDockerContainer443714913
Output: https://www.syncfusion.com/downloads/support/directtrac/general/pd/file638271098138637929-2082575647
Please try the above solution on your end and let us know the result.
Hello,
Special thanks for your support. With your suggestion, I overcame the charset issue, and the arabic letters are displayed correctly in the output now.
However, font is still not correctly displayed.
I ran the same code both on my local environment and AWS. The first is the output of the one running on AWS, and second one is taken from the output generated on my local.
The font difference can be seen here clearly. Despite I provided and specified the "Arial" font, the output is printed with different font on AWS.
The font file I used can be found in the attachments. When I install the font on mac, it displays the characters properly in fontbook. So we know the font file is correct.
I am already glad with the solution you provided. It will be extra appreciated if you can suggest a solution for this as well :)
Attachment: arial.ttf_17b5bb08.zip
We have checked the reported behavior with HTML String to PDF in AWS lambda function. The AWS lambda environment default supported font is “DejaVu”. If the provided font is not available, then The converter will automatically fallbacks to the system's available font. To overcome this substitute font behavior, we have to include the supported font file in the AWS environment “/usr/share/fonts/truetype/” location using docker commands. We have included the required font and ensured the output document, its font renders correctly.
Please refer the below docker command to copying the required to system folder
and output screenshot,
|
|
|
|
RUN yum -y install fontconfig COPY fonts /usr/share/fonts/truetype/
RUN fc-cache -f -v |
We have attached the modified sample with output document
for your reference, please find the below link.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AWSLambdaDockerContainerModified-1885088593
Output: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Output-279581168
Fonts: https://www.syncfusion.com/downloads/support/directtrac/general/ze/fonts1549013305
Please try the above solution on your end and let us know the result.
Hello,
Tried to adopt this approach, but I couldn't make it work. Because we have a ci/cd infrastructure creating lambdas from zip files instead of docker images, and I don't have a permission to change this unfortunately.
This is fine though, because fixing the font family is not a mandatory change for us. Our prior concern was displaying the arabic letters properly which is solved thanks to your help. We appreciate your support.
Thanks for the update. We glad to know that your has been resolved.