示例#1
0
        public static void Run()
        {
            // ExStart:RecognizeBarcodeFromPDFDocuments
            // For complete examples and data files, please go to https://github.com/aspose-barcode/Aspose.BarCode-for-.NET
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_TechnicalArticles();

                // Bind the pdf document
                Pdf.Facades.PdfExtractor pdfExtractor = new Pdf.Facades.PdfExtractor();
                pdfExtractor.BindPdf(dataDir + @"document.pdf");

                // Set page range for image extraction
                pdfExtractor.StartPage = 1;
                pdfExtractor.EndPage   = 1;

                // Extract the images
                Console.WriteLine("Extracting images....");
                pdfExtractor.ExtractImage();

                // Save images to stream in a loop
                while (pdfExtractor.HasNextImage())
                {
                    Console.WriteLine("Getting next image....");

                    // Save image to stream
                    MemoryStream imageStream = new MemoryStream();
                    pdfExtractor.GetNextImage(imageStream);
                    imageStream.Position = 0;
                    Console.WriteLine("Recognizing barcode....");

                    // Recognize the barcode from the image stream above
                    using (BarCodeReader reader = new BarCodeReader(imageStream, DecodeType.Code39Standard))
                    {
                        foreach (BarCodeResult result in reader.ReadBarCodes())
                        {
                            Console.WriteLine("Codetext found: " + result.CodeType + ", Symbology: " + result.CodeText);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:RecognizeBarcodeFromPDFDocuments
            Console.WriteLine(Environment.NewLine + "Recognize BarCode From PDF Documents Finished.");
        }
示例#2
0
        private void ParseDocument(DocumentInfo documentInfo, string zipOutFolder)
        {
            var doc = new Document(documentInfo.FileName);
            // Extract text
            var pdfExtractor = new Pdf.Facades.PdfExtractor(doc);

            pdfExtractor.ExtractText();
            pdfExtractor.GetText(zipOutFolder + "\\" + Path.GetFileNameWithoutExtension(documentInfo.FileName) + ".txt");

            // Extract images
            pdfExtractor.ExtractImage();
            System.IO.Directory.CreateDirectory(zipOutFolder + "\\images\\");
            var imageFileNameTemplate = System.IO.Path.GetFileNameWithoutExtension(documentInfo.FileName);
            var imageCounter          = 0;

            while (pdfExtractor.HasNextImage())
            {
                var imageFileName = zipOutFolder + "\\images\\" + imageFileNameTemplate + (++imageCounter).ToString("D8") + ".png";
                pdfExtractor.GetNextImage(imageFileName,
                                          System.Drawing.Imaging.ImageFormat.Png);
            }

            // Extract attachments
            pdfExtractor.ExtractAttachment();
            System.IO.Directory.CreateDirectory(zipOutFolder + "\\attachments\\");
            pdfExtractor.GetAttachment(string.Format("{0}\\attachments", zipOutFolder));

            // Extract Annotations
            var pdfAnnotationEditor = new Pdf.Facades.PdfAnnotationEditor(doc);
            var annotType           = new[] { AnnotationType.FreeText, AnnotationType.Highlight, AnnotationType.Ink };
            var stream = System.IO.File.OpenWrite(string.Format("{0}\\annotation.xdf", zipOutFolder));

            pdfAnnotationEditor.ExportAnnotationsXfdf(stream, 1, doc.Pages.Count, annotType);
            stream.Close();

            // Export bookmarks
            var bookmarkEditor = new Pdf.Facades.PdfBookmarkEditor(doc);

            bookmarkEditor.ExportBookmarksToXML(string.Format("{0}\\bookmarks.xml", zipOutFolder));

            // Export form data
            var form = new Aspose.Pdf.Facades.Form(doc);

            stream = System.IO.File.OpenWrite(string.Format("{0}\\formdata.xdf", zipOutFolder));
            form.ExportFdf(stream);
            stream.Close();
        }