Git Product home page Git Product logo

android-pdfium's Introduction

Pdfium Android library

Original Android pdfium has few rendering issues.

Build tweaks:

Natives shall be build manually. Read more about setup OS and build scripts from links below. Use gclient config --unmanaged --custom-var=checkout_android=True https://pdfium.googlesource.com/pdfium.git, ./build.sh and build.diff

  • library renamed to libmodpdfium.so because API21 && API22 failed to lookup symbols due to conflict with /system/lib/libpdfium.so.

Some portion of jni code shared with:

Example

    ParcelFileDescriptor fd = ...;
    int pageNum = 0;
    Pdfium pdfium = new Pdfium();
    pdfium.open(fd);
    Pdfium.Size size = pdfium.getPageSize(pageNum);
    Pdfium.Page page = pdfium.getPage(pageNum);

    // ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError
    // RGB_565 - little worse quality, twice less memory usage
    Bitmap bitmap = Bitmap.createBitmap(size.width, size.height, Bitmap.Config.RGB_565);
    
    pdfium.render(bitmap, 0, 0, bm.getWidth(), bm.getHeight());

    Log.e(TAG, "title = " + pdfium.getMeta(Pdfium.META_TITLE));
    Log.e(TAG, "author = " + pdfium.getMeta(Pdfium.META_AUTHOR));

    for (Pdfium.Bookmark b : pdfium.getTOC()) {
        Log.e(TAG, String.format("- %s, p %d", sep, b.title, b.page));
    }

    p.close();
    
    pdfium.close();

Reading links

    ParcelFileDescriptor fd = ...;
    int pageNum = 0;
    Pdfium pdfium = new Pdfium();
    pdfium.open(fd);
    Pdfium.Page page = pdfium.getPage(pageNum);
    List<Pdfium.Link> links = page.getLinks();
    for (Pdfium.Link link : links) {
        Rect mappedRect = p.mapRectToDevice(..., link.getBounds())

        if (clickedArea(mappedRect)) {
            String uri = link.getUri();
            if (link.getDestPageIdx() != null) {
                // jump to page
            } else if (uri != null && !uri.isEmpty()) {
                // open URI using Intent
            }
        }
    }

Links

android-pdfium's People

Contributors

axet avatar barteksc avatar matpag avatar mshockwave avatar phaestion avatar yusefmaali avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.