Shape Text is Truncated after DOCX to PNG/PDF Conversion using Java 8 at CentOS

Hi,
Have facing issue when convert the word docx document to PDF/PNG, the header image content will be cutoff.
Converted image. image.png (10.8 KB)
Sample document.
Sample.docx (66.1 KB)

The method is use was refer to example in github.

@securemetric

We have tested the scenario using the latest version of Aspose.Words for .NET 21.8 and have not found the shared issue. So, please use Aspose.Words for .NET 21.8. We have attached the output PDF with this post for your kind reference. 21.8.pdf (34.9 KB)

Hi,

I’m using Aspose.words for Java version 21.80-jdk17, I have try several method. Below with the same sample code.

ByteArrayOutputStream bOut = new ByteArrayOutputStream();  
com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(file));  

ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setDmlRenderingMode(DmlRenderingMode.DRAWING_ML);
imageSaveOptions.setResolution(80);
imageSaveOptions.setMemoryOptimization(true);            
imageSaveOptions.setHorizontalResolution(72f);
imageSaveOptions.setVerticalResolution(72f);
imageSaveOptions.setScale(96f / 72f);
			           
imageStream = new ByteArrayOutputStream();
imageSaveOptions.setPageSet(new PageSet(pageIndex));  
doc.save(imageStream, imageSaveOptions);

I have try same document on aspose online tools was no issue at all, but however i using the example code but not working as expected. Do you able provide the working version sample code in java?

Thanks.

@securemetric

We have tested the scenario using following code example and have not faced the shared issue. Please check the attached output PNG. 21.8.png (8.0 KB)

Document doc = new Document(MyDir + "Sample (5).docx");
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setDmlRenderingMode(DmlRenderingMode.DRAWING_ML);
imageSaveOptions.setResolution(80);
imageSaveOptions.setMemoryOptimization(true);
imageSaveOptions.setHorizontalResolution(72f);
imageSaveOptions.setVerticalResolution(72f);
imageSaveOptions.setScale(96f / 72f);
imageSaveOptions.setPageSet(new PageSet(0));

doc.save(MyDir + "21.8.png", imageSaveOptions);

Could you please save the document to PDF and PNG and share both files here for our reference? Please also share your working environment e.g. operating system, Java version etc.

Attached with the png that i converted and save.
6335_6910_41280_210824.png (16.5 KB)

We are running the code CentOS 8, Java 1.8, the application is running under apache tomcat 8.
Please let me know if need more details.

Thanks.

@securemetric

Please save your document to PDF and share it also. We need PDF file for investigation. Thanks for your cooperation.

Hi attached with converted pdf. Thanks.

6335_6936_210825.pdf (684.6 KB)

@securemetric

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:
https://docs.aspose.com/words/java/using-truetype-fonts/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

Please install ‘Calibri’ font on the machine where you are converting document to fixed page formats.

Hi,

Thanks for help, it solve the problem off the cutoff margin. But it create another problem on the bullet point is not convert properly and become some weird icon. I try at aspose online tools, the converted PNG was no issue.

Is that also issue on the font on the OS? Can provide solution?

Converted image.
6335_6949_41441_210826.png (21.6 KB)

Original document:
fontpattern.docx (66.0 KB)

Thanks.

Yes, this issue is also related to missing fonts. Please implement IWarningCallback interface to get the missing fonts notifications.

Hi,

Which if detected there is warning about the missing font, then system need to manually replace with others fonts ?

Have not sure the solution here, because IWarningCallback it just show detect when there is missing font. What need to done next ? Manually set others fonts or how ?

Can explain more details, if possible share more sample snippet code ?

Appreciate for the help.

@securemetric

You need to install missing fonts used in your document to get the correct output. Please read following article about installing fonts.
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

The answer of your query is well explained in the following article along with code examples.
https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts

You can specify the font’s folder along with system fonts using Aspose.Words. We suggest you please read following article also.

https://docs.aspose.com/words/java/specify-truetype-fonts-location/

Hi Tahir,

I’m sorry i was confuse with the step and action from the sample link that you have, please correct if my understanding is wrong.

First we need to do the warning handler callback and get the substitution warning, but another example was need the XML.

Can you please give more straight forward instruction on how to solve this instead?

Thanks.

@securemetric

The simple answer of your issue is that please install the fonts used in your input Word document on the machine where you are converting document to PDF.

You do not need to use XML (TableSubstitutionSettings). If you want to substitute the missing fonts with your desired fonts, you can use this approach.

Hi Tahir,

I have already install the True Type font, this is solve the issue of the cutoff margin. However it not able to solve the bullet point issue.

What you means i need find each uploaded document have using which font and manually install it to my machine/server?

The document upload function is dynamic and I have difficulty to install the font on real time. How we able to do that ?

@securemetric

Do you receive missing fonts notifications after implementing IWarningCallback interface? If you do not receive any notifications, please ZIP and attach your input, problematic and expected output PDF files here for testing.

Mostly, common fonts are installed on the Windows machine. You can copy these fonts to your Linux machine.

To render the document to fixed file format e.g. PDF, you need to upload the required fonts on the machine where you are converting document to PDF.

Hi Tahir,

I have try to check fonts on the Mircosoft Words, then manually apply the missing fonts to Linux machine, then it’s work. Thanks.

Just my opinion, If possible maybe Aspose can share most of the common Microsoft Office fonts for Words, Excel and PPT. Then we can manually setup and apply at the Linux machine to avoid such cases in future.

Thanks again for the help.

@securemetric

Please note that common fonts are installed by Windows 10. You can copy these fonts to your Linux machine.