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);
}