Extarct string from PDF

Extarct string from PDF

how can i search a particular character from pdf? also extarct string from a pdf document??

View Answers

January 18, 2011 at 1:40 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class ReadPDF {
    public static void main(String[] args) throws IOException {
        try {
            Document document = new Document();
            document.open();
            PdfReader reader = new PdfReader("file.pdf");
            PdfDictionary dictionary = reader.getPageN(1);
            PRIndirectReference reference = (PRIndirectReference) dictionary.get(PdfName.CONTENTS);
            PRStream stream = (PRStream) PdfReader.getPdfObject(reference);
            byte[] bytes = PdfReader.getStreamBytes(stream);
            PRTokeniser tokenizer = new PRTokeniser(bytes);
            StringBuffer buffer = new StringBuffer();
            while (tokenizer.nextToken()) {
                if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
                    buffer.append(tokenizer.getStringValue());
                }
            }
            String test = buffer.toString();
            System.out.println(test);
        } catch (Exception e) {
        }
    }
}

For the above code, you need itext api.

Thanks


January 20, 2011 at 9:36 PM

Thanks for response.This code is working fine.But if there are any special charecter then this code is not working properly.If there are any solution please upload.









Related Tutorials/Questions & Answers:
Extarct string from PDF
Extarct string from PDF  how can i search a particular character from pdf? also extarct string from a pdf document
Extracting position of a particular string from a PDF
Extracting position of a particular string from a PDF  I have a pdf form. I want to knw the exact position(location) of a particular string of that form. Using iText I have extracted all the string from the PDF form, but nt able
Advertisements
Extarct equation
Extarct equation  Want to extarct equation of the form ax+by+c=0 from... org.apache.poi.hwpf.extractor.WordExtractor; public class FileRead{ public static void main(String... File("c:\\Hello.doc"); String st=""; FileInputStream fis=new FileInputStream
create pdf from jsongrid
create pdf from jsongrid  i need to create pdf from jsongrid in java struts2.. otherwise i need to create pdf from result set
pdf generate from jsp
pdf generate from jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
Create PDF from java
Create PDF from java  Good afternoon, I have a problem how to create report. i want to create report in pdf file from my database in mysql. Now i... code to create pdf file from database call from java programming. thank you
reading from pdf
reading from pdf  how can i read specific words from pdf file?   Java Read pdf file import java.io.*; import java.util.*; import... static void main(String[] args) throws IOException { try
pdf from i report
pdf from i report  I have a problem again with my report, i use I Report to make pdf file. but when the application running in java, pdf can't view. but in rtf format data can view. or can icon save like this to be dissapear
Removing characters from a string
Removing characters from a string  Removing characters from a string...(String []args){ String str="Hello 123.you are At 3456"; String...() method removes all blank spaces in the string
reading from pdf to java - Java Beginners
reading from pdf to java  How can i read the pdf file to strings in java. I need the methods of reading data from file and to place that data in the string, using java.   Hi Friend, We are providing you a code
jsonelement from string
jsonelement from string  Hi, I have to create jsonelement from string in Java. How to do this? Thanks   Hi, You can use following code: Gson gson = new Gson(); String data ="Hello"; JsonElement ele
Java dom from string
Java dom from string  Hi, How to create dom tree from string data? I am trying to search the example for java dom from string. Thanks... static void main(String[] args) { String url="http://www.roseindia.net
remove a substring from a string
remove a substring from a string  Please I jave an arraylist composed as follwoing [w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2] w2.w4 is a subset of w2.w3.w4 ?how I recognize it also ADS_TO_REPLACE_1 w1.w3
how to generate the pdf report from jsp
how to generate the pdf report from jsp  <%@page import... want to generate the pdf file from jsp page.I add the itext.jar to the libraries... not getting the pdf file.Any one please help me asap.Its very important
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP
Removing character from a string in sql.
Removing character from a string in sql.  How to remove or replace character from a string
Removing character from a string in sql.
Removing character from a string in sql.  Removing special characters from a string in sql
Generate unicode malayalam PDF from JSP
Generate unicode malayalam PDF from JSP   Hi, I want to generate a malayalam report in PDF format.I have generated a report in jsp.Now I want the same report to be saved as PDF in unicode malayalam font.I have tried to generate
Stripping of unwanted characters from string
Stripping of unwanted characters from string  how to strip off unwanted characters from a string   Hi Friend, Try this: public class StripCharacters { public String strip(String s) { String st
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP?   remove last comma from string names = names.replaceAll(",$", ""); //Or a simple substring: if (names.endsWith(",")) { names
remove punctuation from string in java
remove punctuation from string in java  Hi, I want to remove punctuation in text from Java program. How to remove punctuation from string in java... RemovePunctExample { public static void main(String[] args) { //Construct String
Removing HTML from a Java String
Removing HTML from a Java String  Removing HTML from a Java String
How to return a string from a JTextField
How to return a string from a JTextField  Hi, Am new to java, and am trying to get a string from a JTextField so that I can compare it with another String using either compare or equals or compareTo methods of the String class
Convert Text To PDF
required for the conversion of a text file into the pdf file from http... from console that returns a string into byte format. Convert this byte... Convert Text To PDF      
convert data from pdf to text file - Java Beginners
convert data from pdf to text file   how to read the data from pdf file and put it into text file(.txt
Reading string from file timed
Reading string from file timed  So I want to make a file reader/ buffered reader that reads a new line of the textfile, lets say every 30 second. Like it reads the first line, waiting 30 seconds, read the next line and so one
how to add the scrollbar to the pdf page when generating the pdf file from jsp - JSP-Servlet
how to add the scrollbar to the pdf page when generating the pdf file from jsp  I am not able to see all the columns when i generated the pdf file from jsp.i have 12 colums so how to add the scrollbar
open pdf file in same jsp page and the pdf file should retrieved from database
open pdf file in same jsp page and the pdf file should retrieved from database  Hai all, I need code to open a pdf file in same jsp page(browser) while click on hyperlink And the file was located in database table. Can any
How to read PDF files created from Java thru VB Script
How to read PDF files created from Java thru VB Script  We have created the PDF file thru APache FOP but when we are unable to read the data thru... to read the FOP pdf? Is their any tool which convert the Apache FOP to Adobe PDF
pdf file is having the 0 KB when generate the pdf file from jsp - JSP-Servlet
pdf file is having the 0 KB when generate the pdf file from jsp  Hi Friend, I am getting OKB pdf file .if i inserting the image into pdf file , i am getting the OKB pdf file now and also not able to open the pdf
how to generate the pdf file with scroolbar from jsp age - JSP-Servlet
how to generate the pdf file with scroolbar from jsp age  How to generate the pdf file with scroolbar from jsp.i am not able to see the all the columns in pdf file now .it is very urgent for me plz help
Count Palindromes from the string
Count Palindromes from the string In this section, we are going to find out the number of palindromes from the string. For this, we have allowed the user to input a sentence or string. This string is then break down into tokens using
How to set the pdfptable as pdf page header when generating the pdf from jsp page. - JSP-Servlet
How to set the pdfptable as pdf page header when generating the pdf from jsp page.  how to set the pdfptable column headers as a header of the documet.i need to display the column headers for every pdf page if pdf documt is 20
PHP get character from String
PHP Get Character From String To get sub string from a String we can use substr() method. Structure of this method is :ADS_TO_REPLACE_1 string substr (string $var, int $initial [, int $len]  ) In the above example we want
generating itext pdf from java application - Java Beginners
generating itext pdf from java application  hi, Is there any method in page events of itext to remove page numbers from pdf generated frm java application.  Hi friend, Read for more information. http
create a string from an array using JavaScript
create a string from an array using JavaScript  How to use "join()" to create a string from an array using JavaScript
Remove duplicate characters from the string
Remove duplicate characters from the string In this tutorial, you will learn how to remove duplicate characters from the string. Java has provide several.... Here we are going to remove duplicate characters from the string
Java Remove a character from string
Java Remove a character from string In this tutorial, you will learn how to remove a character from the string. There are several methods for examining... to remove a particular character from the string. In the given example, we have
ModuleNotFoundError: No module named 'nums-from-string'
ModuleNotFoundError: No module named 'nums-from-string'  Hi, My... named 'nums-from-string' How to remove the ModuleNotFoundError: No module named 'nums-from-string' error? Thanks   Hi, In your
Java: Searching a string from doc files
Java: Searching a string from doc files   I want to search a string from DOC, DOCX files in java. Can anyone please help me
How to evaluate the mathematical expression from the string in J2ME.
How to evaluate the mathematical expression from the string in J2ME.  How to evaluate the mathematical expression from the string in J2ME. For example a string containing "24".From the string i want evaluate the mathematical
How to evaluate the mathematical expression from the string in J2ME.
How to evaluate the mathematical expression from the string in J2ME.  How to evaluate the mathematical expression from the string in J2ME. For example a string containing "24".From the string i want evaluate the mathematical
how to write to file from string in Java
how to write to file from string in Java  Hi, Please any one help me for how to write to file from string in Java. I am beginner in Java programming. Thanks,   Hi, Are you eager to learn how to write to file from
Java get Int from String
Java get Int from String     ... from String. For this, we have defined a string. The method  Integer.parseInt(st) converts the string into the integer. Here is the code
Remove Repeated Characters from the String
Remove Repeated Characters from the String In this we are going to remove repeated characters from the string. For this, we have allowed the user to enter the string. The class BufferedReader reads the string from the console. Then we
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u...="com.lowagie.text.pdf.*"%> <% String name[]=request.getParameterValues("name
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u...="com.lowagie.text.pdf.*"%> <% String name[]=request.getParameterValues("name
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u...="com.lowagie.text.pdf.*"%> <% String name[]=request.getParameterValues("name
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u...="com.lowagie.text.pdf.*"%> <% String name[]=request.getParameterValues("name
query regarding exporting table from jsp page to pdf
query regarding exporting table from jsp page to pdf  hello i am displaying one table on my jsp page and i want to save that table in pdf file can u...="com.lowagie.text.pdf.*"%> <% String name[]=request.getParameterValues("name

Ads