Convert Figma logo to code with AI

JoanZapata logoandroid-pdfview

[DEPRECATED] A fast PDF reader component for Android development

2,833
783
2,833
141

Top Related Projects

Android view for displaying PDFs rendered with PdfiumAndroid

iText for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText can be a boon to nearly every workflow.

Create Toast like tooltips, but targets can be specified, plus custom properties and features

Quick Overview

JoanZapata/android-pdfview is an open-source Android library for rendering and displaying PDF documents within Android applications. It provides a customizable view component that allows developers to easily integrate PDF viewing functionality into their apps, offering smooth scrolling and zooming capabilities.

Pros

  • Easy integration with Android projects
  • Smooth scrolling and zooming of PDF documents
  • Customizable appearance and behavior
  • Lightweight and efficient rendering

Cons

  • Limited advanced PDF features (e.g., form filling, annotations)
  • May have compatibility issues with some complex PDF structures
  • Not actively maintained (last update was several years ago)
  • Lack of recent updates for newer Android versions and devices

Code Examples

  1. Basic PDF viewing:
PDFView pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset("sample.pdf")
       .defaultPage(0)
       .load();

This code loads a PDF file from the app's assets and displays it in the PDFView.

  1. Customizing page display:
pdfView.fromFile(new File(pdfPath))
       .pages(0, 2, 4) // Specify pages to display
       .enableSwipe(true)
       .swipeHorizontal(false)
       .enableDoubletap(true)
       .defaultPage(0)
       .load();

This example loads a PDF from a file, specifies which pages to display, and configures swipe and double-tap behaviors.

  1. Adding a page change listener:
pdfView.fromUri(uri)
       .defaultPage(0)
       .onPageChange(new OnPageChangeListener() {
           @Override
           public void onPageChanged(int page, int pageCount) {
               setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
           }
       })
       .load();

This code adds a listener to update the activity title when the page changes.

Getting Started

To use android-pdfview in your project:

  1. Add the JitPack repository to your build file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency:
dependencies {
    implementation 'com.github.JoanZapata:android-pdfview:1.0.4'
}
  1. Add the PDFView to your layout:
<com.joanzapata.pdfview.PDFView
    android:id="@+id/pdfView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
  1. Load a PDF in your activity or fragment:
PDFView pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset("sample.pdf").load();

Competitor Comparisons

Android view for displaying PDFs rendered with PdfiumAndroid

Pros of AndroidPdfViewer

  • More recent updates and active development
  • Better performance for large PDF files
  • Supports text selection and search functionality

Cons of AndroidPdfViewer

  • Larger library size compared to android-pdfview
  • May require more setup and configuration

Code Comparison

android-pdfview:

PDFView pdfView = (PDFView) findViewById(R.id.pdfView);
pdfView.fromAsset("example.pdf")
       .defaultPage(1)
       .showMinimap(false)
       .enableSwipe(true)
       .load();

AndroidPdfViewer:

PDFView pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset("example.pdf")
       .defaultPage(0)
       .onPageChange(this)
       .enableAnnotationRendering(true)
       .load();

Both libraries offer similar basic functionality for loading and displaying PDF files. However, AndroidPdfViewer provides more advanced features like text selection and search, which are not available in android-pdfview. The code snippets show that both libraries have a similar API for loading PDF files, but AndroidPdfViewer offers additional options for customization and event handling.

While android-pdfview is lighter and may be suitable for simpler PDF viewing needs, AndroidPdfViewer is more feature-rich and actively maintained, making it a better choice for projects requiring advanced PDF functionality and long-term support.

iText for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText can be a boon to nearly every workflow.

Pros of itext-java

  • More comprehensive PDF manipulation capabilities (creation, editing, signing)
  • Supports a wider range of PDF features and standards
  • Actively maintained with regular updates and improvements

Cons of itext-java

  • Larger library size, potentially increasing app size
  • Steeper learning curve due to more complex API
  • Commercial licensing required for some use cases

Code Comparison

android-pdfview:

PDFView pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset("sample.pdf")
    .defaultPage(0)
    .load();

itext-java:

PdfDocument pdf = new PdfDocument(new PdfWriter("output.pdf"));
Document document = new Document(pdf);
document.add(new Paragraph("Hello World!"));
document.close();

android-pdfview is focused on simple PDF viewing for Android, while itext-java offers more extensive PDF manipulation capabilities across Java platforms. android-pdfview provides an easier-to-use API for basic PDF rendering, whereas itext-java offers more advanced features at the cost of increased complexity. The choice between the two depends on the specific requirements of your project, such as the need for PDF creation or editing versus simple viewing functionality.

Create Toast like tooltips, but targets can be specified, plus custom properties and features

Pros of android-target-tooltip

  • Focused on creating tooltips for UI elements, providing a specific and targeted functionality
  • Lightweight library with minimal dependencies, easier to integrate into existing projects
  • Offers customizable tooltip appearance and positioning options

Cons of android-target-tooltip

  • Limited to tooltip functionality, not as versatile as a PDF viewer
  • May require additional libraries for more complex UI interactions
  • Less actively maintained, with fewer recent updates compared to android-pdfview

Code Comparison

android-target-tooltip:

ToolTip toolTip = new ToolTip()
    .withText("Hello, World!")
    .withColor(Color.RED)
    .withShadow();

mToolTipView = mToolTipFrameLayout.showToolTipForView(toolTip, findViewById(R.id.target_view));

android-pdfview:

PDFView pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset("sample.pdf")
    .defaultPage(0)
    .onPageChange(this)
    .load();

The code snippets demonstrate the primary use cases for each library. android-target-tooltip focuses on creating and displaying tooltips, while android-pdfview is designed for loading and displaying PDF documents. The android-pdfview code is more straightforward for its specific purpose, while android-target-tooltip offers more customization options for tooltip appearance.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

This project is no longer maintained.

You can find a good replacement here, which is a fork relying on Pdfium instead of Vudroid/MuPDF for decoding PDF files, allowing it to use the Apache License 2.0 which gives you much more freedom.


Android Arsenal

Screenshot of the sample app

Android PDFView is a library which provides a fast PDFView component for Android, with animations, gestures, and zoom. It's based on VuDroid for decoding the PDF file.

Get it

Android PDFView is available in Maven Central.

<dependency>
	<groupId>com.joanzapata.pdfview</groupId>
	<artifactId>android-pdfview</artifactId>
	<version>1.0.4</version>
	<type>apklib</type>
</dependency>

Or via gradle:

compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'

Include PDFView in your layout

<com.joanzapata.pdfview.PDFView
        android:id="@+id/pdfview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

Load a PDF file

pdfView.fromAsset(pdfName)
    .pages(0, 2, 1, 3, 3, 3)
    .defaultPage(1)
    .showMinimap(false)
    .enableSwipe(true)
    .onDraw(onDrawListener)
    .onLoad(onLoadCompleteListener)
    .onPageChange(onPageChangeListener)
    .load();
  • pages is optional, it allows you to filter and order the pages of the PDF as you need
  • onDraw is also optional, and allows you to draw something on a provided canvas, above the current page

License

Copyright 2013-2015 Joan Zapata

This file is part of Android-pdfview.

Android-pdfview is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Android-pdfview is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Android-pdfview.  If not, see <http://www.gnu.org/licenses/>.