Use the DevExpress Cross-Platform Drawing Engine
- 3 minutes to read
This topic describes how to replace the libdgiplus-based drawing engine with the DevExpress cross-platform drawing engine in your ASP.NET Core application. A drawing engine is invoked when users preview, print, or export reports. Based on tests conducted on Linux and MacOS, the cross-platform engine renders reports more accurately. The following improvements are seen, for instance, when users export reports to image and PDF on Linux:
Fully displayed text
libgdiplus Cross-platform drawing engine International character set support
libgdiplus Cross-platform drawing engine Correctly applied text emphasis
libgdiplus Cross-platform drawing engine Proper text alignment
libgdiplus Cross-platform drawing engine
Configuration
Follow the steps below to enable the cross-platform drawing engine for your reports.
Add the DrawingEngine NuGet package
Add the DevExpress.CrossPlatform.Printing.DrawingEngine NuGet package to your ASP.NET Core application.
dotnet add package DevExpress.CrossPlatform.Printing.DrawingEngine
Configure the Environment
Linux
The following commands configure the environment in the dockerfile:
RUN apt-get update && \
apt-get install -y libc6 -f -o APT::Immediate-Configure=0 && \
apt-get install -y \
libgdiplus \
libicu-dev \
libharfbuzz0b \
libfontconfig1 \
libfreetype6 \
libpango-1.0-0 \
libpangocairo-1.0
To avoid .NET 6 and .NET 7 limitations related to the System.Drawing.Common library, specify the EnableUnixSupport
option as described in the following help topic: System.Drawing.Common is Supported on Windows Only. This step is required even if you use the cross-platform drawing engine (Pango). The reason is that the Pango library is used only to measure text in a non-Windows environment, and the reporting components use the System.Drawing.Common
library (GDI+) to render the document.
MacOS
Add the runtime.osx.10.10-x64.CoreCompat.System.Drawing NuGet package to your ASP.NET Core application:
dotnet add package runtime.osx.10.10-x64.CoreCompat.System.Drawing
- Install homebrew.
Install additional operating system libraries:
brew install mono-libgdiplus brew install pango
You may want to modify the formulas to install the recommended versions (pango-1.48.0 and cairo-1.16.0_3).
If your machine is Apple M1, add the following environment variable to the launchsettings.json file:
"DYLD_FALLBACK_LIBRARY_PATH": "/opt/homebrew/lib:"
Windows
Use vcpkg to install DLLs. Run the Admin Command Prompt and execute the following commands:
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
vcpkg.exe integrate install
vcpkg.exe install pango --triplet x86-windows
vcpkg.exe install pango --triplet x64-windows
The DLLs are located in the vcpkg repository’s installed subfolder.
Register the Engine
Register the cross-platform drawing engine at application startup.
The code below registers the drawing engine if the application is executed on a non-Windows platform. The engine does not need to be registered on Windows because reports are rendered without the issues described above.
using System.Runtime.InteropServices;
// ...
public void ConfigureServices(IServiceCollection services) {
// ...
if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
DevExpress.Printing.CrossPlatform.CustomEngineHelper.RegisterCustomDrawingEngine(
typeof(DevExpress.CrossPlatform.Printing.DrawingEngine.PangoCrossPlatformEngine));
}
}
Install Fonts
All fonts used in the report should be available on the server that hosts the report. Please install all fonts on the server.
Troubleshooting
If your configuration includes the libgdiplus library, and you experience unexpected visual glitches or artifacts in the output, check whether you have installed the latest version (v6+) of the library. If you cannot find the recommended version in the package manager, you can build the library from the source code available as part of the Mono project on Github: libgdiplus: An Open Source implementation of the GDI+ API..