Thursday 14 March 2013

How to Read PDF files in Android?

Read PDF Files from Sdcard in Android

First Create one Android Project in Eclipse after that download PDFViewer.jar file from Internet and then add into project's build path.

After Create one Activity in this Project, Name is Second.java

Second.java

public class Second extends PdfViewerActivity {
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    }
   
    public int getPreviousPageImageResource() {
    return R.drawable.left_arrow;
    }
   
    public int getNextPageImageResource() {
    return R.drawable.right_arrow;
    }
   
    public int getZoomInImageResource() {
    return R.drawable.zoom_in;
    }
   
    public int getZoomOutImageResource() {
    return R.drawable.zoom_out;
    }
   
    public int getPdfPasswordLayoutResource() {
    return R.layout.pdf_file_password;
    }
   
    public int getPdfPageNumberResource() {
    return R.layout.dialog_pagenumber;
    }
   
    public int getPdfPasswordEditField() {
    return R.id.etPassword;
    }
   
    public int getPdfPasswordOkButton() {
    return R.id.btOK;
    }
   
    public int getPdfPasswordExitButton() {
    return R.id.btExit;
    }
   
    public int getPdfPageNumberEditField() {
    return R.id.pagenum_edit;
    }
}

After that Add below code into your project's main activity and change extends Activity to ListActivity in your java file.

First.java

public class First extends ListActivity {
   
    String[] pdflist;
    File[] imagelist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
   
    File images = Environment.getExternalStorageDirectory();
    imagelist = images.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
    return ((name.endsWith(".pdf")));
    }
    });
    pdflist = new String[imagelist.length];
    for (int i = 0; i < imagelist.length; i++) {
    pdflist[i] = imagelist[i].getName();
    }
    this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pdflist));
    }
   
    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    String path = imagelist[(int) id].getAbsolutePath();
    openPdfIntent(path);
    }
   
    private void openPdfIntent(String path) {
    try {
    final Intent intent = new Intent(First.this, Second.class);
    intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
    startActivity(intent);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
}

And Don't Forget to Add Second Activity in Android Manifest file.

Enjoy :--)

