示例#1
0
 public static void GeneratePdf(ref ProgressBar progressBar, string name, ref double time, ref Label label, string fileName)
 {
     using (PdfDocument doc = new PdfDocument())
     {
         string        folderPath = "PDF\\CUTTED\\QR\\";
         DirectoryInfo dirInfo    = new DirectoryInfo(folderPath);
         Stopwatch     sw         = new Stopwatch();
         foreach (var file in dirInfo.GetFiles("*.jpeg"))
         {
             PdfPage   page_    = null;
             XImage    img      = null;
             XGraphics graphics = null;
             sw.Start();
             try
             {
                 page_    = doc.AddPage();
                 img      = XImage.FromFile(file.FullName.ToString());
                 graphics = XGraphics.FromPdfPage(page_);
                 graphics.DrawImage(img, 0, 0, (int)page_.Width, (int)page_.Height);
             }
             finally
             {
                 page_.Close();
                 img.Dispose();
                 graphics.Dispose();
                 progress(progressBar);
             }
             sw.Stop();
             time -= sw.ElapsedMilliseconds;
             TimeCalc.MinuteSeconds(time, label);
             sw.Reset();
         }
         string[] fileNames = fileName.Split(new char[] { '\\' });
         doc.Save($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\PDF\\{fileNames[fileNames.Length-1]}");
     }
     Cutter.DeleteJpeg();
 }
示例#2
0
        public static void ConvertToImg(string path, ref ProgressBar progressBar, ref double time, ref Label label)
        {
            //Stopwatch sw = new Stopwatch();
            // sw.Start();
            SautinSoft.PdfFocus f = new PdfFocus();
            f.OpenPdf(path);
            int    pageCount      = f.PageCount;
            string prefixFilePath = "PDF\\";

            f.ImageOptions.Dpi = 320;
            Stopwatch sw = new Stopwatch();

            Cutter.setMaximumAndStep(progressBar, f.PageCount * 2);

            for (int i = 1; i <= f.PageCount; i++)
            {
                sw.Start();
                f.ToImage(prefixFilePath + i.ToString() + ".jpeg", i);
                sw.Stop();
                time -= sw.ElapsedMilliseconds;
                TimeCalc.MinuteSeconds(time, label);
                sw.Reset();
            }

            f.ClosePdf();

            for (int i = 1; i <= pageCount; i++)
            {
                sw.Start();
                Cutter.Cut(prefixFilePath + i.ToString() + ".jpeg", i, progressBar);
                sw.Stop();
                time -= sw.ElapsedMilliseconds;
                TimeCalc.MinuteSeconds(time, label);
                sw.Reset();
            }
        }