we are using different fonts of template Burmese and Khmeer
while saving to word its working fine and saving to Pdf showing boxes
It seems that you are experiencing issues with displaying Khmer and Burmese text correctly in PDF format, where the text appears as boxes. This typically occurs when the font used does not support the specific Unicode characters for these languages.
To resolve this issue, you can try the following steps:
-
Use Compatible Fonts: Ensure that the fonts you are using for Khmer and Burmese text are capable of displaying these characters. Fonts like “Noto Sans Khmer” for Khmer and “Noto Sans Myanmar” for Burmese are good options as they support a wide range of Unicode characters.
-
Font Substitution: If you are using Aspose.Cells, you can utilize the
PdfSaveOptions.setFontSubstitutionCharGranularity()
method. By setting this property to true, you can ensure that only the specific characters that cannot be displayed by the chosen font will have their font changed, while the rest of the text remains unaffected. This can help maintain the integrity of your text formatting. -
Embed Fonts: When saving your document to PDF, make sure to embed the fonts used in the document. This ensures that the PDF viewer can render the text correctly, even if the viewer does not have the fonts installed.
-
Check for Updates: Ensure that you are using the latest version of Aspose libraries, as updates may include improvements and fixes related to font handling and Unicode support.
By following these steps, you should be able to improve the rendering of Khmer and Burmese text in your PDF documents. If the problem persists, consider checking the documentation or reaching out to the support community for further assistance.
Sources:
[1]: Change the Font on just the specific Unicode characters while saving to PDF
I tried with this two fonts, still seeing same can you please help me.
Can you please share the sample code as well? We will test the scenario in our environment and address it accordingly.
Can you please share the sample code as well? We will test the scenario in our environment and address it accordingly.
public ResponseEntity<?> testFont() throws ParseException, UnknownHostException, JAXBException, IOException {
try {
LOGGER.info("Entered into PDF generation webservice implementation");
FontSettings.getDefaultInstance()
.setFontsFolder(getClass().getClassLoader().getResource("fonts").getPath() + "/", false);
List<CoverageDocumentBatch> switchForPageCount = coverageDocumentBatchDao.getBatchstatus(40);
/* Enable License for Aspose Word Object*/
com.aspose.words.License license = new com.aspose.words.License();
FileInputStream fileWordsLicense = new FileInputStream(getClass().getClassLoader().getResource(PrintServerBoImplConstants.ASPOSE_LIC).getFile());
license.setLicense(fileWordsLicense);
/* Enable License for Aspose Barcode Object*/
LOGGER.info("License file path is "+getClass().getClassLoader().getResource(PrintServerBoImplConstants.ASPOSE_LIC).getFile());
FileInputStream fileBarcodeLicense = new FileInputStream(getClass().getClassLoader().getResource(PrintServerBoImplConstants.ASPOSE_LIC).getFile());
com.aspose.barcode.License barcodelicense = new com.aspose.barcode.License();
barcodelicense.setLicense(fileBarcodeLicense);
if(license.getIsLicensed()){
LOGGER.info("Licensed S/w");
}
Document doc = new Document("/template/New folder/test.dot");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("khmer សាកល្បងភាសាខ្មែរ");
builder.writeln("Burmese အရေးကြီးသည့်အချက်- ");
doc.save("/template/New folder/testLanguagefont.pdf");
PdfResponseBO pdfResponse = new PdfResponseBO("200",PrintServerBoImplConstants.PDF_SUCCESS,null,null,0,null);
if(fileWordsLicense != null) {
try {
fileWordsLicense.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fileBarcodeLicense != null) {
try {
fileBarcodeLicense.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return new ResponseEntity<PdfResponseBO>(pdfResponse,HttpStatus.OK);
// LOGGER.info("PDF generator webservice return the response to PDF generator Service ");
} catch (Exception ex) {
LOGGER.error(ex);
throw new com.aspose.barcode.BarCodeException();
}
}
@prathibareddy Most likely the problem occurs because the font is not properly 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/