118 comments:

  1. how read assets floder pfd file

    ReplyDelete
  2. Can you Please send me source code of this project?
    I got error in it...
    My id-bkothari99@gmail.com

    ReplyDelete
  3. i got a error in onclick..help me..

    ReplyDelete
  4. i also got error when m click on file.......

    ReplyDelete
  5. pls give the link of jar file

    ReplyDelete
    Replies
    1. https://github.com/jblough/Android-Pdf-Viewer-Library

      Delete
  6. Dear Sir,

    Thank you sir for this post. i am getting List Books from my mnt/sdcard. but when i click on any book it shows me error like this. [ http://pastebin.com/TUaVKrxt ].
    and it shows error on below two line from first.java class.
    " openPdfIntent(path);" //line no.53
    "final Intent intent = new Intent(First.this, Second.class);" //line no. 58

    PLEASE HELP ME AS SOON AS POSSIBLE.

    ReplyDelete
  7. it is run but some time it crash automatically..

    ReplyDelete
  8. Everything is fine but only Loading PDF Page, and PDF is not loading...

    ReplyDelete
  9. I got a NullPointerException error that related to the imagelist = images.listFiles() ; in First.class !!
    Can you help me ?!

    ReplyDelete
  10. Thanks for the tutorial, it was a good starting point, but do you know of any RECENT examples with to Read PDF files in Android.. A lot of things in this code are deprecated..
    Android Training institute in chennai with placement | Android Training in chennai |Android Training in Velachery | android development course fees in chennai

    ReplyDelete
  11. I have never needed to do this, but you could probably use a library like iText to access the PDF file programmatically, and then display the PDF.Android Training in chennai | Android Training|Android Training in chennai with placement | Android Training in velachery

    ReplyDelete
  12. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
    Click here:
    angularjs training in btm
    Click here:
    angularjs training in rajajinagar
    Click here:
    angularjs training in marathahalli
    Click here:
    angularjs training in bangalore
    Click here:
    angularjs training in pune

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
    Blueprism training in Chennai

    Blueprism training in Bangalore

    Blueprism training in Pune

    Blueprism online training

    Blueprism training in tambaram

    ReplyDelete
  15. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Devops Training in Chennai

    Devops Training in Bangalore

    Devops Training in pune

    ReplyDelete
  16. Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, anyways I am here now and would just like to say thanks for a tremendous post. Please do keep up the great work.

    Data Science course in rajaji nagar | Data Science with Python course in chenni
    Data Science course in electronic city | Data Science course in USA
    Data science course in pune | Data science course in kalyan nagar

    ReplyDelete
  17. Well done! Pleasant post! This truly helps me to discover the solutions for my inquiry. Trusting, that you will keep posting articles having heaps of valuable data. You're the best! 

    java training in omr | oracle training in chennai

    java training in annanagar | java training in chennai

    ReplyDelete
  18. I am a regular reader of your blog and being students it is great to read that your responsibilities have not prevented you from continuing your study and other activities. Love

    angularjs-Training in chennai

    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    ReplyDelete
  19. Thanks for your contribution in sharing such a useful information. Waiting for your further updates.

    ejobsalert
    Education

    ReplyDelete
  20. I and my friends were going through the nice, helpful tips from the blog then the sudden came up with an awful suspicion I never expressed respect to the website owner for those secrets.
    iosh course in chennai

    ReplyDelete
  21. Thanks for information , This is very useful for me.
    Keep sharing Lean Six Sigma Green Belt Training Bangalore


    ReplyDelete
  22. I was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!

    informatica mdm online training

    apache spark online training

    apache spark online training

    devops online training

    aws online training

    ReplyDelete
  23. Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up.
    data science course malaysia

    ReplyDelete
  24. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    Data Science Courses

    ReplyDelete
  25. Coin master is one of the famous and grossing games right now. you can spin the wheel and believe in fortune to get a lot of Spins. But you end up getting small amounts of spins. For those who are searching for Coin Master unlimited spins, this article is very useful to them. https://meditips.in/coin-master-free-spins/

    ReplyDelete
  26. I Got Job in my dream company with decent 12 Lacks Per Annum Salary, I have learned this world most demanding course out there in the current IT Market from the Data Science Course in Bangalore Providers who helped me a lot to achieve my dreams comes true. Really worth trying.

    ReplyDelete
  27. Nice article
    Thanks for sharing the information
    Please visit leadmirro to know your blog rank

    ReplyDelete
  28. BA Revaluation Result 2019
    Hey Nice Blog!! Thanks For Sharing!!! Wonderful blog & good post. It is really very helpful to me, waiting for a more new post. Keep Blogging

    ReplyDelete
  29. Such a great information for blogger i am a professional blogger thanks…

    Looking for Best Training Institute in Bangalore , India. Softgen Infotech is the best one to offers 85+ computer training courses including IT Software Course in Bangalore , India. Also, it provides placement assistance service in Bangalore for IT.

    ReplyDelete
  30. Thanks for sharing this blog. This very important and informative blog.Become a Trainer

    ReplyDelete

  31. Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind.Student Reviews

    ReplyDelete
  32. Thanks for sharing this blog. This very important and informative blog. content



    ReplyDelete
  33. Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge.student review for Realtime Experts marathahalli bangalore

    ReplyDelete
  34. Very useful and informative blog. Thank you so much for these kinds of informative blogs.
    who provides seo services, web development services, logo design services, graphic design ,
    digital markeing and all kind of web design, development and digital marketing services.
    best website design services in gurgaon
    web company in delhi
    web desiging company
    web design & development banner
    web design & development company
    web design & development services
    web design agency delhi
    web design agency in delhi
    web design and development services
    web design companies in delhi
    web design company delhi
    web design company in delhi
    web design company in gurgaon
    web design company in noida
    web design company list
    web design company services
    web design company website
    web design delhi
    web design development company
    web design development services
    web design in delhi
    web design service
    web design services company
    web design services in delhi
    web designer company
    web designer delhi
    web designer in delhi
    web designers delhi
    web designers in delhi
    web designing & development
    web designing advertisement
    web designing and development
    web designing and development company
    web designing and development services
    web designing companies in delhi
    web designing company delhi
    web designing company in delhi
    web designing company in gurgaon
    web designing company in new delhi
    web designing company in noida
    web designing company logo
    web designing company sites
    web designing company websites
    web designing delhi
    web designing in delhi
    web designing in gurgaon
    web designing in gurgaon
    web designing service
    web designing services
    web designing services delhi

    ReplyDelete
  35. Really i found this article more informative, thanks for sharing this article! Also Check here
    CCC Previous Year Question Paper

    ReplyDelete
  36. Attend The Data Science Course Bangalore From ExcelR. Practical Data Science Course Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Science Course Bangalore.
    ExcelR Data Science Course Bangalore
    Data Science Interview Questions

    ReplyDelete
  37. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!

    data analytics courses

    data science interview questions

    business analytics courses

    data science course in mumbai

    ReplyDelete

  38. Excellent! I love to post a comment that "The content of your post is awesome" Great work!

    top data analytics courses in mumbai

    ReplyDelete

  39. I found a ton of data here to make this in reality best for all novice here. Much obliged to you for this data.

    Artificial Intelligence Training In Hyderabad

    Artificial Intelligence Course In Hyderabad

    ReplyDelete
  40. Hi, Thanks for sharing nice information about Blog...


    AI Training In Hyderabad

    ReplyDelete
  41. This comment has been removed by the author.

    ReplyDelete
  42. Attend The Data Analytics Courses From ExcelR. Practical Data Analytics Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Courses.
    Data Analytics Courses
    Data Science Interview Questions

    ReplyDelete
  43. Get the superb apartment living experience with Apartment Management Software, Accounting, Parking and Facility Management System.thanks a lot.
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  44. Really cool stuff. Thanks for sharing this small piece of code.

    AI course in indore

    ReplyDelete
  45. Thanks for sharing information awesome blog post Online Education Quiz website For Exam Follow this website Gk in Hindi

    ReplyDelete
  46. it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    Salesforce Training in Chennai

    Salesforce Online Training in Chennai

    Salesforce Training in Bangalore

    Salesforce Training in Hyderabad

    Salesforce training in ameerpet

    Salesforce Training in Pune

    Salesforce Online Training

    Salesforce Training


    ReplyDelete
  47. Apply for freelance acting jobs, freelance rappers jobs, freelance acting jobs, freelance makeup artists jobs, freelance painter jobs and for other artists jobs in India. jobs for models

    ReplyDelete
  48. Consider the best microwave oven in India with best solo, convection and under 5000,10000, 15000 in India. best microwave oven in india

    ReplyDelete
  49. Are you looking for the best Digital Marketing Courses in Aurangabad for learning digital marketing skills..? Then you are on the right website. Become a Digital Marketer with our advanced digital marketing course.
    digital Marketing courses in Aurangabad

    ReplyDelete
  50. Show some love and affinity to your grandma and grandpa by getting them unique gifts for grandma and best gifts for grandpa this Christmas. gifts for beer lovers

    ReplyDelete
  51. Searching for the best tracker in India under 3000 - 5000? This is the place where you can get the best fitness band India in 3000 to 5000. best fitness band india

    ReplyDelete
  52. Pick the best youtube videos from our playlist which are tending. Enjoy the best youtube videos and make your mood light. trending india

    ReplyDelete
  53. This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.
    Data Analyst Course

    ReplyDelete
  54. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    DevOps Training in Chennai

    DevOps Course in Chennai

    ReplyDelete
  55. Wish your family and friends with best good morning and funny quotes also send them whatsaap status and Facebook status. hindi motivational quotes

    ReplyDelete
  56. With so many books and articles coming up to give gateway to make-money-online field and confusing reader even more on the actual way of earning money,
    data scientist course

    ReplyDelete
  57. 이 웹 사이트는 내가이 주제에 대해 원했던 모든 정보를 가지고 있고 누구에게 물어봐야할지 몰랐습니다.토토
    공유해 주셔서 감사합니다!

    ReplyDelete
  58. Sex stories which are not only sexy and hot but also very hot and amazing. Best sex stories of all time. Amazing fuck story and sexy Indian sex stories which are simply wow. Got my dick hard best sex stories. indian sex stories

    ReplyDelete
  59. hi thanku so much this information this blog is very useful
    cs executive
    freecseetvideolectures/

    ReplyDelete
  60. Your website is really cool and this is a great inspiring article.
    data science training in malaysia



    ReplyDelete
  61. AximTrade Offers A Safe And Secure Platform To Do Forex Trading And CFDs And Our Customer Support Is Ready To Help You 24/7. You Can Easily Sign Up Your Aximtrade Login Account Here.

    ReplyDelete
  62. Do You Know AximTrade Review Is A Global Financial Firm That Offers A Wide Range Of Financial Services, Including Fx, Cfd, No Deposit Bonus And More Sign Up With AximTrade Login Account And Trade In Forex

    ReplyDelete
  63. AVATRADE REVIEW Review - Find Out Everything About This Forex Broker. Read Our Detailed Fx Choice Review And Make Sure If This Broker Is For You. We Scrutinized The Broker And The Trading Conditions Thoroughly.

    ReplyDelete
  64. Wonderful illustrated information. I thank you for that. No doubt it will be very useful for my future projects. Would like to see some other posts on the same subject!
    data science coaching in hyderabad

    ReplyDelete
  65. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.data science course in bhubaneswar

    ReplyDelete
  66. This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post. data science course in kanpur

    ReplyDelete
  67. I wish more writers of this sort of substance would take the time you did to explore and compose so well. I am exceptionally awed with your vision and knowledge. business analytics course in mysore

    ReplyDelete
  68. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one.
    cyber security certification malaysia

    ReplyDelete
  69. I really thank you for the valuable info on this great subject and look forward to more great posts data science training in mysore

    ReplyDelete
  70. I like this post,And I figure that they having a great time to peruse this post,they might take a decent site to make an information,thanks for sharing it to me business analytics course in kanpur

    ReplyDelete
  71. Very nice article. I enjoyed reading your post. very nice share. I want to twit this to my followers. Thanks !. data science course in surat

    ReplyDelete
  72. Hello! I just wish to give an enormous thumbs up for the nice info you've got right here on this post. I will probably be coming back to your weblog for more soon! data scientist course in kanpur

    ReplyDelete
  73. Nice knowledge gaining article. This post is really the best on this valuable topic. data science course in mysore

    ReplyDelete
  74. Looking for the best convection microwave oven in India under 10000 for your kitchen and start
    cooking. best convection microwave oven

    ReplyDelete
  75. Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
    data science training in hyderabad

    ReplyDelete
  76. Gardening Tips This method for planting was discovered by the author of My Roman Apartment. The blog owner had vowed to buy nothing new for one calendar year, but then ended up stumped over where to plant a new seedling. As it turns out, you can successfully grow a seedling in a hollowed-out citrus rind with some potting soil in it. Evening of Primrose, Perfect for Problem Areas, 5 Hard to Kill Plants for Your Flower Garden, Wake Up to Perfect Organic Gardening, How to Plant Succulents in Container Garden, Container Gardening: Choosing the Right Container, Planting Apple Trees in Your Garden for Fruit Variety, Gardening in the Pacific Northwest, Encouraging Volunteer Sunflowers to Grow and Make Your Vegetable Garden Grow

    ReplyDelete
  77. This is a really very nice post you shared, i like the post, thanks for sharing..
    data scientist course

    ReplyDelete
  78. Nice Post, If you are willing to learn graphic design from an expert, then learn graphic designing courses in Delhi from one of the best graphic design institutes in Delhi.

    ReplyDelete
  79. That is a valuable instrument and every individual who utilizes the component and downloads information and riding on the web, needs to utilize this application.Malwarebytes Free Activation Key

    ReplyDelete
  80. Nice article and thanks for sharing with us. Its very informative
    Girvi Software
    Girvi Software

    ReplyDelete
  81. This article seems to provide guidance on how to read PDF files in Android, which can be a useful skill for developers or users looking to integrate PDF viewing capabilities into their Android applications or simply read PDFs on their devices.

    Data Analytics Courses In Kochi




    ReplyDelete
  82. This concise guide offers a clear solution for reading PDF files in Android applications. The author's step-by-step instructions and code samples make it accessible and user-friendly. Great work.
    Data Analytics Courses In Dubai

    ReplyDelete
  83. Your willingness to share your knowledge and provide practical guidance is greatly appreciated. Thank you for your valuable contribution!
    Data Analytics Courses In Chennai

    ReplyDelete
  84. This article offers a comprehensive understanding of the subject. Thanks.
    Data Analytics Courses in Agra

    ReplyDelete
  85. Thank you so much for this wonderful tutorial on how to read pdf files in android.
    Visit - Data Analytics Courses in Delhi

    ReplyDelete
  86. The insights, step-by-step instructions, and practical code snippets are invaluable. It's evident that you've gone the extra mile to create this resource.

    Digital marketing courses in illinois

    ReplyDelete
  87. Thanks for sharing outstanding and incredible tutorial on How to Read PDF files in Android.
    data analyst courses in limerick

    ReplyDelete
  88. thanks for sharing such great blog post, really well written
    Digital marketing business

    ReplyDelete
  89. Thanks for some wonderful code. This was just what I was looking for.

    Investment banking analyst jobs

    ReplyDelete
  90. I was looking for this kind of information and enjoyed reading this one. the blog was very informative. Thank you for sharing. well done.
    Digital marketing courses in city of Westminster

    ReplyDelete
  91. You explained very well how to read PDF files in Android. this blog was very helpful for so many people. Thank you for sharing useful information with us. nice article.
    Data analytics framework

    ReplyDelete