Aspose Words PDF differences on environment

Hi Team, I am working with Aspose Words 19.4 to convert a word .doc template to a PDF .

I am doing this in the backend using Spring Boot and Java. When I run my project locally, the PDF produced looks normal and has the formatting I intended. When I run it from Pivotal Cloud Foundry , the formatting is off in several locations. Spacing becomes wider in some places and things that were supposed to be right next to each other move further down the page. I have tried to eliminate all other variables so I am fairly sure it is the difference in environments that is causing this.

I was wondering if anyone else has faced a similar problem and knows a solution, or if there might be other problems that could cause this? Let me know if more information is needed, Thanks in advance!PDF_Generated_LocalWindows.pdf (184.1 KB)
PDF_Generated_PCFPlatform.pdf (94.7 KB)

Find the attached PDF generated Locally and PCF cloud environment.

@ganeshtech,

Please upgrade to the latest version of Aspose.Words for Java i.e. 19.6 and see how it goes on your end? In case the problem still remains, please ZIP and upload your input Word document (you are getting this problem with) here for testing. We will then investigate the issue on our end and provide you more information.

I have now modified the Aspose.Words version to 19.6 (using aspose-words-19.6-jdk17.jar) and added the dependency in my pom.xml

<dependency>
<groupId>aspose-words</groupId>
<artifactId>aspose-words</artifactId>
<version>19.6</version>
</dependency>

After deploying it to Cloud environment the problem still persist.
I have attached the Word document template for your further investigation.
Thank you.PDFGenerationTemplate.zip (80.5 KB)

@ganeshtech,

Please check below the PDF outputs that we produced on our end by using MS Word 2019 and the following code of Aspose.Words for Java 19.6:

Both these PDFs look identical.

Document doc = new Document("E:\\PDFGenerationTemplate\\PDFGenerationTemplate.doc");
doc.save("E:\\PDFGenerationTemplate\\awjava-19.6.pdf");

Instead of saving to PDF, using the code on your end, can you please save the final output to DOCX format, ZIP and attach the Word output here for further testing?

Attached the docx output generated after the below code change
Templatedoc.zip (254.1 KB)

from

String fileName = new SimpleDateFormat("yyyyMMddHHmms").format(new Date()) + ".pdf";
doc.save(dynamicDirectory.getPath() + "/" + fileName, SaveFormat.PDF);

to

String fileName = new SimpleDateFormat("yyyyMMddHHmms").format(new Date()) + ".docx";
doc.save(dynamicDirectory.getPath() + "/" + fileName, SaveFormat.DOCX);

I have attached 3 docx document
PDFGenerationTemplate.docx (Template document now changed from doc to docx)
20190628181931-PCF.docx (Docx Output Generated in PCF cloud)
20190628182017-Windows10.docx(Docx Output Generated local windows)

Output generated using DOCX in PCF provided the desired results, same looks different when it is generated using PDF.
I tried removing the SaveFormat.PDF from doc.save() doesn’t make any difference.
please let me know if you need any additional information.

@ganeshtech,

Please install the following fonts (copy Font files from Windows machine to other machine’s Fonts folder) to be able to get the correct PDF output:

  • ‘Lucida Sans’
  • ‘Arial’
  • ‘Calibri’
  • ‘Arial Narrow’
  • ‘Microsoft Sans Serif’

These are required because your Word document uses these Fonts. For more details, please refer to the following articles:

https://docs.aspose.com/words/java/using-truetype-fonts/
https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts/

As suggested I tried copying above-mentioned 5 fonts from wondows/fonts to the application resources/fonts custom folder and referred the same in the code like below.

log.info("Fontdir:::"+fontDir);
FontSettings.getDefaultInstance().setFontsFolder(fontDir, false);

now generated pdf looks again different local as desired and PCF not desired.
PCF-version.pdf (68.6 KB)
Local-version.pdf (183.8 KB)
In fact i tried copying entire windows/fonts to the application custom folder.

Can you setup a meeting to discuss this issue, as it is delaying our production deployment.
please let me know how we can connect and discuss this issue.

@ganeshtech,

It seems that Aspose.Words is not able to locate those Font files. Please also make sure that your application has permissions to access that custom fonts folder. Do you see any missing fonts related warnings thrown by Aspose.Words (see How to Receive Notification of Missing Fonts and Font Substitution during Rendering)? Please also try the code from the following section of documentation:
Specifying Fonts to be Read from both the System Fonts Folder and a Custom Folder

Also, when you open these PDF files with Adobe, you will see a difference in Fonts by going to File | Properties | Fonts

https://i.imgur.com/svu3f7h.png

Secondly, I am afraid, the main avenue of technical support is through our forums only and we cannot setup a meeting session. We apologize for any inconvenience.

Now the issue resolved, PDF looks similar in both local and PCF environment.
The problem in reading the custom folder, I have also included the warning notification and allowed fonts to read system fonts folder and custom fonts folder. Thank you for your suggestions :slight_smile:

How to find list of fonts usage from the word template. In future if anyone modifies the template someone need to be find and add the newly introduced fonts in the custom folder.

@ganeshtech,

Please try the following code snippets:

Document doc = new Document("E:\\Templatedoc\\20190628182017-Windows10.docx");

Console.WriteLine("------------------------");
Console.WriteLine("-Fonts used in Document-");
Console.WriteLine("------------------------");
foreach (FontInfo info in doc.FontInfos)
{
    Console.WriteLine(info.Name);
}

Console.WriteLine("-------------------------");
Console.WriteLine("-Fonts used by Run Nodes-");
Console.WriteLine("-------------------------");

ArrayList list = new ArrayList();
NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);
foreach (Run run in runs)
{
    if (!list.Contains(run.Font.Name))
    {
        list.Add(run.Font.Name);
    }
}

foreach (string str in list)
{
    Console.WriteLine(str);
}

thank you I have to refactor your code snippet like below to make it work.

private void getUsedFontsfromDocument(Document doc)
{
    log.info("------------------------");
    log.info("-Fonts used in Document-");
    log.info("------------------------");
    for (FontInfo info : doc.getFontInfos()) {
    log.info(info.getName());
}
log.info("-------------------------");
log.info("-Fonts used by Run Nodes-");
log.info("-------------------------");
ArrayList list = new ArrayList();
NodeCollection runs = doc.getChildNodes(NodeType.RUN, true);
for (Run run : (Iterable<Run>)runs)
{
    if (!list.contains(run.getFont().getName()))
    {
        list.add(run.getFont().getName());
    }
}
for (String str : (Iterable<String>)list)
{
    log.info(str);
}

@ganeshtech,

It is great that you were able to find what you were looking for. Please let us know any time you have any further queries.

A post was split to a new topic: Aspose Words Word to PDF