Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用任务计划程序打印pdf_C#_Scheduled Tasks - Fatal编程技术网

C# 如何使用任务计划程序打印pdf

C# 如何使用任务计划程序打印pdf,c#,scheduled-tasks,C#,Scheduled Tasks,我的应用程序将pdf发送到打印机并在双击时打印。但是,当我想使用任务调度器时。它不是印刷品。我该怎么办 看起来你根本不需要涉及任何C代码。如果您使用的是计划任务,那么您可以直接调用AcrobatReader。请参阅。实际上,我的应用程序从mail下载包含pdf的.zip文件,打开它,然后发送打印机。我不明白你的意思。我需要用调度任务@JohnIs启动这个应用程序,这是与您遇到的问题相关的最上面的代码段?这就是我在上面写的问题。因为第二个代码将pdf发送到打印机。然而,第一个是不发送pdf到打印机

我的应用程序将pdf发送到打印机并在双击时打印。但是,当我想使用任务调度器时。它不是印刷品。我该怎么办


看起来你根本不需要涉及任何C代码。如果您使用的是计划任务,那么您可以直接调用AcrobatReader。请参阅。实际上,我的应用程序从mail下载包含pdf的.zip文件,打开它,然后发送打印机。我不明白你的意思。我需要用调度任务@JohnIs启动这个应用程序,这是与您遇到的问题相关的最上面的代码段?这就是我在上面写的问题。因为第二个代码将pdf发送到打印机。然而,第一个是不发送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();
   }