Free Support Forum - aspose.com

Watermark for japanese doesn't work while converting to pdf

Hi,
We have an issue while converting the document to pdf, the watermark for the Japanese language given in noto sans font family doesn’t work. When the pdf is generated the we see boxes instead of the text. Is there any way we can solve the issue?I have attached the generated pdf
new.pdf (14.4 KB)

@sindhuV

Please note that Aspose.Words requires TrueType fonts when rendering document to fixed-page formats (JPEG, PNG, PDF or XPS). You need to install fonts that are used in your document on the machine where you are converting documents to PDF. Please refer to the following articles:
Using TrueType Fonts
Manipulating and Substitution TrueType Fonts

If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue and provide you more information on it.

Thank you for the reply. The aspose is not picking up the Noto family fonts. Dejavu sans which are true type fonts are also not embedded in the pdf. Also we tried to embed watermark in word and directly convert it to pdf, even though i have the same fonts in my system ( for example: dejavu sans, noto sans cjk jp regular) it does not embed them and use other fonts.
I am attaching you the word documents ( both with watermark from word and without watermark)
watermarkTest.zip (3.5 MB)

@sindhuV

Please attach the following resources here for further testing:

  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here.
  • Please ZIP and attach the following fonts:
    • ‘Noto Sans CJK JP Regular’
    • ‘Noto Serif CJK JP Black’
    • ‘Noto Sans CJK JP Black’

We will investigate the issue and provide you more information on it.

PS: To attach these resources, please zip and upload them.

I have attached the sample source code. I am unable to attach the font files even though i zipped them. But i will include the links from where i downloaded them.
https://www.google.com/get/noto/
watermark.zip (1.3 KB)

@sindhuV

We have tested the scenario using the latest version of Aspose.Words for Java 20.9 and have not found the shared issue. So, please use Aspose.Words for Java 20.9

We have upgraded the version, it works for text but it is not working for watermarks

@sindhuV

Please use the following code example to get the desired output. We have attached the output PDF with this post for your kind reference. Noto Sans CJK JP Regular.pdf (28.7 KB)

Document doc = new Document(MyDir + "notoAndDejaVu.docx");
Watermark watermark = doc.getWatermark();
watermark.setText("Test 会社");
doc.save(MyDir + "Noto Sans CJK JP Regular.pdf");

We have tested this in two scenarios, it has worked in one and not in another.

  1. In our local system ( windows), the watermark has been embedded. The font which is used was calibri, not Noto Sans CJK JP Regular.
  2. In our Linux system, the watermark sometimes disappears and sometimes it appears as boxes. There in the Linux system we have the Noto sans cjk jp - black font and all other noto family fonts. but still it is not picking up the noto font for embedding the watermark.

@sindhuV

Please install the fonts used in your document on the system where you are converting document to PDF.

Please execute the following code at your Linux system and let us know if you face any missing font notification.

Document doc = new Document(MyDir + "notoAndDejaVu.docx");
Watermark watermark = doc.getWatermark();
watermark.setText("Test 会社");
doc.setWarningCallback(new com.aspose.words.IWarningCallback() {
    @Override
    public void warning(com.aspose.words.WarningInfo warningInfo) {
        if(warningInfo.getWarningType() == WarningType.FONT_SUBSTITUTION)
            System.out.println(warningInfo.getDescription());
    }
});
doc.save(MyDir + "Noto Sans CJK JP Regular.pdf");

You may also set the fonts location using FontSettings.SetFontsSources method as shown below. Hope this helps you.

   Document doc = new Document(getMyDir() + "input.docx");
   Watermark watermark = doc.getWatermark();
    watermark.setText("Test 会社");
    ArrayList fontSources = new ArrayList(Arrays.asList(FontSettings.getDefaultInstance().getFontsSources()));

    // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts
    FolderFontSource folderFontSource = new FolderFontSource("...path to noto fonts...", true);

    // Add the custom folder which contains our fonts to the list of existing font sources
    fontSources.add(folderFontSource);

    // Convert the ArrayList of source back into a primitive array of FontSource objects
    FontSourceBase[] updatedFontSources = (FontSourceBase[]) fontSources.toArray(new FontSourceBase[fontSources.size()]);

    // Apply the new set of font sources to use
    FontSettings.getDefaultInstance().setFontsSources(updatedFontSources);

    doc.save(getArtifactsDir() + "Rendering.SetFontsFoldersSystemAndCustomFolder.pdf");

