Create and Display PDF within Android Application

Embedding functionality to Create and Display PDF within Android Application can increase engagement of your user significantly. Rather than asking user to bounce off to other pdf viewer application, we will create an application with support of Pdf creation and viewing functionalities.


 

[su_button url=”https://github.com/androidsrc/PdfReadWrite” target=”blank” style=”stroked” background=”#51d461" color=”#ffffff” size=”6" center=”yes” radius=”0" icon=”icon: arrow-circle-o-down”]Download Full Source Code[/su_b[/su_button]p> 

[su_ca[su_carousel source=”media: 522,523,524,525,526" link=”lightbox” width=”1000" height=”720" items=”2" mousewheel=”no”]d.permission.INTERNET[/su_carousel][/su_carousel]e Application For Creation and Display of Pdf

1. Create a new Android Application Project with Package name com.androidsrc.pdfdemo. Make sure to select API 21. As PdfRenderer was introduced in requires API level 21. If you are creating functionality of Pdf document creation only, you can opt for API 19 as well.

2. Preparing AndroidManifest.xml

Add permission into your manifest file to read and write from external storage. Ensure to add uses-sdk tag with minSdkVersion specified as 21.

You may also like...

20 Responses

  1. Asad Mughal says:

    its really a good tutorial

  2. Sunil Singh says:

    can I add textcolor and textstyle in PDF using PDFviewer pls help

  3. daniyal says:

    it is showing errors

  4. Pranav Pal Lekhi says:

    The line ‘outputFile.createNewFile();’ is giving me an IOException. It says ‘ENOENT No such file or directory’. What could I be doing wrong?

  5. Prachi Singh says:

    Hi, thanks a lot for your help! Can you tell me how to zoom-in or zoom-out while displaying a pdf?

  6. Masi Ahmad says:

    Hi i also get the errors

    content.getWidth()
    and content.draw(page.getCanvas());

    And idont know how to call runOnUiThread

  7. Jon says:

    Hi does anyone get a “NullPointerException” on closeOption?

    10-08 16:06:23.001 30249-30249/com.micron.jrobinsonriv.read_pdf E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.micron.jrobinsonriv.read_pdf, PID: 30249
    java.lang.NullPointerException: Attempt to invoke interface method ‘android.view.MenuItem android.view.MenuItem.setVisible(boolean)’ on a null object reference
    at com.micron.jrobinsonriv.read_pdf.Read_pdf_main.updateView(Read_pdf_main.java:249)
    at com.micron.jrobinsonriv.read_pdf.Read_pdf_main.onClick(Read_pdf_main.java:275)
    at android.view.View.performClick(View.java:5702)
    at android.widget.TextView.performClick(TextView.java:10887)
    at android.view.View$PerformClick.run(View.java:22546)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7237)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

  8. Carlos Sierra says:

    how to use this when your app uses only a webview ( I develop hybrid apps, using html content local storage )

  9. ani says:

    Thank you so much for the sharing. I’m having an issue when trying to put a message dialog. It needs to click “OK” button several times(~2-3 times) to close the dialog.

  10. Mica Kardashian says:

    Como faço pra ler pdf com uma api abaixo da 21?
    quero na versão 4.0

  11. Pavneet Singh says:

    when i click the botton “open pdf” and “create pdf “application is crash !!
    Give me solution…

  12. Abdul Rehman says:

    its has many errors update the code and in how much android app api till it works?

  1. August 30, 2016

    […] create-and-display-pdf-within-android-application String myPdfUrl = "http://example.com/awesome.pdf"; String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl; Log.i(TAG, "Opening PDF: " + url); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(url); […]

  2. April 20, 2018

    […] Create and Display PDF within Android Application […]

Leave a Reply

Your email address will not be published. Required fields are marked *