0

I am developing android application. This application allows the user to highlight words in PDF file. Then these words must be extracted, so how can I parse the PDF file to get extracted words from the file without any library? Can any one help me?

Kalpesh
  • 4,020
  • 4
  • 18
  • 27
user3393104
  • 31
  • 1
  • 5
  • What have you tried so far? Please edit your question to include your attempts and any code that you have used. – Blue Ice Mar 09 '14 at 21:54

2 Answers2

0

You have to code it yourself if you don't want to use a libary. There isn't any build-in classes in Android SDK for PDF manipulation.

However you have to use a Libary and have a look at this question:

PDF Library to rendering the PDF files in Android

Community
  • 1
  • 1
Jackson
  • 149
  • 8
  • Thank you for your replay, If I want to write code by my self , can i read the PDFfile like other text file? an how can i get the background color of the text? – user3393104 Mar 09 '14 at 22:17
  • You can't do that because you have to use the SDK from Adobe and that is managed code. so it would be very difficult. Why don't you want to use a library? – Jackson Mar 09 '14 at 22:19
0

You can parse PDF easily on android easily using the iText library as like I've done it on my project by parsing a pdf file from assets and displaying it in the android listview.

iTextG Link: https://developers.itextpdf.com/itextg-android

assetManager = getAssets();

try{
    InputStream inputStream = assetManager.open("sample.pdf");
    String parsedText = "";
    PdfReader reader = new PdfReader(inputStream);
    int n = reader.getNumberOfPages();

    for (int i = 0; i < n; i++)
        parsedText = parsedText + PdfTextExtractor.getTextFromPage(reader, i + 1).trim() + "\n";

    String[] data = parsedText.split("\n");

    for(String d : data){
        patients.add(d);
    }

    reader.close();

}catch (FileNotFoundException e){
    Toast.makeText(this, "File Not Found", Toast.LENGTH_SHORT).show();
}catch (IOException e){
    Toast.makeText(this, "IO Error reading input stream", Toast.LENGTH_SHORT).show();
}
  • 1
    Welcome to SO! Code-only answers are discouraged, as they provide no insight into how the problem was solved. Please update your solution with an explanation of how your code solves the OP's problem :) – Joel Oct 14 '18 at 02:21