Re: Word { PRINT } field codes are not working

Is there any update on WORDSNET-6258?

We’re using the {PRINT} command in document-templates on a server using MailMerge to enable duplex printing for particular document.

For the sake of performance I was advised to use XPSprint for the printing of the documents.

The downside of the use of XPSprint: the {PRINT}-command doesn’t work.

So I would like to know the status of WORDSNET-6258. Or maybe another solution/hint for duplex-printing using XPSprint.

Regards,

Michel

PS the same problem is described in Double Side Printing

Hi Michel,

Thanks for your inquiry. This problem actually requires us to implement a new feature in Aspose.Words and we regret to share with you that implementation of this issue (WORDSNET-6258) has been postponed for now. However, the fix of this problem may definitely come onto the product roadmap in the future. Unfortunately, we cannot currently promise a resolution date. We apologize for your inconvenience and thank you for your understanding.

Best regards,

Hi Awais,

thank you for the quick reply.
Sorry to hear that a fix of this problem isn’t on the roadmap for now.
Do you (or a colleque) maybe have a hint or solution how I can manage to print a document in duplex mode using XPSprint without setting the printer default at duplex?

Regards,
Michel

Hi Michel,

Thanks for your inquiry. I am afraid, the method StartJob() is taken from Microsoft Printing API, please see this page for reference. It does not take any argument like “Duplex”. Unfortunately, I see no way to help you using XpsPrint API. But may be you can use Document.Print method. As it says in article:

The Document object provides a family of the Print methods to print documents and these methods print via the .NET printing classes defined in the System.Drawing.Printing namespace. There are many customers of Aspose.Words who use this printing method in their server-side applications without any problems.

So, It’s possible to do double-sided printing of the document using Document.Print method.

Best regards,

Hi Awais,

Here I will give my thoughts and experiences about my problems with printing so others can benefit.

I’m aware of the possibilities of the Document.Print method. And the double-sided printing works as a charm.

The downside of the Document.Print method is the performance of my service on a server.

To improve the performance I started using the XpsPrint API described here:
https://docs.aspose.com/words/net/print-a-document-programmatically-or-using-dialogs/

This was a great improvement on the performance but I lost the ability to manage single-sided/double sided.

To be able to manage the simplex/duplex modes, I searched the internet and stumbled upon this:
https://social.msdn.microsoft.com/forums/en-us/eb1aab0d-f015-479e-9fe7-bfb848a4d58b/how-to-create-new-xpsfile-with-print-ticket

I’ve modified the Aspose XpsPrintHelper to create a Print Ticket in the documents that has to be printed.

The code is working, but I’ve not been able yet to test the performance of my service on a Windows Server.

The modified code is:

public static void Print(Aspose.Words.Document document, string printerName, string jobName, bool isWait, bool printDuplex)
{
    if (document == null)
        throw new ArgumentNullException("document");
    // Create a PrintTicket to set Simplex or Duplex
    var xpsInName = Path.ChangeExtension(document.OriginalFileName, "xps");
    var xpsOutName = string.Format("{0}PT.xps", Path.GetFileNameWithoutExtension(xpsInName));
    document.Save(xpsInName);
    using (var doc = new XpsDocument(xpsInName, FileAccess.ReadWrite))
    {
        using (var container = Package.Open(xpsOutName, FileMode.Create))
        {
            using (var xpsDoc = new XpsDocument(container))
            {
                var xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
                xpsWriter.WritingPrintTicketRequired += new WritingPrintTicketRequiredEventHandler((s, e) => WritingPrintTicketRequired(s, e, printDuplex));
                xpsWriter.Write(doc.GetFixedDocumentSequence());
            }
        }
    }
    var stream = new MemoryStream();
    using (var fileStream = File.OpenRead(xpsOutName))
    {
        fileStream.CopyTo(stream);
    }
    stream.Position = 0;
    Print(stream, printerName, jobName, isWait);
}

private static void WritingPrintTicketRequired(Object sender, WritingPrintTicketRequiredEventArgs e, bool printDuplex)
{
    if (e.CurrentPrintTicketLevel == PrintTicketLevel.FixedDocumentSequencePrintTicket)
    {
        var pt = new PrintTicket { Duplexing = printDuplex ? Duplexing.TwoSidedLongEdge : Duplexing.OneSided };
        e.CurrentPrintTicket = pt;
    }
}

I hope the performance is good and others can use this as well.

Best regards,

Michel van Vuren

Hi Michel,

Thanks for the additional information which may help other developers who are facing the same problem. It is great you were able to find what you were looking for.

Best regards,