Hello, I’m encountering a performance issue when rendering a PDF using the Aspose.PDF library.
When the document contains Chinese Simplified (zh-CN) or Chinese Traditional (zh-TW) text, I set:
pdfDocument.OptimizeResources(new OptimizationOptions()
{
SubsetFonts = true
});
On my local machine, calling:
pdfDocument.Save(_request.ResultFile);
takes only about 3 seconds.
However, when I deploy the same code to Docker (Linux-based container) or our test environment, the Save()
call takes about 6 minutes under the same conditions.
Some notes:
- The issue happens only when
SubsetFonts = true
and the document contains Chinese text.
- English documents, or Chinese documents with
SubsetFonts = false
, save quickly.
- The Docker container already includes required fonts (
fonts-noto-cjk
, fontconfig
, etc.).
- Local environment: Windows, .NET 6, Aspose.PDF latest version.
- Docker: Debian-based image, .NET 6, Aspose.PDF same version.
Question:
I would like to keep SubsetFonts = true
(to reduce PDF size) but still have the same fast performance as my local environment.
- Is there any known cause for such a big performance difference in Linux/Docker?
- Are there recommended font settings, caching, or configuration to speed up
SubsetFonts
processing for Chinese text in Docker?
- Could this be related to font file access speed, font fallback resolution, or encoding handling in Linux?
Any advice or best practices to avoid this delay would be greatly appreciated.
Thank you,
@tuantran3012
It sounds like you’re experiencing a significant performance issue when rendering PDFs with Chinese text in a Docker environment, particularly when using the SubsetFonts
option. Here are some potential causes and actionable steps to improve performance:
Diagnosis & Next Steps
-
Font Configuration: Ensure that the required Chinese fonts are correctly installed and accessible in your Docker container. Font configuration can differ between environments, leading to performance issues.
-
Font Caching: Implement font caching mechanisms to reduce the time taken to access and load fonts during PDF rendering.
-
Resource Optimization: Review your resource optimization settings. While SubsetFonts
is beneficial for reducing file size, it may introduce overhead in certain environments. Experiment with different optimization settings to find a balance between performance and file size.
-
Docker Resource Allocation: Check the resource allocation for your Docker container. Ensure it has sufficient CPU and memory resources, as limited resources can lead to slower processing times.
-
Testing with Different Images: If possible, try using a different base image for your Docker container. Some images may have better performance characteristics for font handling.
-
Logging and Monitoring: Implement logging to monitor the performance of the PDF rendering process. This can help identify specific bottlenecks or issues related to font handling.
Example Code Snippet
Here’s a simple example of how you might set up your PDF optimization:
var pdfDocument = new Document("input.pdf");
var optimizationOptions = new OptimizationOptions
{
SubsetFonts = true,
CompressImages = true,
RemoveUnusedObjects = true
};
pdfDocument.OptimizeResources(optimizationOptions);
pdfDocument.Save("output.pdf");
Additional Considerations
- Font Fallback: Ensure that any fallback fonts your application relies on are also available in the Docker environment.
- Encoding Handling: Verify that the encoding settings in your application are consistent with those used in your local environment.
Please implement these suggestions and monitor the performance. If you continue to experience issues or have further questions, feel free to reach out for additional assistance!
I’ve tried it in many ways, but it still doesn’t work. One thing to note is that when using the NotoSansTC font (or NotoSansTC) and setting SubsetFonts = false
, the rendered text comes out incorrect, some parts are missing or displayed wrong.
image.png (3.1 KB)
I also tried another font that supports Chinese well - HanSans Font, but if SubsetFonts = true
, it renders text with errors similar to NotoSans with SubsetFonts = false
. However, if I set it to true
, it renders correctly, but the file size increases significantly. It seems this is an issue related to the library.
@tuantran3012
Could you specify what version & library you are using?
In case of Linux it’s common to use Aspose.Pdf Drawing version of library as more adapted to Linux environment, maybe that’s the case in this situation
Also, could you provide file and code you used to investigate issue in our environment?