I’m using GroupDocs Watermark for Java. In my local Windows environment, running a Spring Boot project in debug mode, Korean characters in the watermark are displayed correctly. However, when I run the same project in a Linux environment using Docker, the Korean characters appear garbled. What should I check to resolve this issue?
This issue may arise from missing fonts in the server or Linux environment. Ensure that the necessary fonts are installed on the server. If the problem continues, we will need the Docker image, source files, and example code to reproduce the issue on our end.
Thank you for your response.
It was indeed a font issue. However, the font is not applied only when adding a TextWatermark to an image. For example, the same font is applied correctly to a PDF, but not when adding a TextWatermark to an image. Please see the code comparison below.
[Add TextWatermark To Image: Font Not Applied]
ImageLoadOptions loadOptions = new ImageLoadOptions();
Watermarker watermarker = new Watermarker(filePath, loadOptions);
String baseText = String.format("strictly confidential, printed by %s, %s", userName, userId);
Font watermarkFont;
try {
watermarkFont = new Font("MyFont", 15);
} catch (Exception e) {
watermarkFont = new Font("DejaVu Sans", 15);
}
TextWatermark footerTextWatermark = new TextWatermark(baseText, watermarkFont);
footerTextWatermark.setForegroundColor(Color.getGray());
footerTextWatermark.setBackgroundColor(Color.getAntiqueWhite());
footerTextWatermark.setHorizontalAlignment(HorizontalAlignment.Left);
footerTextWatermark.setVerticalAlignment(VerticalAlignment.Bottom);
footerTextWatermark.setOpacity(0.5);
watermarker.add(footerTextWatermark);
[Add TextWatermark To PDF: Font Applied]
PdfLoadOptions loadOptions = new PdfLoadOptions();
Watermarker watermarker = new Watermarker(filePath, loadOptions);
String baseText = String.format("strictly confidential, printed by %s, %s", userName, userId);
StringBuilder watermarkTextBuilder = new StringBuilder();
int repeatCount = 10;
for (int i = 0; i < repeatCount; i++) {
watermarkTextBuilder.append(baseText);
}
String watermarkText = watermarkTextBuilder.toString();
Font watermarkFont;
try {
watermarkFont = new Font("MyFont", 40);
} catch (Exception e) {
watermarkFont = new Font("DejaVu Sans", 40);
}
Color watermarkColor = Color.getGray();
double opacity = 0.1;
double rotationAngle = -10;
PdfArtifactWatermarkOptions textWatermarkOptions = new PdfArtifactWatermarkOptions();
int pageCount = watermarker.getDocumentInfo().getPageCount();
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
double pageWidth = watermarker.getDocumentInfo().getPages().get_Item(pageIndex).getWidth();
double pageHeight = watermarker.getDocumentInfo().getPages().get_Item(pageIndex).getHeight();
double lineHeight = watermarkFont.getSize() * 3;
double startX = 0;
for (double y = 0; y < pageHeight; y += lineHeight) {
for (double x = startX; x < pageWidth; x += watermarkText.length() * 20) {
TextWatermark textWatermark = new TextWatermark(watermarkText, watermarkFont);
textWatermark.setForegroundColor(watermarkColor);
textWatermark.setOpacity(opacity);
textWatermark.setRotateAngle(rotationAngle);
textWatermark.setX(x - y);
textWatermark.setY(y);
watermarker.add(textWatermark, textWatermarkOptions);
}
}
}
Font subWatermarkFont;
try {
subWatermarkFont = new Font("MyFont", 15);
} catch (Exception e) {
subWatermarkFont = new Font("DejaVu Sans", 15);
}
TextWatermark headerTextWatermark = new TextWatermark(baseText, subWatermarkFont);
headerTextWatermark.setForegroundColor(Color.getRed());
headerTextWatermark.setHorizontalAlignment(HorizontalAlignment.Left);
headerTextWatermark.setVerticalAlignment(VerticalAlignment.Top);
TextWatermark footerTextWatermark = new TextWatermark(baseText, subWatermarkFont);
footerTextWatermark.setForegroundColor(Color.getBlue());
footerTextWatermark.setHorizontalAlignment(HorizontalAlignment.Left);
footerTextWatermark.setVerticalAlignment(VerticalAlignment.Bottom);
watermarker.add(headerTextWatermark, textWatermarkOptions);
watermarker.add(footerTextWatermark, textWatermarkOptions);
Could you please help identify why the font is applied correctly in PDFs but not in images?
@Kim_KyungMok
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WATERMARKJAVA-146
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Could you please provide the TTF file for the custom font “MyFont” mentioned in your sample code? We would like to reproduce the issue on our side using that specific font. Additionally, could you share image samples showing where Korean characters are displayed correctly and where they are not?
I used the NanumSquareR font and have compressed and sent the TTF file to you.
NanumSquareR.zip (278.1 KB)
I am using GroupDocs Watermark for Java version 24.11, and when applying a TextWatermark to an image, the desired font is not being set. This issue occurs for both Korean and English text.
[When outputting in JPG : failure case]
_d84a70a8-59f9-4563-98fd-3978b4a9a67b (1).jpg (91.9 KB)
image.jpg (22.3 KB)
[When outputting in PDF : success case]
image.png (16.3 KB)
You don’t need to worry about the color.
Thank you.
Thanks for the details. We’ll continue investigation and notify you in case of any update or if any further details are required.
hi @Kim_KyungMok
We reviewed the samples you provided, and both the Korean and English characters seem to be presented correctly in the failure case. Could you please clarify what specifically is wrong with the failure case?
Additionally, I noticed that the image sample seems to use the BackgroundColor
setting, whereas the PDF sample does not. Could this difference be related to the issue you’re experiencing? Any further details would help us better understand and address the problem.
Looking forward to your response!
Hi @alexndr, Thank you for your response.
I am having an issue regarding the application of the ‘NanumSquareR’ font. In successful cases, the ‘NanumSquareR’ font is correctly applied, but in failed cases, it is not. You can notice the difference in the appearance of characters, particularly by looking at the letter ‘y’ in English. The shape of the Korean characters also differs. I have explicitly specified the application of the same font in the code.
I would like to request support for this issue.
Hi @Kim_KyungMok , thank you for the clarification.
While we continue our investigation, could you please try setting the following environment variable in your Docker Linux configuration?
ENV LANG=ko_KR.UTF-8
Let us please know if this helps improve the consistency of the ‘NanumSquareR’ font application.
I have added the environment variable, but it did not have any effect.
Is there a significant difference between adding a text watermark to a PDF and adding a text watermark to an image? It is strange that the font is not being applied only when adding a text watermark to the image.
Could you please check if others are successfully applying the desired font for the watermark on images in their environments? Thank you!
Hi @Kim_KyungMok ,
Yes, there are internal differences in how we handle PDF files versus image files when applying text watermarks.
Could you please share the exact font name you pass into the Font
constructor for NanumSquareR.ttf
?
We have identified a potential issue. For images, the input argument is treated as the font family name, while for PDFs it uses the full font name. Some fonts have identical family and full names, so the issue never surfaced before. However, the NanumSquareR.ttf
font has a family name "NanumSquare"
and a full name "NanumSquare Regular"
. For reference, here’s a screenshot showing the font details:
- [font.png](13.0 KB)
This means:
- If your code uses the full font name, for example:
watermarkFont = new Font("NanumSquare Regular", 15);
it will likely work properly for PDFs but not for images.
- If you try using the family name, for example:
watermarkFont = new Font("NanumSquare", 15);
this should work correctly for images.
Additionally, please ensure that the font is properly installed in your Linux Docker environment. For instance:
# Add custom font
COPY ["ConsoleApp1/NanumSquareR.ttf", "/usr/share/fonts/truetype/"]
Let us know if this resolves the issue. We may need some time to prepare a fix for the described behavior, but your feedback will help guide our next steps.
Thank you for your assistance in identifying the issue.
Thanks to your help, we have resolved it.
For PDFs, we specified the font using the font file name (i.e., the TTF file name):
watermarkFont = new Font("NanumSquareR", 15);
For images, we used the full name of the font, which for NanumSquareR is “NanumSquare Regular”:
watermarkFont = new Font("NanumSquare Regular", 15);
By specifying the fonts this way, we were able to display the desired font correctly.
Once again, thank you for your support in addressing this issue!