Free Support Forum - aspose.com

Printing using Microsoft XPS Document Writer

Hi,

Im using folowing method to print a document:

public static void PrindWordDocument(String strFullFileName, String strPrinterName)
{
new Aspose.Words.License().SetLicense("Aspose.Total.lic");
Document docToPrint = new Document(strFullFileName);
docToPrint.Print(strPrinterName);
}

Every time i use "Microsoft XPS Document Writer" as printer name i get an exception if I save the document or click cancel.

The exception: The data area passed to a system call is too small.

Is there a way to fix this?

Kind Regards Ibbe.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I cannot reproduce the problem on my side. I used the following code for testing:

Document doc = new Document(@"Test001\in.doc");

doc.Print("Microsoft XPS Document Writer");

Also I tried to print to file. Here is code:

Document doc = new Document(@"Test001\in.doc");

PrinterSettings settings = new PrinterSettings();

settings.PrinterName = "Microsoft XPS Document Writer";

settings.PrintToFile = true;

settings.PrintFileName = @"C:\Temp\out.xps";

doc.Print(settings);

In addition, you can convert your document to XPS using Apsose.Words. Please see the following code:

Document doc = new Document(@"Test001\in.doc");

doc.SaveToXps(@"Test001\out.xps");

Hope this helps.

Best regards.

You should use Aspose.Words.Document.SaveToXps instead of printing. It gives a number of advantages. For example hyperlinks and bookmarks will be converted to XPS and will be functional in it.