Zero formatting output is different on Linux OS

I am using Aspose words licensed version to generate pdf report from TXT format. While i am using JBoss on Windows OS to deploy my enterprise application, its working fine and generating expected pdf report ( with “0” as expected ). But when i do same enterprise application deployment on Linux OS and reproduce the same report, in report zero formatting is wrong. On Linux, report consist of zero with dot in between. Could you please guide or suggest its solution?

@parmod.parmod

The issue you’re experiencing with the formatting of the number “0” in the PDF report generated on Linux, where it appears with a dot in between, could be related to differences in font rendering or numeral formatting between the Windows and Linux environments.

Here are a few suggestions to troubleshoot and potentially resolve the issue:

  1. Font Availability: Ensure that the fonts used in your document are available on the Linux server. If the specific font is not installed, Aspose.Words may substitute it with a different font, which could lead to formatting discrepancies. You can specify a font source in your code to ensure the correct fonts are used.

  2. Numeral Format Settings: Check if the numeral format settings are being applied correctly in your code. You can explicitly set the numeral format when saving the document to PDF. For example, you can use the PdfSaveOptions class to set the numeral format to ensure consistency across different operating systems.

  3. Testing with Different Fonts: Try using a different font that is known to be compatible across both Windows and Linux. This can help determine if the issue is font-related.

  4. Update Aspose.Words: Ensure that you are using the latest version of Aspose.Words, as updates may include fixes for cross-platform issues.

  5. Environment Configuration: Sometimes, the configuration of the Java environment (like JDK version or locale settings) can affect how documents are rendered. Make sure that the environment on Linux is set up similarly to that on Windows.

If the problem persists after trying these suggestions, consider reaching out to Aspose support with specific details about the fonts used and the code snippet you are using to generate the PDF. This will help them provide more targeted assistance.

Feel free to ask if you need further clarification or assistance!

@parmod.parmod Could you please attach your input, output and expected documents along with code that will allow us to reproduce the problem? We will check the issue and provide you more information.

Please find attached as issue and expected zero format.
Issue_ZeroFormat


Expected_ZeroFormat

@parmod.parmod Could you please attach your input, output and expected documents in DOCX format and provide code that will allow us to reproduce the problem? We will check the issue and provide you more information. Unfortunately, screenshots does not give enough information to test the scenario and reproduce the problem on our side.

@parmod.parmod To answer the question we need to reproduce the problem on our side. So please provide the requested information. It is not required to provide your actual documents, you can create a simple example just enough to reproduce the problem.

public byte[] generatePdf(int id){
List<ReportDataDetailsVO> data =
        databaseClass.generateData(id);
try (Reader reader = data.get(0).getData().getCharacterStream()) { // Get clob object data as charater stream
	StringBuilder stringBuilder = new StringBuilder();
    try (BufferedReader bufferedReader = new BufferedReader(reader)) {
      String line;
      while ((line = bufferedReader.readLine()) != null) {
        if (line.startsWith("$")) {
          stringBuilder.append('\f');
          line = line.substring(1);
          stringBuilder.append(line);
        } else {
          stringBuilder.append(line);
        }
        stringBuilder.append(System.getProperty("line.separator"));
      }
    }
    byte[] byteArray = new byte[stringBuilder.length()];
    for (int i = 0; i < stringBuilder.length(); i++) {
      byteArray[i] = (byte) stringBuilder.charAt(i);
    }
      outputPdfArray = documentGenerate(byteArray);
    }
}
	
	
private byte[] documentGenerate(byte[] byteArray) {
    try {
      TxtLoadOptions options = new TxtLoadOptions();
      options.setAutoNumberingDetection(false);
      Document document = new Document(new ByteArrayInputStream(byteArray),options));
	if (Objects.nonNull(document.getSections())) {
      for (Section section : document.getSections()) {
        PageSetup pageSetup = section.getPageSetup();

        // Set the orientation to landscape
        pageSetup.setOrientation(com.aspose.words.Orientation.LANDSCAPE);
        pageSetup.setPageWidth(990);
        pageSetup.setPageHeight(850);
      }
    }
	ByteArrayOutputStream out = new ByteArrayOutputStream();
    document.updateFields();
    document.save(out, SaveFormat.PDF);
    
    } catch (Exception e) {
      // throws exception();
    }
    return out.toByteArray();
  }

@alexey.noskov Could you please suggest now? As this code is working fine on Windows but giving above mentioned issue in Linux server application Server.

@parmod.parmod Unfortunately, no, because you still did not provide your input and output documents so we cannot test and reproduce the problem. Please provide at least the data passed into documentGenerate method.

@alexey.noskov as an input you could pass any String having zero (0) such as " 0000 123 Its a sample String with 4 times 0 as prefixed index ". In my scenario i fetch this report data from database which stores this report data in clob object. Report conversion from Clob having TXT data to Pdf is working fine in Windows but giving issues in zero formatting when deploy same enterprise application to Linux server. Issue in format shown in above screenshots. Please suggest and guide.

