示例#1
0
            private static void DrawPage(pdfDocument doc, int count, Bitmap b)
            {
                pdfPage page = doc.addPage();
                int bw = b.Width;
                int bh = b.Height;
                if (bw > page.width)
                {
                    bh = (int)((float)bh / ((float)bw / page.width));
                    bw = page.width;
                }

                if (bh > page.height)
                {
                    bw = (int)((float)bw / ((float)bh / page.height));
                    bh = page.height;
                }

                doc.addImageReference(b, "img" + count);
                pdfImageReference rf = doc.getImageReference("img" + count);
                page.addImage(rf, 0, page.height - bh, bh, bw);
            }
示例#2
0
        private void Main()
        {
            try
            {
                string source;
                using (var client = new WebClient())
                {
                    source = client.DownloadString("http://www.mangahit.com/" + CurrentChapter.Link);
                }
                _pages = int.Parse(Regex.Match(source, TotalRegex).Groups["pages"].Value);
                _link = Regex.Match(source, LinkRegex).Groups["link"].Value;
            }
            catch (Exception ex)
            {
                LogError("Error occured while gathering information.",ex.Message);
                goto DONE;
            }

            for (var page = 1; page <= _pages; page++)
            {
                download.Invoke(new Action<int, int>((current, total) =>
                    {
                        download.Text = string.Format("Downloading {0} of {1}", current, total);
                    }),page,_pages);
                var rTime = 0;
                RETRY:
                try
                {
                    if (!(Profile.Settings.Resume && File.Exists(GetPath(page))))
                    {

                        if (rTime <= Profile.Settings.Retries)
                        {
                            Http.Download(GetLink(page), GetPath(page));
                        }
                        else
                        {
                            LogError("Error occured while downloading the image","Unable to download within given number of retries.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogError("Error occured while downloading the image",ex.Message);
                    rTime++;
                    goto RETRY;
                }

                Invoke(new Action<int>(progress =>
                    {
                        Tag.Text = string.Format(ProgressFormat, CurrentChapter.Name, progress);
                        Text = string.Format(ProgressFormat, CurrentChapter.Name, progress);
                        progressBar.Value = progress;
                    }),(int)(((double)page/_pages)*100));
            }

            if (Profile.Settings.CreatePdf)
            {
                try
                {
                    using (var pdf=new pdfDocument(CurrentChapter.Name,"Abdullah Saleem"))
                    {
                        for (var page = 1; page <= _pages; page++)
                        {
                            var file = GetPath(page);

                            if (!File.Exists(file))
                            {
                                LogError("Error occured while creating the PDF","File not found.");
                                continue;
                            }

                            try
                            {
                                pdf.addImageReference(file, page.ToString("00"));
                                var refrenceImage = pdf.getImageReference(page.ToString("00"));
                                var currentPage = pdf.addPage(refrenceImage.height, refrenceImage.width);
                                currentPage.addImage(refrenceImage, 0, 0, refrenceImage.height, refrenceImage.width);
                            }
                            catch (Exception ex)
                            {
                                LogError("Error occured while creating the PDF[Internal]", ex.Message);
                            }
                        }
                        var pdfPath = Path.Combine(_directory, CurrentChapter.Name + ".pdf");
                        pdf.createPDF(pdfPath);
                        if (Profile.Settings.OpenPdf)
                        {
                            Process.Start(pdfPath);
                        }
                    }

                }
                catch (Exception ex)
                {
                    LogError("Error occured while creating the PDF", ex.Message);
                }
            }

            if (Profile.Settings.DeleteImages)
            {
                for (var page = 1; page <= _pages; page++)
                {
                    var file = GetPath(page);

                    if (!File.Exists(file))
                    {
                        LogError("Error occured while deleting the images","Image not found.");
                        continue;
                    }

                    try
                    {
                       File.Delete(file);
                    }
                    catch (Exception ex)
                    {
                        LogError("Error occured while deleting the images", ex.Message);
                    }
                }
            }
            DONE:
            Invoke(new MethodInvoker(Close));
        }