GroupDocs viewer not working with .eml file properly

I am facing issues with GroupDocs HTML viewer with .eml file sharing the file for your reference.

the alignment is very bad in html viewer but it is good in png viewer.
RE DMS - signoff for all documents upload - June’2025 - ASRP (22.5 KB).zip (21.3 KB)

@Niteen_Jadhav

It sounds like you’re experiencing alignment issues when viewing .eml files with the GroupDocs HTML viewer, while the PNG viewer displays them correctly. This can occur due to differences in how the two viewers render content.

Cause: The alignment issues may stem from the rendering options or the specific content of the .eml files.

Solution: Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Check Rendering Options: Ensure that you are using the correct rendering options for the HTML viewer. Specify any necessary settings that could affect layout and alignment.

  2. Update GroupDocs Viewer: Make sure you are using the latest version of the GroupDocs Viewer. Updates often include bug fixes and improvements that could resolve rendering issues.

  3. Test with Different .eml Files: Try viewing other .eml files to see if the issue is consistent across all files or specific to the one you are testing.

  4. Review HTML Output: If possible, inspect the generated HTML output for the .eml file to identify any discrepancies in the layout that could be causing the alignment issues.

  5. Contact Support: If the problem persists, reach out to GroupDocs support with specific details about the issue, including the .eml file in question, so they can assist you further.

Next Steps: Please follow the steps outlined above and let me know if they help resolve the issue. If you continue to experience problems, I can assist you further.

Thank you for your patience, and I look forward to your update!

I tried viewing multiple .eml file issue is on all of them

Hi @Niteen_Jadhav

I assume you’re used the GroupDocs.Viewer for .NET latest version 25.8. I checked your file “RE DMS - signoff for all documents upload - June’2025 - ASRP (22.5 KB).msg” with the next source code:

string inputFile = "RE DMS - signoff for all documents upload - June'2025 - ASRP (22.5 KB).msg";

string outputHtmlPathTemplate = "RE DMS - signoff for all documents upload - June'2025 - ASRP (22.5 KB)-msg-licensed-embedded-page{0}.html";
HtmlViewOptions htmlViewOpt = HtmlViewOptions.ForEmbeddedResources(outputHtmlPathTemplate);

using (Viewer viewer = new Viewer(inputFile))
{
    viewer.View(htmlViewOpt);
}

And the resultant HTML file is correct from my perspective, I don’t see any issues here. I’m attaching the resultant file “RE DMS - signoff for all documents upload - June’2025 - ASRP (22.5 KB)-msg-licensed-embedded-page1.html” inside the ZIP archive, you can compare it with your results.

RE DMS - signoff for all documents upload - June’2025 - ASRP (22.5 KB)-msg-licensed-embedded-page1.zip (102.4 KB)

If you insist that there are some alignment issues, please describe them in detail or show on a screenshot.

Thanks and waiting for your reply.

viewer error.PNG (149.5 KB)

sharing my viewer for your reference, and also my code below

private LoadDocumentEntity GetDocumentPages(PostedDataEntity postedData, bool loadAllPages)
{
    // get/set parameters
    string documentGuid = GetDocumentPath(postedData.guid); //postedData.guid;
    string password = string.IsNullOrEmpty(postedData.password) ? null : postedData.password;

    var fileFolderName = Path.GetFileName(documentGuid).Replace(".", "_");
    string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName);

    if (!File.Exists(documentGuid))
    {
        throw new GroupDocsViewerException("File not found.");
    }

    IViewerCache cache = new FileViewerCache(cachePath, fileCacheSubFolder);

    LoadDocumentEntity loadDocumentEntity;
    var htmlMode = string.IsNullOrEmpty(postedData.IsHTMLMode) ? "false" : postedData.IsHTMLMode;
    if (htmlMode != "false")
    {
        using (HtmlViewer htmlViewer = new HtmlViewer(documentGuid, cache, GetLoadOptions(password)))
        {
            loadDocumentEntity = GetLoadDocumentEntity(loadAllPages, documentGuid, fileCacheSubFolder, htmlViewer, htmlMode);
        }
    }
    else
    {
        using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password)))
        {
            loadDocumentEntity = GetLoadDocumentEntity(loadAllPages, documentGuid, fileCacheSubFolder, pngViewer, htmlMode);
        }
    }

    return loadDocumentEntity;
}