We have executed the code which you have given us to get the notification if the font is missed, we didn’t get any warning that the font is missing. we saw that the noto font was set to the watermark text after setting up font like this: watermark.getTextPath().setFontFamily(“NotoSansCJKjp-Black”);
But still the watermark is missing in the pdf. when we save the document as docx then the watermark is appearing but in the pdf it is missing and now it is happening only for Japanese or Chinese text.

The error we are getting now while saving to pdf is “DATA_LOSS: [FONT] - Parsing glyph data of OpenType(CFF) font is not supported.”

@sindhuV

It seems that you are not using this code example. Please use it and let us know if you still face this issue. The input document you used in your code is not ‘notoAndDejaVu.docx’. If you are using different document, please ZIP and attach it.

Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Thanks for your cooperation.

We have tested following scenarios:

Scenario:1. With snippet you provided:

    Document doc = new Document("notoAndDejaVu.docx");
	Watermark watermark = doc.getWatermark();
	String text = "Test 会社";
	watermark.setText(text);
	doc.setWarningCallback(new com.aspose.words.IWarningCallback() {
		@Override
		public void warning(com.aspose.words.WarningInfo warningInfo) {
			if (warningInfo.getWarningType() == WarningType.FONT_SUBSTITUTION) {
				System.out.println(
						WarningType.getName(warningInfo.getWarningType()) + " " + warningInfo.getDescription());
			}
		}
	});
	doc.save("test110.pdf");

Result:
The pdf was generated with watermark.
There were no warnings for font substitution
The font which was embedded in the generated pdf was times new roman, but we wanted it in noto sans cjk jp black

Scenario: 2. With the same snippet you provided but we added font and logged all warnings:

      Document doc = new Document("notoAndDejaVu.docx");
      Watermark watermark = doc.getWatermark();
   String text = "Test 会社";
	TextWatermarkOptions options = new TextWatermarkOptions();
	options.setFontFamily("Noto Sans CJK JP Black");
	options.setColor(Color.BLACK);
	watermark.setText(text, options);
			doc.setWarningCallback(new com.aspose.words.IWarningCallback() {
	    @Override
	    public void warning(com.aspose.words.WarningInfo warningInfo) {
	        if(warningInfo.getWarningType() == WarningType.FONT_SUBSTITUTION) {
	        	System.out.println(WarningType.getName(warningInfo.getWarningType()) +" "+  warningInfo.getDescription());
	        }
	        else {
	        	System.out.println(WarningType.getName(warningInfo.getWarningType())+ " "+ warningInfo.getDescription());
	        }
	    }
	});
	doc.save("test110.pdf");

Result:

  1. when font set to Noto Sans CJK JP Black
    The pdf was generated, but no watermark found
    Thi warning is shown “DATA_LOSS Parsing glyph data of OpenType(CFF) font is not supported.

  2. When font set to Dejavu Sans
    The pdf was was generated with watermark set to dejavu sans.
    No warnings related to this

Scenario 3: ( In our Windows system)
Result

  1. when font set to Noto Sans CJK JP Black
    The pdf was generated, but no watermark found
    Thi warning is shown “DATA_LOSS Parsing glyph data of OpenType(CFF) font is not supported.

  2. When font set to Dejavu Sans
    The pdf was was generated with watermark set to dejavu sans.
    No warnings related to this

Scenario 4: ( In our Linux system)

  1. when font set to Noto Sans CJK JP Black
    The pdf was generated, but no watermark found
    This warning is shown “DATA_LOSS Parsing glyph data of OpenType(CFF) font is not supported.

  2. When font set to Dejavu Sans
    The pdf was was generated, but no watermark found
    This warning is shown “DATA_LOSS Parsing glyph data of OpenType(CFF) font is not supported.

@sindhuV

We have logged this issue as WORDSNET-21214 in our issue tracking system. You will be notified via this forum thread once it is resolved.

Regarding data loss issue, we have logged it as WORDSJAVA-2469. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@sindhuV

Please note that Aspose.Words does not support parsing of glyph data for OpenType(CFF) and your issue is related to it. This is a missing feature in Aspose.Words and its ID is WORDSNET-13702. We will inform you via this forum thread once this feature is available. The support parsing of glyph data for OpenType(CFF) is a very heavy task. So, it will not be available in near future. Please use fonts other than Noto for watermark.

We apologize for your inconvenience.