@rnara Have you tried implementing IWarningCallback to get a notification when font substitution is performed. As mentioned above, Aspose.Words requires the fonts used in the source document to properly render the document.
Hi @alexey.noskov,
By implentation of IWarningCallback | Aspose.Words for Java , we are getting completely different content attached below.
outp.pdf (32.1 KB)
In our case we have arial font installed in our system by default and that is being subsituted.
Can you please tell how we can use simplified Arabic font instead of arial in the document while rendititon
Thanks,
Krishna
@rnara I mean implemention IWarningCallback
to get notifications about font substitutions. The document you have attached uses Fanwood
font. Most likely the environment does not have available fonts at all, since the last resort font Fanwood
is used for rendering the document. This font is embedded into Aspose.Words library and is used if no other fonts are available.
Hi @alexey.noskov ,
I have tried implementing IWarningCallback | Aspose.Words for Java but still i don’t see any warnings for font substitution.
As in output file I can see Arial font is being substituted but warning is not coming up on console.
I have tried installing Fanwood font also but still the output is not as expected.
Output file shared below :
output.pdf (101.7 KB)
Thanks,
Krishna
@rnara It looks like misunderstood me. I mean that in the PDF you have attached Fanwood
font is used instead the font specified in your source document. This occurs when there are no font available in the environment where document is converted to PDF. Aspose.Words uses Fanwood
font as the last resort font.
Please try using the following code to check for warnings:
Document doc = new Document("C:\\Temp\\in.docx");
doc.setWarningCallback(new FontSubstitutionWarningCollector());
doc.save("C:\\Temp\\out.pdf");
private static class FontSubstitutionWarningCollector implements IWarningCallback {
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION) {
System.out.println(info.getDescription());
}
}
}
Hi @alexey.noskov ,
I have tried implementing above code and different ways using https://reference.aspose.com/words/java/com.aspose.words/iwarningcallback/
but still, it does not show up any font substitution in console.
As the substitution is happening to arial and this is default.
Please check image below:
Thanks,
Krishna
@rnara As I can see, in the document you have attached above Simplified Arabic
font is used. So Aspose.Words uses correct font for rendering PDF.
But as mentioned above, to properly render your document, it is required to enable open type features:
https://forum.aspose.com/t/pdf-rendition-is-not-getting-generating-like-word-document/308458/3
Hi @alexey.noskov ,
I was trying implementing open type, but I didn’t find package to import for below line:
String dataDir = Utils.getDataDir(OpenTypeFeatures.class);
I tried below code instead:
Document doc = new Document("test.docx");
doc.getLayoutOptions().setTextShaperFactory(HarfBuzzTextShaperFactory.getInstance());
doc.save("opentype.pdf")
After implementing above code I can see the fonts are getting replaced by Calibri bold as shown below
Thanks,
Krishna
@rnara Enabling Open Type Feature does not affect font substitution. Here is the PDF document produced on my side:
out.pdf (64.5 KB)
As I can see it looks the same as PDF produced by MS Word.
Hi @alexey.noskov ,
Can you please share the code which you are using for these transformations which includes open type features?
Thanks,
Krishna
@rnara Sure, I used the following code:
// Open a document
Document doc = new Document("in.docx");
// When text shaper factory is set, layout starts to use OpenType features.
// An Instance property returns static BasicTextShaperCache object wrapping HarfBuzzTextShaperFactory
doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());
// Render the document to PDF format
doc.save("out.pdf");
Hi @alexey.noskov ,
I have tried above code provided but still transformation is not as expected and still getting Calibri Bold in output file.
Thanks,
Krishna
@rnara Could you please convert the document to XPS and PDF using the following cod eon your side and attach the output here for our reference?
Document doc = new Document("in.docx");
doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());
doc.save("out.pdf");
doc.save("out.xps");
Does IWarningCallback
show any warnings upon conversion on your side?
Hi @alexey.noskov ,
I tried reproducing and now I don’t see any Calibri or other fonts expect arabic.
But the signature part is still not aligned as shown in image below
I have attached both out.pdf and out.xps files below.
files.zip (149.6 KB)
Thanks,
Krishna
@rnara I cannot reproduce the problem on my side using the latest 25.2 version of Aspose.Words:
out_java_harfbuzz.pdf (64.5 KB)
Hi @alexey.noskov ,
As we have tried all possibilities suggested but none of them worked.
Can you please provide any solution on how we can move ahead or fix this issue?
Thanks,
Krishna
@rnara Unfortunately, There are no other recommendations then provided above. To sum them up to get the correct rendering on my side I made the following actions:
Used the following code and the latest version of Aspose.Words for Java:
// Open a document
Document doc = new Document("in.docx");
// When text shaper factory is set, layout starts to use OpenType features.
// An Instance property returns static BasicTextShaperCache object wrapping HarfBuzzTextShaperFactory
doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());
// Render the document to PDF format
doc.save("out.pdf");
Hi @alexey.noskov ,
Can you please share Language & Region settings from the environment where the issue is not reproducible?
Thanks,
Krishna
Hi @alexey.noskov ,
I am also having same locale but still not getting expected output file.
I have tried everything suggested but nothing worked.
Any way we can progress on this?
Thanks,
Krishna