public HtmlViewer(IndexedFileInfo fileInfo, IViewerCache cache, string password)
{
	this.cache = cache;
	sFileInfo = fileInfo;
	Directory.CreateDirectory(sFileInfo.FileCacheFolderPath);

	var loadOptions = new LoadOptions
	{
		Password = password,
	};
	viewer = new GroupDocs.Viewer.Viewer(sFileInfo.FilePath, loadOptions);
	viewOptions = CreateHtmlViewOptions();
}

private HtmlViewOptions CreateHtmlViewOptions(int passedPageNumber = -1, int newAngle = 0)
{
	HtmlViewOptions htmlViewOptions = HtmlViewOptions.ForEmbeddedResources(
		pageNumber =>
		{
			string fileName = $"p{pageNumber}.html";
			string cacheFilePath = this.cache.GetCacheFilePath(fileName);

			return File.Create(cacheFilePath);
		});
	
	htmlViewOptions.SpreadsheetOptions.TextOverflowMode = TextOverflowMode.HideText;
	htmlViewOptions.SpreadsheetOptions.SkipEmptyColumns = true;
	htmlViewOptions.SpreadsheetOptions.SkipEmptyRows = true;
	SetWatermarkOptions(htmlViewOptions);

	if (passedPageNumber >= 0 && newAngle != 0)
	{
		Rotation rotationAngle = GetRotationByAngle(newAngle);
		htmlViewOptions.RotatePage(passedPageNumber, rotationAngle);
	}

	return htmlViewOptions;
}

private static void SetWatermarkOptions(ViewOptions options)
{
	Watermark watermark = null;

	if (!string.IsNullOrEmpty(globalConfiguration.GetViewerConfiguration().GetWatermarkText()))
	{
		GroupDocs.Viewer.Drawing.Argb32Color argb32 = new GroupDocs.Viewer.Drawing.Argb32Color();
		// Set watermark properties
		watermark = new Watermark(globalConfiguration.GetViewerConfiguration().GetWatermarkText())
		{
			//Color = System.Drawing.Color.Blue,
			Color = argb32,
			Position = Position.Diagonal,
		};
	}

	if (watermark != null)
	{
		options.Watermark = watermark;
	}
}

private static Rotation GetRotationByAngle(int newAngle)
{
	switch (newAngle)
	{
		case 90:
			return Rotation.On90Degree;
		case 180:
			return Rotation.On180Degree;
		case 270:
			return Rotation.On270Degree;
		default:
			return Rotation.On90Degree;
	}
}

private static LoadDocumentEntity GetLoadDocumentEntity(bool loadAllPages, string documentGuid, string fileCacheSubFolder, ICustomViewer customViewer, string htmlMode = "")
{
	if (loadAllPages)
	{
		customViewer.CreateCache();
	}

	dynamic viewInfo = GetviewInfo(htmlMode, customViewer);// customViewer.GetViewer().GetViewInfo(ViewInfoOptions.ForHtmlView());
	LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity();

	if (!Directory.Exists(cachePath))
	{
		Directory.CreateDirectory(cachePath);
	}

	TryCreatePagesInfoXml(fileCacheSubFolder, viewInfo, out string pagesInfoPath);

	for (var i = 0; i < viewInfo.Pages.Count; i++)
	{
		
		var page = viewInfo.Pages[i];
		PageDescriptionEntity pageData = new PageDescriptionEntity
		{
			Number = i + 1,
			//Angle = (int)(page.GetType().GetProperty("Angle")?.GetValue(page, null) as int?), // Adjust type as needed
			Width = (int)(page.GetType().GetProperty("Width")?.GetValue(page, null) as int?), // Adjust type as needed
			Height = (int)(page.GetType().GetProperty("Height")?.GetValue(page, null) as int?) // Adjust type as needed
		};
		loadDocumentEntity.SetPages(pageData);
	}
	loadDocumentEntity.SetGuid(documentGuid);
	return loadDocumentEntity;
}

