Как распечатать PDF с помощью планировщика заданий - PullRequest
0 голосов
/ 17 марта 2020

Мое приложение отправляет PDF на принтер и печатает, когда я дважды щелкаю. Тем не менее, когда я хочу использовать планировщик задач. это не печать. Как я могу справиться с этим?

static void Main(string[] args)
        {


            ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
            exchange.Credentials = new WebCredentials("mail", "password);
            exchange.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

                if (exchange != null)
                {

                        SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
                        FindItemsResults<Item> result = exchange.FindItems(WellKnownFolderName.Inbox, sf, new ItemView(20));

                        foreach (Item item in result)
                        {

                                EmailMessage message = EmailMessage.Bind(exchange, item.Id);

                                message.IsRead = true;
                                message.Update(ConflictResolutionMode.AutoResolve);

                                List<Attachment> zipList = message.Attachments.AsEnumerable().Where(x => x.Name.Contains(".zip")).ToList();

                                foreach (Attachment Attachment in zipList)
                                {

                                        if (Attachment is FileAttachment)
                                        {
                                            FileAttachment f = Attachment as FileAttachment;

                                            f.Load("C:\\pdfFiles\\" + f.Name);



                                            string zipPath = @"C:\pdfFiles\" + f.Name;
                                            string extractPath = @"C:\pdfFiles\" + Path.GetRandomFileName();

                                            ZipFile.ExtractToDirectory(zipPath, extractPath);

                                            string[] filePaths = Directory.GetFiles(extractPath, "*.pdf",
                                                         SearchOption.TopDirectoryOnly);

                                            foreach (string path in filePaths)
                                            {

                                                    SendToPrinter(path);

                                            }


                                        }



                                }


                        }


                }

        }


  static void SendToPrinter(string path)
        {
    var printerName = "EPSON L310 Series";

         ProcessStartInfo info = new ProcessStartInfo();
                    info.Verb = "PrintTo";
                    info.FileName = filePath;
                    info.CreateNoWindow = true;
                    info.Arguments = "\"" + printerName + "\"";
                    info.WindowStyle = ProcessWindowStyle.Hidden;

                    Process p = new Process();
                    p.StartInfo = info;
                    p.Start();

                    System.Threading.Thread.Sleep(3000);
 }

Кстати, код, который работает снизу, но мне нужно использовать выше

static void SendToPrinter(string path)
        {
      PdfDocument pdf = new PdfDocument();

       pdf.LoadFromFile(path);

       pdf.Print();
       pdf.Dispose();
   }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...