public static bool IsPdfPageBlank(string pdf_file, int page) { var text_found = false; try { if (!System.IO.File.Exists(pdf_file)) { throw new Exception("File does not exist."); } var reader = new iTextSharp.text.pdf.PdfReader(pdf_file); var strat = new Models.Utilities.iTextSharpUtilities.MyLocationTextExtractionStrategy(); var text = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page, strat); var re = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z0-9\s,]*$"); if (!re.IsMatch(text)) { text_found = true; } reader.Close(); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); } return(text_found); }
public static bool IsPdfPageBlank(System.IO.MemoryStream pdf_stream, int page) { var text_found = false; try { var reader = new iTextSharp.text.pdf.PdfReader(pdf_stream.ToArray()); var strat = new Models.Utilities.iTextSharpUtilities.MyLocationTextExtractionStrategy(); var text = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page, strat); var re = new System.Text.RegularExpressions.Regex(@"[a-zA-Z0-9]"); if (!re.IsMatch(text)) { text_found = true; } reader.Close(); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); } return(text_found); }