ATM实现扫描二维码打印(二)下载文件到根目录,并判断文件是PNG还是PDF

上一步通过扫描二维码获取了一个URL,这里通过这个URL下载文件,下载的文件存在根目录,然后判断文件类型。如果文件是PDF类型,打印文档,如果为png则不存在,转到扫描页。

代码:

  //下载PDF
            using (WebClient webClient = new WebClient())
            {
              
                    timer.Stop();
                 
                    webClient.DownloadFile("http://180.166.99.4/print/scanOutReal.htm?outEnterId=677469", $"{System.Environment.CurrentDirectory}/scanOutReal.PDF");//PDF//webClient.DownloadFile("http://180.166.99.4/print/scanOutReal.htm?outEnterId=675767", $"{System.Environment.CurrentDirectory}/scanOutReal.PDF"); //png,无实提单               
                    //根据是否为PNG,判断有无实提单                
                    FileStream fs = new FileStream($"{System.Environment.CurrentDirectory}/scanOutReal.PDF", FileMode.Open, FileAccess.Read);
                    BinaryReader reader = new BinaryReader(fs);
                    string fileClass;
                    byte buffer;
                    byte[] b = new byte[2];
                    buffer = reader.ReadByte();
                    b[0] = buffer;
                    fileClass = buffer.ToString();
                    buffer = reader.ReadByte();
                    b[1] = buffer;
                    fileClass += buffer.ToString();
                    reader.Close();
                    fs.Close();
                    if (fileClass == "13780")//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar 
                    {
                       
                    }
                    else
                    {
                        
                    }
                
             
              
原文地址:https://www.cnblogs.com/king10086/p/12911248.html