private string GetPrinterPath(IDocumentContract document, DocumentContractType documentContractType) { switch (documentContractType) { case DocumentContractType.Metafile: return(PageSettingsHelper.PrinterNameFromPageSettings(document.Settings)); case DocumentContractType.Pdf: return(PageSettingsHelper.PrinterNameFromPageSettings(document.Settings)); case DocumentContractType.Zebra: return(document.Settings); default: throw new ArgumentException("Unsupported value", nameof(documentContractType)); } }
/// <summary> /// Prints the specified document. /// </summary> /// <param name="document">The document.</param> /// <returns>True if document was printed successfully.</returns> public bool Print(IDocumentContract document) { var documentContract = document as PdfDocumentContract ?? throw new ArgumentException("Invalid type", nameof(document)); // Validate the document contract if (documentContract == null) { throw new ArgumentNullException(nameof(documentContract)); } if (documentContract.Contents == null || documentContract.Contents.Length == 0) { throw new ArgumentNullException("documentContract.Contents"); } if (string.IsNullOrWhiteSpace(documentContract.Settings)) { throw new ArgumentNullException("documentContract.Settings"); } // Get the printer from the settings var printer = PageSettingsHelper.PrinterNameFromPageSettings(documentContract.Settings); if (string.IsNullOrWhiteSpace(printer)) { throw new ArgumentNullException("PageSettings.PrinterName"); } // Get the pdf file to send to the printer var pdfFilePath = this.DocumentContractToTempFile(documentContract); try { this.AdobeReaderPrint(pdfFilePath, printer); return(true); } catch (Exception) { // TODO Error Log return(false); } }