@JThomas98
Hi,
Thank you for providing the sample code and the screenshots.
Below are the reasons why the EMF output differs from the original Excel chart and the steps you can take to obtain a rendering that matches the Excel view as closely as possible.
Font substitution (Arial Narrow → Calibri)
Why it happens
Aspose.Cells renders charts using the fonts that are available on the machine where the code runs.
If Arial Narrow cannot be found, GDI+ falls back to the default UI font (Calibri) – this is exactly what you see in the EMF image.
How to fix it
- Install the missing font on the server/machine where the conversion is performed.
- If installing the font is not possible, register a custom font folder so that Aspose.Cells can load the font at runtime:
using Aspose.Cells;
using Aspose.Cells.Rendering;
// Register a folder that contains Arial Narrow (or any other required fonts)
FontConfigs fontConfigs = FontConfigs.GetDefaultInstance();
fontConfigs.FontSources.Add(new FolderFontSource(@"C:\MyFonts", true));
// (Optional) If you need to use a specific font collection for this conversion only
FontSettings fontSettings = new FontSettings();
fontSettings.SetFontSources(new IFontSource[] { new FolderFontSource(@"C:\MyFonts", true) });
ImageOrPrintOptions options = new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Emf,
HorizontalResolution = 100,
VerticalResolution = 100,
OnlyArea = true,
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
FontSettings = fontSettings // <-- attach the FontSettings
};
Tip: After adding the font source, you can verify that Aspose can see the font:
bool hasArialNarrow = fontSettings.FontSources
.SelectMany(fs => fs.GetAllAvailableFonts())
.Any(f => f.FontFamilyName.Equals("Arial Narrow", StringComparison.OrdinalIgnoreCase));
If hasArialNarrow
returns true
, the chart will be rendered with the correct font.
Missing shadow effect on the red bars
Why it happens
The EMF (Enhanced Metafile) format does not support many of the newer shape‑effects that Excel uses (e.g., soft‑edges, shadows, 3‑D bevels).
Aspose.Cells faithfully reproduces the chart data, but the shadow style is omitted because the target format cannot represent it.
Possible work‑arounds
Option |
Description |
Render to a raster format (PNG, JPEG, TIFF) |
These formats store the visual appearance as pixels, so all shadow/3‑D effects are preserved. |
Export to PDF first and then convert PDF → EMF (if you really need EMF) |
The PDF renderer keeps the shadow, and the subsequent PDF‑to‑EMF conversion can retain it better. |
Disable the shadow in Excel if EMF is a hard requirement |
Since EMF cannot display it, removing the shadow will make the source and output identical. |
Sample code – rendering to PNG (keeps the shadow):
ImageOrPrintOptions pngOptions = new ImageOrPrintOptions
{
OnePagePerSheet = true,
ImageType = ImageType.Png, // raster format retains shadows
HorizontalResolution = 150,
VerticalResolution = 150,
OnlyArea = true,
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
};
SheetRender pngRender = new SheetRender(sourceWS, pngOptions);
pngRender.ToImage(0, Path.Combine(dir, $"Demographics_Chart{i + 1}.png"));
If you must have an EMF file, the shadow simply cannot be reproduced because the EMF specifications do not contain such effect information.
Quick checklist to get the closest visual match
Item |
Action |
Arial Narrow font available |
Install on the host or add a custom font folder (see code above). |
Use a raster format for full visual fidelity |
Switch ImageType to Png /Jpeg when shadows are needed. |
Upgrade to the latest Aspose.Cells version |
New releases contain bug‑fixes and better rendering support. |
Verify DPI settings |
Higher DPI (150‑300 ) reduces visual gaps between Excel and the exported image. |
Set PageSetup.PrintArea correctly |
Ensure the chart is fully inside the defined area. |
Helpful links
What to try next
- Add the custom font source (or install Arial Narrow) and re‑run the conversion.
- If the shadow is essential, change
ImageType
to Png
(or another raster format) and compare the output.
- Let us know which combination gives you the desired result, or share a small workbook that reproduces the issue if you need further fine‑tuning.
Feel free to ask any follow‑up questions—we’re happy to help you get the exact visual output you need!