In an environment using Aspose.Words 25.9, specifically within a Dockerized setup, the removeBlankPages() method is not removing blank pages as expected. As a result, incorrect internal pageIndex values are assigned during image extraction, leading to failures.
The following exception is encountered when attempting to extract images:
Caused by: java.lang.IllegalArgumentException: Specified argument was out of the range of valid values.
Parameter name: pageIndex
at com.aspose.words.Document.zzXw(Unknown Source)
at com.aspose.words.Document.getPageInfo(Unknown Source)
... 11 more
Added a basic code for the issue
main4-anonymysed.docx (3.5 MB)
This is the document which is causing the issue.
@ELSSAM_elsevier_com
Summary
Document.removeBlankPages() is not removing the blank pages when the code runs inside your Docker container, which leads to an invalid page index being passed to Document.getPageInfo(pageIndex) and the resulting IllegalArgumentException.
Why it happens
- The method relies on the layout engine to detect blank pages. In a minimal Docker image the layout engine may lack required system resources such as fonts or native libraries, causing it to mis‑detect blank pages.
- If the layout cannot be performed correctly, the page count reported by the document remains unchanged, and any subsequent logic that assumes blank pages have been removed may request a page index that no longer exists.
- An improperly loaded license can also cause certain features to be disabled, but the fact that the same code works outside Docker points to missing runtime dependencies inside the container.
What to do next
- Verify required fonts and libraries – Ensure the container image includes common TrueType fonts and the font‑config library (or their equivalents for the base OS). After installing, you can run
fc-list inside the container to confirm fonts are visible.
- Check that the Aspose.Words license is loaded – Load the license file from a path that exists inside the container and confirm that the license is recognized (e.g., by checking
License.isLicensed() if available).
- Run a minimal test to see whether the page count changes:
Document doc = new Document("/app/input.docx");
System.out.println("Pages before: " + doc.getPageCount());
doc.removeBlankPages();
System.out.println("Pages after: " + doc.getPageCount());
If the count does not decrease, the layout engine is still unable to detect blank pages.
4. Collect diagnostic information – When the problem persists, gather:
- The full Dockerfile (base image and installed packages).
- The complete stack trace.
- Confirmation that the same code works on a non‑Docker host with the same Aspose.Words version.
- Any custom fonts embedded in the DOCX that might be missing in the container.
- Consider updating the library – If you are not on the latest Aspose.Words release, try upgrading to the most recent version available through your build system, as newer releases may contain fixes for Docker‑related layout issues.
These steps should help you identify whether missing fonts, libraries, or licensing are preventing removeBlankPages() from working inside Docker, and provide the information needed for further assistance.
I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.
@ELSSAM_elsevier_com As you may know MS Word documents are flow by their nature and there is no “page” concept. To remove blank pages Aspose.Words needs to build whole document layout. To achieve this the fonts are required. Most likely the problem occurs because the fonts used in the document are not available in the environment where document is processed. 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/