Free Support Forum - aspose.com

Problem with High DPI scaling

Hi,

I’m having having some issues with Aspose.Cells when using to produce PDF files on systems with High DPI displays. My app is based on Qt5 and can scale to High DPI displays, but it seems like Aspose.Cells is affected as well. Is there a way to force Aspose.Cells to use e.g. 96 DPI when saving to a PDF using Aspose::Cells::IWorkbook::Save()?

Please find examples of this issue attached to the post. Highdpi_problem.zip (84.7 KB)

@patjep,

I think you may try to set DPI settings to 96 at the start of your program using static SetDPI method of Aspose::Cells::ICellsHelper.

@Amjad_Sahi

I tried the SetDPI/GetDPI combo and can’t get it to work. The result is confusing as the Windows API GetDpiForSystem() returns 240 for my High DPI-display, but your GetDPI returns 96.0. Furthermore, your SetDPI() functions doesn’t seem to affect the PDF at all no matter what value I choose. Does your functions work properly? If so, please explain how I can use them to achieve the effect I want.

@patjep,

Please notice, we reproduced the issue as you mentioned. The static SetDPI method of Aspose::Cells::ICellsHelper does not work in higher display (scale) settings. We have logged a ticket with an id “CELLSCPP-271” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

@patjep,

We found the GetDPI and SetDPI APIs are not implemented in Aspose.Cells for C++. If it is necessary for you, we can try to implement the feature within 7-10 days, please confirm?

@Amjad_Sahi ,

The preferable solution would be to let the IWorkbook::Save() function properly scale objects and images when saving PDF files on GUI apps run on High GPI screen. Implementing the SetDPI/GetDPI might work if the DPI can be set to e.g. 96 before the Save() function is called, and then reset to the previous DPI directly after the call. If you choose this way to fix the issue it’s important that you can change the DPI setting without affecting the rest of the GUI app (like graphical glitches and the like).

@patjep,

Yes, we will go with this way. Once we have more updates on it, we will let you know.

@patjep,

Please try our latest fix: Aspose.Cells for C++ v20.7.1_new

Your issue should be fixed in it.

Let us know your feedback.

@Amjad_Sahi

I’ve downloaded the new fix and can’t get the GetDPI function to return anything other
than 96.0 on any screen. The SetDPI function seems to have an effect, although I cannot be
certain the result is correct. Changing the DPI awareness of my application doesn’t seem to
have an impact on the GetDPI function.

@patjep,

Please try to set DPI settings to 96 at the start of your program using static SetDPI method of Aspose::Cells::ICellsHelper in the new fix before rendering and let us know your feedback.

No effect at all, which is unsurprising since the GetDPI function reports 96.0.

@patjep,

Please forget about GetDPI which might not give correct DPI settings of your screen. Please set DPI settings to 96 at the start of your program using static SetDPI method of Aspose::Cells::ICellsHelper using the new fix before rendering to PDF and let us know if the output PDF is correct.

@Amjad_Sahi

That is what I did, no effect.

@patjep,

I tested your scenario/case using our latest fix (we provided) with your original file you share in the first post in the thread. I could not find the issue. The Excel to PDF rendering is working fine (in 240 display settings) after we set DPI settings to 96 using SetDPI method. I first set the custom display settings of my Window 10 os to 240. Then I run my test project with latest fix and it works as expected. The output PDF is ok. Please download the project here and run it.

If you still find the issue, kindly do share your runnable sample project with sample file (via some third party service (dropbox, Google drive,etc.)), we will check it soon.

@Amjad_Sahi

I tested your demo and it works fine om my computer with High DPI screen. But the fact remains
that it doesn’t work in my main application (based on Qt5). Can you provide som insight regarding what may interfere with Aspose.Cells PDF drawing?

@patjep,

We will check it further. But could you also provide more details and sample project to reproduce the issue on our end, this will help us to evaluate your issue precisely to figure it out.

@Amjad_Sahi

I’ve created an example project now. It turns out that all you have to do is to create an instance
of QApplication to prevent your SetDPI from working properly. My example contains source code that is supposed to be placed in the Aspose.Cells dir (in my case “Aspose.Cells for C++ 20.7.1”). Then you need to install a recent version of the Qt 5 sdk (I’m using 5.12.2), and install cmake. Then you should
be ready to go. The “bin” folder also includes a pdf which is the result of running the example on a high dpi screen.
https://1drv.ms/u/s!Arnq_7ocxp-R8DaZWCVUwsUgI2aO?e=Ih6XUk

@patjep,

Thanks for the sample project and details.

I have logged your sample to your existing ticket “CELLSCPP-271” into our database. We will look into it soon.

Once we have any new information available, we will update you.

@patjep,

We have looked into your project. We found that if we remove the code “QApplication app(args, argv);” , the Aspose.Cells library will work fine. We conclude that since Aspose.Cells library calls GDIPlus to realize drawing functionality, and QT GUI also call GDI, so, when you call “QApplication app(args, argv);” this code may execute some initialization and settings work which have an impact to Aspose.Cells drawing functions and causes a different result compare to running in Visual Studio.

To prove our inference, we modify your project and just call a simple GDIPlus function, which returns different result before and after removing “QApplication app(args, argv);”. So, we think you should modify your code in QT side accordingly. Because, we are not familiar with QT GUI module much, so we cannot give you more professional advice. If you still do not know how to do, you can rise a topic in forum.qt.io.

@Amjad_Sahi

Qt is a popular, widely used library for adding GUI (among other things) to apps. My company doesn’t own Qt and our application literally has millions of lines of code that depends on Qt for various task. Thus removing or changing Qt is out of the question, it’s simply not doable.

Using GDI in one way or another isn’t something strange for a Windows GUI app to do. Since GDI conflicts with Aspose.Cells, are you saying that you do not support embedding Aspose.Cells in GUI applications?