Ejemplo n.º 1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //txtScanResult.Text = ReadImage(txtFilePath.Text);
            Pdf2ImageSettings settings;

            settings = new Pdf2ImageSettings();
            settings.AntiAliasMode = AntiAliasMode.High;
            settings.Dpi = 300;
            settings.GridFitMode = GridFitMode.Topological;
            settings.ImageFormat = ImageFormat.Png24;
            settings.TrimMode = PdfTrimMode.CropBox;

            Bitmap firstPage = new Pdf2Image(txtFilePath.Text).GetImage(1);

            string outputfilePath = System.IO.Path.Combine(@"D:\temp\", System.IO.Path.GetFileNameWithoutExtension(txtFilePath.Text));

            firstPage.Save(outputfilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Ejemplo n.º 2
0
        private string GetPage(string projectName, string pdfPath, int pageNumber, out int pageCount)
        {
            byte[] imageBytes = null;
            string response = null;
            string prefix = "data:image/png;base64,";

            Pdf2ImageSettings settings;

            settings = new Pdf2ImageSettings();
            settings.AntiAliasMode = AntiAliasMode.High;
            settings.Dpi = 300;
            settings.GridFitMode = GridFitMode.Topological;
            settings.ImageFormat = ImageFormat.Png24;
            settings.TrimMode = PdfTrimMode.CropBox;

            if (File.Exists(pdfPath))
            {
                var converter = new Pdf2Image(pdfPath);

                Bitmap pageImage = converter.GetImage(pageNumber);

                pageCount = converter.PageCount;

                var jpegFilePath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/pages"), projectName + pageNumber + ".jpg");

                pageImage.Save(jpegFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);

                ImageConverter imgConverter = new ImageConverter();
                imageBytes = (byte[])imgConverter.ConvertTo(pageImage, typeof(byte[]));
                response = Convert.ToBase64String(imageBytes);

                return prefix + response;
            }

            // if the file path is invalid set the page count to zero
            pageCount = 0;

            return "";
        }