DOCX to PDF/XPS conversion issue with text font and image color using .NET

We have an in-house document printing solution that generates an Open XML document and prints it. The old solution automated Word 2010 using the Interop libraries to print the document. The new solution uses Aspose to convert the document and print via XPS.
The problem we are running into is that Aspose is not rendering the document exactly the same as Word. We are seeing image color changes, font size changes and line spacing issues.
I have attached an example mocked up docx file that contains a logo with the problem and a mocked up letter body that is similar to the ones generated from our code that has the font and linespacing issue. The two attached PDFs are rendered from the postscript sent to the printer and illustrates the aforementioned problems. I also attached the postscript files themselves.
Print from Word 2010 and then from a simple Aspose to XPS (color printer req.) and if you cannot reproduce the problem than we may have to figure out how to get you copies of the output.
Unfortunately, the output color is very dependent on the printer driver so you may not be able to reproduce on your end.

Hi,

Thanks for your query. I have tried to understand your problem statement but unfortunately I have not completely understand your issue. Please use the latest version of Aspose.Words for .NET 11.1.0.

I have generated the PDF and XPS from your document and have not found any issue. Please find the output document in attachment and share some more information about your issue along with code for investigation purposes.

I am currently using the latest version of Aspose for Word 11.1.0 3.5 Client DLL.
If you look at the pdfs provided you can see the difference in the colors in the logo. The Word version was printed directly from Word 2010 to the GDI driver. The Aspose version converts the docx to XPS and then prints via XPS. Although the PDF’s are grainy, you can see that the shade of blue has changed. although you cannot see the tagline “Your partner to new heights” clearly in the PDF’s, printouts show that the text has a wider stroke to the typeface, indicating that the image went through compression in the conversion. The body of the letters also have a different line spacing and stroke as well (and can be seen as such in the PDFs). Compare the Word version to your PDFs and you will see that the blues are different colors and the text is also different.
Our code cannot easily be separated from all the internal core libraries and database, but the call to Aspose is straightforward. I pasted the code that does the Aspose document load and save to xps stream. The XPS print helper is your sample from your demos.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;
using System.Diagnostics.Contracts;
using System.Globalization;
using DataAccess;
using System.Reflection;
using System.Linq;
using Word = Microsoft.Office.Interop.Word;
using System.Drawing.Printing;
using System.Diagnostics;
using DocGenBusinessLogic;
using Aspose.Words;
using System.Printing;
using System.Windows.Xps;
using System.Windows.Xps.Packaging;
namespace DocGenPrintWindowsService
{
    public class DocGenPrint: IDisposable
    {
        #region Properties
        #endregion
        private bool _disposed = false;
        #region Constructors
        public DocGenPrint()
        {}
        #endregion
        #region Methods
        public void PrintLetter(string docxFile, PrintTicket ticket, string printerName, string trayName)
        {
            Contract.Requires <NullReferenceException> (!string.IsNullOrEmpty(docxFile));
            Contract.Requires <NullReferenceException> (ticket != null);
            Contract.Requires <NullReferenceException> (!string.IsNullOrEmpty(printerName));
            Document document = new Document(docxFile);
            PrintTicket adjTicket = PrintTicketSetTray(ticket, trayName);
            using(var stream = new MemoryStream())
            {
                document.Save(stream, SaveFormat.Xps);
                stream.Position = 0;
                XpsPrint.Print(stream, printerName, docxFile, true);
            }
        }
        private PrintTicket PrintTicketSetTray(PrintTicket ticket, string trayName)
        {
            Contract.Requires <ArgumentNullException> (ticket != null);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(ticket.GetXmlStream());
            // create NamespaceManager and add PrintSchemaFrameWork-Namespace (should be on DocumentElement of the PrintTicket)
            // Prefix: psf NameSpace: xmlDoc.DocumentElement.NamespaceURI = "http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework"
            XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
            manager.AddNamespace(xmlDoc.DocumentElement.Prefix, xmlDoc.DocumentElement.NamespaceURI);
            // find the trays section
            XmlNode node = xmlDoc.SelectSingleNode("//psf:Feature[@name='psk:JobInputBin']/psf:Option", manager);
            if (node == null)
                node = xmlDoc.SelectSingleNode("//psf:Feature[@name='psk:DocumentInputBin']/psf:Option", manager);
            if (node == null)
                node = xmlDoc.SelectSingleNode("//psf:Feature[@name='psk:PageInputBin']/psf:Option", manager);
            // set the tray
            if (node != null)
                node.Attributes["name"].Value = trayName;
            // create a new PrintTicket out of the XML
            MemoryStream printTicketStream = new MemoryStream();
            xmlDoc.Save(printTicketStream);
            printTicketStream.Position = 0;
            PrintTicket modifiedPrintTicket = new PrintTicket(printTicketStream);
            return modifiedPrintTicket;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        private void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                _disposed = true;
            }
        }
        #endregion
    }
}

