Example #1
0
        protected override string ExtractText(string extensionName, byte[] data)
        {
            StringBuilder stringBuilder = new StringBuilder();

            PdfDocumentBase doc = null;

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(data))
                {
                    doc = SPdfDocument.MergeFiles(new Stream[] { memoryStream });
                    foreach (PdfPageBase page in doc.Pages)
                    {
                        stringBuilder.AppendLine(page.ExtractText());
                    }
                    doc.Close();
                }
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close();
                }
            }
            return(stringBuilder.ToString());
        }
Example #2
0
        protected override Picture[] ExtractImages(string extensionName, byte[] data)
        {
            List <Picture>  pictures = new List <Picture>();
            PdfDocumentBase doc      = null;

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(data))
                {
                    doc = SPdfDocument.MergeFiles(new Stream[] { memoryStream });
                    foreach (PdfPageBase page in doc.Pages)
                    {
                        foreach (Image image in page.ExtractImages())
                        {
                            pictures.Add(new Picture()
                            {
                                Data      = GetImageData(image),
                                Extension = ImageFormat.Jpeg.ToString(),
                                Width     = image.Width,
                                Height    = image.Height
                            });
                        }
                    }
                }
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close();
                }
            }
            return(pictures.ToArray());
        }