Esempio n. 1
0
        public Bitmap ToBitmap(string pdfFile)
        {
            Bitmap bitmap = null;

            using (PDFDoc doc = new PDFDoc(pdfFile))
            {
                foxit.common.ErrorCode error_code = doc.Load(null);
                if (error_code == foxit.common.ErrorCode.e_ErrSuccess)
                {
                    //	Console.WriteLine("The PDFDoc [{0}] Error: {1}\n", pdfFile, error_code);
                    //}
                    //else
                    //{

                    int nPageCount = doc.GetPageCount();

                    for (int i = 0; i < nPageCount; i++)
                    {
                        using (PDFPage page = doc.GetPage(i))
                        {
                            // Parse page.
                            page.StartParse((int)foxit.pdf.PDFPage.ParseFlags.e_ParsePageNormal, null, false);

                            int      width  = (int)(page.GetWidth()) * 600 / 96;
                            int      height = (int)(page.GetHeight()) * 600 / 96;
                            Matrix2D matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation());

                            // Prepare a bitmap for rendering.
                            bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            bitmap.SetResolution((float)600, (float)600);
                            using (Graphics draw = Graphics.FromImage(bitmap))
                            {
                                draw.Clear(Color.White);

                                // Render page
                                foxit.common.Renderer render = new foxit.common.Renderer(bitmap, false);
                                render.StartRender(page, matrix, null);
                            }
                        }
                    }
                }
            }
            return(bitmap);
        }
Esempio n. 2
0
        private static void GrepDates(String pdf_file)
        {
            Console.WriteLine("Search dates in " + pdf_file);

            string text_name  = pdf_file.Replace(".pdf", ".txt");
            string input_file = pdf_file;

            ErrorCode error_code = Library.Initialize(sn, key);

            if (error_code != ErrorCode.e_ErrSuccess)
            {
                Console.WriteLine("Library Initialize Error: {0}", error_code);
                return;
            }

            var text = "";

            try
            {
                using (var doc = new PDFDoc(input_file))
                {
                    error_code = doc.Load(null);
                    if (error_code != ErrorCode.e_ErrSuccess)
                    {
                        Console.WriteLine("The PDFDoc " + input_file + " Error: " + error_code);
                        return;
                    }
                    using (var writer = new StreamWriter(text_name, false, System.Text.Encoding.Unicode))
                    {
                        int pageCount = doc.GetPageCount();
                        for (int i = 0; i < pageCount; i++)
                        {
                            using (var page = doc.GetPage(i))
                            {
                                page.StartParse((int)PDFPage.ParseFlags.e_ParsePageNormal, null, false);
                                // Get the text select object.
                                using (var text_select = new TextPage(page, (int)TextPage.TextParseFlags.e_ParseTextNormal))
                                {
                                    int count = text_select.GetCharCount();
                                    if (count > 0)
                                    {
                                        String chars = text_select.GetChars(0, count);
                                        text = text + chars;
                                    }
                                }
                            }
                        }

                        foreach (var dateTime in GetDates(text))
                        {
                            writer.WriteLine(dateTime.Date.ToString("yyyy-MM-dd"));
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Library.Release();
        }