コード例 #1
0
        private static void RunApp()
        {
            if (!Directory.Exists(saveFolder))
            {
                Directory.CreateDirectory(saveFolder);
            }



            var reader = new PdfReader(pdfPath);
            var raf    = new RandomAccessFileOrArray(pdfPath);



            Console.WriteLine("PDF Found, getting text.");
            for (var i = 1; i < reader.NumberOfPages; i++)
            {
                PDFText.Add(PdfTextExtractor.GetTextFromPage(reader, i));

                if (PdfImageExtractor.PageContainsImages(pdfPath, i))
                {
                    PDFImages.Add(PdfImageExtractor.ExtractImages(pdfPath, i));
                }
            }


            Console.WriteLine(string.Format("Found {0} pages of text, from {1} pages in PDF", PDFText.Count, reader.NumberOfPages));

            var saveFile = System.IO.Path.Combine(saveFolder, string.Format("{0}_Text.txt", pdfName));

            Console.WriteLine(string.Format("Saving text to {0}", saveFile));
            File.AppendAllLines(saveFile, PDFText);

            Console.WriteLine("Saving Images");

            foreach (var dict in PDFImages)
            {
                foreach (var key in dict.Keys)
                {
                    System.Drawing.Image img;
                    if (dict.TryGetValue(key, out img))
                    {
                        imageCount += dict.Count - 1;
                        try
                        {
                            img.Save(System.IO.Path.Combine(saveFolder, key));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }
            }

            Console.WriteLine(string.Format("Saved {0} images in {1}", imageCount, saveFolder));
            Console.WriteLine("...any key to continue...");
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: DennisWacom/AlphaSign
        private void getSignatureFromPdf(string pdf_filename)
        {
            bool imagesFound = PdfImageExtractor.PageContainsImages(pdf_filename, 1);

            if (imagesFound)
            {
                Dictionary <string, System.Drawing.Image> dict = PdfImageExtractor.ExtractImages(pdf_filename, 1);
                foreach (string key in dict.Keys)
                {
                    System.Drawing.Image img = dict[key];
                    img.Save("sign.png");

                    SigObj sig = new SigObj();
                    ReadEncodedBitmapResult result = sig.ReadEncodedBitmap("sign.png");
                    if (result == ReadEncodedBitmapResult.ReadEncodedBitmapOK)
                    {
                        MessageBox.Show(sig.Who + " " + sig.Why + " " + sig.When);
                    }
                }
            }
        }