Word to PDF conversion issue in hindi mangal font and images are look like Distorted appearnce not good

Hello,
I am using aspose.word in java product and converting docx file to pdf file using that. I am facing below two issue there :

  1. Hindi “Joda Akshar” not coming as it is given in docx.
    e.g in docx there is ‘निम्नलिखित’ word after converting into pdf file out put getting like this
  2. On conversion of docx to pdf , image quality is not proper in pdf. Distorted image appeared in pdf after conversion.

Aspose Product: word.aspose in java
version : 22.11
Code :

Document convDoc;
try {
    convDoc = new Document(docxFile.getAbsolutePath());
    convDoc.save( new FileOutputStream(pdfFile), SaveFormat.PDF);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Word Input file and pdf out file : DOCXToPDF_issue.zip (152.0 KB)

Please guide us to resolve those issue.

@nitinchopkar You should enabling open type features to get the desired result. To achieve this you should add reference to Aspose.Words Shaping Harfbuzz plugin:

<dependency>
	<groupId>com.aspose</groupId>
	<artifactId>aspose-words</artifactId>
	<version>22.11</version>
	<classifier>shaping-harfbuzz-plugin</classifier>
</dependency>

and use the following code for conversion:

Document doc = new Document("C:\\Temp\\in.docx");
doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());
doc.save("C:\\Temp\\out.pdf");

Here is the output document produced by this code: out.pdf (53.5 KB)

#1 * Hindi “Joda Akshar” not coming as it is given in docx.
e.g in docx there is ‘निम्नलिखित’ word after converting into pdf file out put getting like this

this issue resolved by adding ‘shaping-harfbuzz-plugin’.

Thank you.

Any solution regarding #2 issue “image quality is not proper in pdf. Distorted image appeared in pdf after conversion”

@nitinchopkar You can try to disable image downsampling and specifying UseAntiAliasing option:

Document doc = new Document("C:\\Temp\\in.docx");
PdfSaveOptions opt = new PdfSaveOptions();
opt.getDownsampleOptions().setDownsampleImages(false);
opt.setUseAntiAliasing(true);
doc.save("C:\\Temp\\out.pdf", opt);

But images in your document are simple raster png images, so both Aspose.Words and MS Word cannot render them better then they are. For example see PDF produced by MS Word on my side: ms.pdf (92.1 KB)

I tried by adding below code but still , I am getting same out put, there is improvement in image quality.

Document convDoc;
try
{
    convDoc = new Document(docxFile.getAbsolutePath());
    convDoc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());

    PdfSaveOptions opt = new PdfSaveOptions();
    opt.getDownsampleOptions().setDownsampleImages(false);
    opt.setUseAntiAliasing(true);
    convDoc.save(new FileOutputStream(pdfFile), opt);

}
catch (Exception e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}

quality of image is better into your provided ms.pdf file https://forum.aspose.com/uploads/default/72941.

Like that we want.

Please guide use to improve image quality while converting into pdf.

@nitinchopkar Please try also specify PdfImageCompression.JPEG

PdfSaveOptions opt = new PdfSaveOptions();
opt.getDownsampleOptions().setDownsampleImages(false);
opt.setUseAntiAliasing(true);
opt.setImageCompression(PdfImageCompression.JPEG);

here is output: out.pdf (55.4 KB)

Yes, its worked for me. Problem resolved

Thank you.

1 Like