private ViewInfo GetViewInfo()
{
	string cacheKey = "view_info.dat";

	if (!this.cache.Contains(cacheKey))
	{
		using (new CrossProcessLock(this.filePath))
		{
			if (!this.cache.Contains(cacheKey))
			{
				return this.cache.GetValue(cacheKey, () => this.ReadViewInfo());
			}
		}
	}

	return this.cache.GetValue<ViewInfo>(cacheKey);
}

private static dynamic GetviewInfo(string isHtmlMode, ICustomViewer customViewer)
{
	if (isHtmlMode != "false")
	{
		return customViewer.GetViewer().GetViewInfo(ViewInfoOptions.ForHtmlView());
	}
	else
	{
		return customViewer.GetViewer().GetViewInfo(ViewInfoOptions.ForPngView(false));
	}
}

private static void TryCreatePagesInfoXml(string fileCacheSubFolder, dynamic viewInfo, out string pagesInfoPath)
{
	if (!Directory.Exists(fileCacheSubFolder))
	{
		Directory.CreateDirectory(fileCacheSubFolder);
	}

	pagesInfoPath = Path.Combine(fileCacheSubFolder, "PagesInfo.xml");

	if (!File.Exists(pagesInfoPath))
	{
		var xdoc = new XDocument(new XElement("Pages"));

		foreach (var page in viewInfo.Pages)
		{
			xdoc.Element("Pages")
				.Add(new XElement(
					"PageData",
					new XElement("Number", page.Number),
					new XElement("Angle", 0)));
		}

		xdoc.Save(pagesInfoPath);
	}
}

Any updates on this?

Hi @Niteen_Jadhav

You’ve provided a big piece of code, which I assume is a part of a big project; we need some time to make it compilable, runnable, workable, and then reproduce the issue.

If you are willing to speed up this forum request, please provide us a project, which will be compilable and runnable from the beginning.

With best regards,
Denis Gvardionov

The process of creating a project is very time consuming hence I just shared the code

Hi @Niteen_Jadhav

You are absolutely correct, creating a working autonomous project from the code you’ve shared is very time consuming task, so we need that time to do that.

With best regards,
Denis Gvardionov

@Niteen_Jadhav

Hi Niteen,

I’ve examined the provided source code, made investigation and here are the results:

  1. I’ve checked the provided piece of source code and didn’t found a Viewer.View() method call, so added it by myself.
  2. I’ve assumed that the htmlMode != "false" and HtmlViewer is used.
  3. I’ve assumed that no watermark is applied at all and the SetWatermarkOptions method is not invoked at all.
  4. I’ve assumed that no page rotation is applied.
  5. As result, I created a test project, based on .NET 6.0. It references the latest GroupDocs.Total 25.7 and uses a license (license is not included in the project).
  6. Sample file “RE DMS - signoff for all documents upload - June'2025 - ASRP (22.5 KB).msg” is already placed inside this project.
  7. After checking the scenario using this project, I cannot reproduce the HTML document, as it can be seen on your screenshot above (file " viewer error.PNG (149.5 KB)")

Please download the ZIP archive with this sample project inside, unzip it, compile and run on your local machine.

ViewerConsole.zip (123.7 KB)

If successful, an output HTML file should be present here: ...\ViewerConsole\bin\Debug\net6.0\RE DMS - signoff for all documents upload - June'2025 - ASRP (22.5 KB)-page1.html. Please check this file on your side. Is it correct or not? If not, please send it to us (file itself and also a screenshot of it).

Thanks and waiting for your reply.

With best regards,
Denis Gvardionov