Example #1
0
        public static double CalculateTimeForFiles(string filePath)
        {
            double time = 0;

            time += TimeCalc.TimeCutPage(filePath);
            time += TimeCalc.TimeGeneratePage();
            time += TimeCalc.TimeGeneratePdf();
            return((time) / 1.065);
        }
Example #2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            dlg.Filter           = "Pdf Files|*.pdf";
            dlg.Multiselect      = true;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                double time = 0;
                button1.Enabled = false;
                label2.Text     = "Розраховується час виконання...";
                label2.Visible  = true;
                for (int i = 0; i < dlg.FileNames.Length; i++)
                {
                    time += TimeCalc.CalculateTimeForFiles(dlg.FileNames[i]);
                    //Cutter.DeleteJpeg();
                }

                label1.Visible = true;
                //label2.Text = TimeCalc.MinuteSeconds(TimeCalc.CalculateTimeForFiles(dlg.FileNames[i])).ToString();

                for (int i = 0; i < dlg.FileNames.Length; i++)
                {
                    label2.Text = $"Файл {i + 1} з {dlg.FileNames.Length}";

                    //label2.Text = TimeCalc.TimeCutPage(dlg.FileNames[i]).ToString()+"\n";
                    //label2.Text += TimeCalc.TimeGeneratePage()+"\n";
                    ProgressBar progressBar = new ProgressBar();
                    progressBar.Name     = progressBar + i.ToString();
                    progressBar.Location = new Point(12, 100);
                    progressBar.Width    = 284;
                    progressBar.Height   = 30;
                    this.Controls.Add(progressBar);
                    await Task.Run(() => Cutter.ConvertToImg(dlg.FileNames[i], ref progressBar, ref time, ref label1));

                    await Task.Run(() => Cutter.GeneratePdf(ref progressBar, i.ToString(), ref time, ref label1, dlg.FileNames[i]));

                    this.Controls.Remove(progressBar);
                    // label2.Visible = false;
                }
            }
            label1.Text     = "";
            label2.Text     = "";
            button1.Enabled = true;
        }
Example #3
0
        private async void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] FileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
            button1.Enabled = false;
            double time = 0;

            button1.Enabled = false;
            label2.Text     = "Розраховується час виконання...";
            label2.Visible  = true;
            for (int i = 0; i < FileNames.Length; i++)
            {
                time += TimeCalc.CalculateTimeForFiles(FileNames[i]);
                //Cutter.DeleteJpeg();
            }

            label1.Visible = true;
            //label2.Text = TimeCalc.MinuteSeconds(TimeCalc.CalculateTimeForFiles(dlg.FileNames[i])).ToString();

            for (int i = 0; i < FileNames.Length; i++)
            {
                label2.Text = $"Файл {i + 1} з {FileNames.Length}";

                //label2.Text = TimeCalc.TimeCutPage(dlg.FileNames[i]).ToString()+"\n";
                //label2.Text += TimeCalc.TimeGeneratePage()+"\n";
                ProgressBar progressBar = new ProgressBar();
                progressBar.Name     = progressBar + i.ToString();
                progressBar.Location = new Point(12, 100);
                progressBar.Width    = 284;
                progressBar.Height   = 30;
                this.Controls.Add(progressBar);
                await Task.Run(() => Cutter.ConvertToImg(FileNames[i], ref progressBar, ref time, ref label1));

                await Task.Run(() => Cutter.GeneratePdf(ref progressBar, i.ToString(), ref time, ref label1, FileNames[i]));

                this.Controls.Remove(progressBar);
                // label2.Visible = false;
            }
            label1.Text     = "";
            label2.Text     = "";
            button1.Enabled = true;
        }
Example #4
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();
 }
Example #5
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();
            }
        }