@parmod.parmod Thank you for additional information. I used the following code for testing:

String data = " 0000 123 Its a sample String with 4 times 0 as prefixed index";
byte[] output = documentGenerate(data.getBytes());
Files.write(Paths.get("/temp/out_linux.pdf"), output);
private static byte[] documentGenerate(byte[] byteArray) {
    try {
        TxtLoadOptions options = new TxtLoadOptions();
        options.setAutoNumberingDetection(false);
        Document document = new Document(new ByteArrayInputStream(byteArray), options);
        if (Objects.nonNull(document.getSections())) {
            for (Section section : document.getSections()) {
                PageSetup pageSetup = section.getPageSetup();
    
                // Set the orientation to landscape
                pageSetup.setOrientation(com.aspose.words.Orientation.LANDSCAPE);
                pageSetup.setPageWidth(990);
                pageSetup.setPageHeight(850);
            }
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        document.updateFields();
        document.save(out, SaveFormat.PDF);
        return out.toByteArray();
    } catch (Exception e) {
        // throws exception();
        return  null;
    }
}

The output looks the same on both Windows and Linux. The difference is only in fonts:
out_linux.pdf (11.3 KB)
out_win.pdf (18.0 KB)

@alexey.noskov So finally you replicated the issue. Have a look at the Linux output pdf there is dot in between zero digit. While in case of windows output its plain zero. Please suggest how to resolve this. Thanks

@parmod.parmod This is the difference in fonts I have mentioned. The problem occurs because the font used in the document is not installed or is not accessible. If Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

@alexey.noskov is their any way in Aspose words where i can restrict my report conversion to use specific font only.

@parmod.parmod You can configure font substitution rules:
https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts/#font-availability-and-substitution

@alexey.noskov Tried to setup to use specified Font as below-

FontSettings fontSettings = new FontSettings();
TableSubstitutionRule substitutionRule = fontSettings.getSubstitutionSettings().getTableSubstitution();
substitutionRule.addSubstitutes("UnknownFont1", new String[] { "Times New Roman" });
TxtLoadOptions options = new TxtLoadOptions();
options.setFontSettings(fontSettings);
options.setAutoNumberingDetection(false);

This is working fine in Windows and showing same issue in Linux. Could you please suggest and help to resolve this?

Thanks,
Parmod

@parmod.parmod As I can see in your code you only configure substitution rule, but do not specify font sources. Please make sure the required fonts are available. Have you tried using IWarningCallback to get a notification when font substitution is performed, as suggested above?

@alexey.noskov tried with below code. But no luck

FontSettings fontSettings = new FontSettings();
TableSubstitutionRule substitutionRule =
    fontSettings.getSubstitutionSettings().getTableSubstitution();
substitutionRule.addSubstitutes("UnknownFont1", new String[] { "Times New Roman" });
TxtLoadOptions options = new TxtLoadOptions();
options.setFontSettings(fontSettings);
options.setAutoNumberingDetection(false);

Document document = new Document(new ByteArrayInputStream(byteArray), options);

FontSubstitutionWarningCollector callback = new FontSubstitutionWarningCollector();
document.setWarningCallback(callback);

// Store the current collection of font sources, which will be the default font source for
// every document
// for which we do not specify a different font source.
FontSourceBase[] originalFontSources = FontSettings.getDefaultInstance().getFontsSources();

// For testing purposes, we will set Aspose.Words to look for fonts only in a folder that does
// not exist.
FontSettings.getDefaultInstance().setFontsFolder("", false);

// When rendering the document, there will be no place to find the "Times New Roman" font.
// This will cause a font substitution warning, which our callback will detect.
document.save(environment.getProperty("reportgeneration.log4j2.configuration")
    + "FontSettings.SubstitutionWarning.pdf");

FontSettings.getDefaultInstance().setFontsSources(originalFontSources);

if (callback.FontSubstitutionWarnings.getCount() != 0)
{
    Assert.assertTrue(callback.FontSubstitutionWarnings.get(0).getWarningType()
        == WarningType.FONT_SUBSTITUTION);
    Assert.assertTrue(callback.FontSubstitutionWarnings.get(0).getDescription()
        .equals(
            "Font 'Times New Roman' has not been found. Using 'Fanwood' font instead. Reason: first available font."));
}

outputPdfArray =
    asposeUtil
        .convertToLandscapePdf(document);

Still its not working. Please suggest and guide.

Thanks,
Parmod

@parmod.parmod Thank you for additional information. But in your code you removing font sources before converting the document to PDF instead of adding them. So in your case all fonts will be substituted with the default Fanwood font. Which is the last resort font, that is used when no other fonts are available.

@alexey.noskov i want to use one of the common font size such as “Times New Roman” which is common for all operating systems. So, is there way where we can set this font type without explicitly passing font sources as we want to use operating systems fonts only. Thanks