Hi,

Thanks for sharing the information. The Aspose.Words mimics the MS Word behavior upon converting documents to XPS/PDF. I have attached the PDF and XPS files with this post generated by Aspose and MS words. I have found one issue that line spacing and shapes are slightly misplaced. It would be great, If you share any other issue except I have mentioned.

If you look carefully at the font in the text in the body, it looks like it is a different size. The Image blue color is different than what Word rendered. The placement of the initial line in the body (not the header or footer),which is contained in a content area, is different than what Word renders. We are on the 5th day now since the initial posting. If you could, please pass this by your team for a work around or some suggestions on what WordML elements you guys are handling incorrectly that I might be able to bypass. I need a solution to this rather than just submitting bugs.
The image issues (enlarged type, color balance) is most likely due to a compression you guys are doing on the images. Please tell me if there is a way to adjust the way you guys are handling that as well.

Hi,

Thanks for sharing the information. I have logged this issue in our issue tracking system. Our development team will look into this issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Please provide an estimate as to when you will be able to find a workaround or solution, whichever is faster. The other option is to tell me 1) How to change the image compression, 2) What Word ML elements are causing the issue and I can try to sub them out.

Hello.

Regarding the image compression.
You can control the image compression while saving into PDF via PdfSaveOptions.ImageCompression and PdfSaveOptions.JpegQuality.
There’re also many useful properties in ImageSaveOptions if you wish to save document into images.
However there’s no way to control image compression while saving into XPS format.

By the way, I see no difference in colors between ElevTest_word.xps and ElevTest_Aspose.xps.

Thank you for your reply. I have been working on a workaround for the issues and identifying them further.
The font and line spacing in the body is being altered by the printer driver and not Aspose. The administrators put in a font substitution at the printer level. Unfortunately, the line spacing of the Courier New font in Word 2010 (and Aspose) is not handled in the same way as the printer font substitution. So a had to be added to the style to match the printer substitution.
The image quality is a complex set of causes. Originally, the image is inserted into the Word document (the template for us, but not a dotx) from an EPS file, but the color in the EPS file is set to a CMYK value instead of a Pantone color. The manually inserted EPS (vector) image into Word is translated to WMF by Word and that vector graphic is further translated by XPS into a compressed graphic format of unknown type. The compression and translation of vector graphics causes the fonts in the image to become less sharp and the CMYK color to be shifted to a lighter shade.
The workaround for that is to first use Illustrator to export the EPS to a compressed format (PNG) that allows me to control the sharpness of the type conversion (Type Optimized) at 300DPI (note the resolution is critical). Insert that PNG into Word (which then stores the PNG as a PNG in the DOCX). XPS translation no longer causes the fonts to become blurrier and the color to shift (I wonder if XPS uses PNG internally). At this point, I can adjust the original color shade in the EPS and through trial and error match the original color output of the image.
Please let me know if you guys fix the Vector graphic conversion.

Hi
Thank you for additional information. Sure, we will immediately let you know once the problem is resolved.
Best regards,

The issues you have found earlier (filed as WORDSNET-6004) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Are these ImageCompression techniques available for XpsSaveOptions?

Hi Chilappagari,

Thank for your inquiry. No, there is no ImageCompression property available in XpsSaveOptions. Please read the members of XpsSaveOptions from here:
https://reference.aspose.com/net/words/aspose.words.saving/xpssaveoptions

You can use PdfSaveOptions.ImageCompression and save your document into Pdf . After that by using Aspose.Pdf component, you can export this PDF to XPS. Hope this helps you.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan