C# Extract text from PDF using PdfSharp

Took Sergio’s answer and made some extension methods. I also changed the accumulation of strings into an iterator. public static class PdfSharpExtensions { public static IEnumerable<string> ExtractText(this PdfPage page) { var content = ContentReader.ReadContent(page); var text = content.ExtractText(); return text; } public static IEnumerable<string> ExtractText(this CObject cObject) { if (cObject is COperator) { var cOperator … Read more

How to extract string following a pattern with grep, regex or perl [duplicate]

Since you need to match content without including it in the result (must match name=” but it’s not part of the desired result) some form of zero-width matching or group capturing is required. This can be done easily with the following tools: Perl With Perl you could use the n option to loop line by … Read more

Getting URL parameter in java and extract a specific text from that URL

I think the one of the easiest ways out would be to parse the string returned by URL.getQuery() as public static Map<String, String> getQueryMap(String query) { String[] params = query.split(“&”); Map<String, String> map = new HashMap<String, String>(); for (String param : params) { String name = param.split(“=”)[0]; String value = param.split(“=”)[1]; map.put(name, value); } return … Read more

Extracting text from a PDF file using PDFMiner in python?

Here is a working example of extracting text from a PDF file using the current version of PDFMiner(September 2016) from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.converter import TextConverter from pdfminer.layout import LAParams from pdfminer.pdfpage import PDFPage from io import StringIO def convert_pdf_to_txt(path): rsrcmgr = PDFResourceManager() retstr = StringIO() codec=”utf-8″ laparams = LAParams() device = TextConverter(rsrcmgr, … Read more

How to extract a substring using regex

Assuming you want the part between single quotes, use this regular expression with a Matcher: “‘(.*?)'” Example: String mydata = “some string with ‘the data i want’ inside”; Pattern pattern = Pattern.compile(“‘(.*?)'”); Matcher matcher = pattern.matcher(mydata); if (matcher.find()) { System.out.println(matcher.group(1)); } Result: the data i want