PrintDialogue output differs between manual and "silent"

Viewed 37

Trying to get silent printing working for an application and I'm hitting a brick wall on setting up printdialogue manually.

If I run it with the ui like below print acts as expected and comes out nicely formatted.

PrintDialog pDialog = new PrintDialog();
if (pDialog.ShowDialog() == true)
{
    XpsDocument xpsDocument = new XpsDocument(filename, FileAccess.Read);
    FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
    pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, file.Name);
}

If however I try and build the printdialogue manuall (set the printer) the output from the printer has incorrect margins, doesnt utilise default printer settings etc. However when I look at the printdialogue values there are no settings that appear vastly different other than the read-only description on the below method having the server name in e.g. "\desktop\printer" while above is just "printer". My guess is I'm missing some sort of "printer.getdefaults()" method but google is failing me!

var printServer = new PrintServer();
var printerQueues = printServer.GetPrintQueues();
var printer = printerQueues.FirstOrDefault(x => x.Name.Equals(PrinterName.Text));
if (printer != null)
{
    PrintDialog pDialog = new PrintDialog();
    pDialog.PrintQueue = printer;
    FileInfo file = new FileInfo(filename);
    XpsDocument xpsDocument = new XpsDocument(filename, FileAccess.Read);
    FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
    pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, file.Name);
}
1 Answers

Looks like it may not have been an issue in the code but actually an issue with some printers over RDP. Locally the code above seams to work correctly however over RDP the behavior sometimes differs in the manner discribed.

Printer was Physically connected to the "remote" machine in both cases so not sure why RDP was interfering and also doing so intermittently. Luckally this application isnt going to be used over RDP!

Related