• Stars
    star
    249
  • Rank 162,987 (Top 4 %)
  • Language
    Java
  • License
    GNU General Publi...
  • Created over 9 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert android XML layouts into PDF document, works on all versions of Android.

Android-PdfMyXml Android Arsenal Jitpack

convert your android XML layouts into PDF document, works on all versions of Android.

Dependencies

How to use

Option 1: Simply fork or download the project, you can also download and create .aar file yourself.

Option 2: Jitpack

Add Jitpack in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add to your dependencies:

dependencies {
    compile 'com.github.HendrixString:Android-PdfMyXml:{Tag}' // the latest version is "v1.0.1"
}

Notable features

  • should work on all Android versions
  • completely scalable
  • supports bitmap re usage.
  • production proved code. Used in a commercial project.

Instructions

1. create XML layouts

First create XML layouts. give it dimensions in pixels (and for all it's sub views) and proportions according landscape or portrait according to ratio 1:1.41.

page1.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="2115px"
                android:layout_height="1500px"
                android:background="@color/white">
  <TextView android:id="@+id/tv_hello"
                android:textColor="@color/black"
                android:textSize="27px"
                android:textStyle="bold"
                android:padding="6px"/>

</RelativeLayout>

you can create as many as pages/templates as you need.

2. Implement a View renderer

implement your View renderer by extending AbstractViewRenderer or by anonymously instantiating it and injecting the layout id. the initView(View view) will supply you an inflated View automatically. There are other options but I wont cover it now.

AbstractViewRenderer page = new AbstractViewRenderer(context, R.layout.page1) {
    private String _text;

    public void setText(String text) {
        _text = text;
    }

    @Override
    protected void initView(View view) {
        TextView tv_hello = (TextView)view.findViewById(R.id.tv_hello);
         tv_hello.setText(_text);
    }
};

// you can reuse the bitmap if you want
page.setReuseBitmap(true);

3. Build the PDF document

Use PdfDocument or PdfDocument.Builder to add pages and render and run it all at background with progress bar.

PdfDocument doc            = new PdfDocument(ctx);

// add as many pages as you have
doc.addPage(page);

doc.setRenderWidth(2115);
doc.setRenderHeight(1500);
doc.setOrientation(PdfDocument.A4_MODE.LANDSCAPE);
doc.setProgressTitle(R.string.gen_please_wait);
doc.setProgressMessage(R.string.gen_pdf_file);
doc.setFileName("test");
doc.setSaveDirectory(_ctx.getExternalFilesDir(null));
doc.setInflateOnMainThread(false);
doc.setListener(new PdfDocument.Callback() {
    @Override
    public void onComplete(File file) {
        Log.i(PdfDocument.TAG_PDF_MY_XML, "Complete");
    }

    @Override
    public void onError(Exception e) {
        Log.i(PdfDocument.TAG_PDF_MY_XML, "Error");
    }
});

doc.createPdf(ctx);

or use PdfDocument.Builder

new PdfDocument.Builder(ctx).addPage(page).orientation(PdfDocument.A4_MODE.LANDSCAPE)
                         .progressMessage(R.string.gen_pdf_file).progressTitle(R.string.gen_please_wait)
                         .renderWidth(2115).renderHeight(1500)
                         .saveDirectory(_ctx.getExternalFilesDir(null));
                         .filename("test")
                         .listener(new PdfDocument.Callback() {
                             @Override
                             public void onComplete(File file) {
                                 Log.i(PdfDocument.TAG_PDF_MY_XML, "Complete");
                             }

                             @Override
                             public void onError(Exception e) {
                                 Log.i(PdfDocument.TAG_PDF_MY_XML, "Error");
                             }
                         }).create().createPdf(this);

Additional Contributors

License

If you like it -> star or share it with others

Copyright (C) 2016 Tomer Shalev (https://github.com/HendrixString)  

This program 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.

This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

Contact Author

More Repositories

1

adobe-cep-react-create

Create Adobe-CEP extension with React, Material-UI, Native Node modules, Webpack, Babel and ExtendScript
JavaScript
112
star
2

Android-Zorn

Async Workers and Worker managers for Android
Java
87
star
3

Falcon

Responsive/Flexible UI controls for Feathers-UI
ActionScript
21
star
4

Android-TriOrm

A 3d database ORM experiment. (used in two commercial projects)
Java
19
star
5

Hendrix-HttP-AiR

a lightweight HTTP library for ActionScript 3 (as3) inspired by Square's OkHttp
ActionScript
12
star
6

node-okhttp

Lightweight HTTP library for Node.js inspired by Square's OkHttp Builder patterns
JavaScript
11
star
7

Quake-Gameboy-Advance

3d engine that runs Quake 1 levels on Nintendo Gameboy Advance hardware.
7
star
8

Google-Glass-Mirror-API-AS3

Google Glass Mirror API implementation for AS3
ActionScript
5
star
9

Hendrix-GfxManager-Starling-AIR

GFX manager for stage3d/Starling
ActionScript
5
star
10

3d-pocket

3D engine developed for Pocket PC and Symbian enabled devices at 2003
5
star
11

Starling-Bidi-TextField

Bidirectional(RTL languages) Bitmap Font TextField control for Starling
ActionScript
4
star
12

Hendrix-Collection-Air

Data structure collection library for AiR/AS3
ActionScript
3
star
13

Hendrix-ContentManager-Air-as3

content manager for Adobe AIR/Flex
ActionScript
3
star
14

Hendrix-ProcessManager-AIR

Worker/Process manager for Adobe AIR
ActionScript
3
star
15

sfly-quest

sfly-quest
2
star
16

Adobe-Flex-4-Comps

A collection of some good Flex 4 comps I have written
ActionScript
2
star
17

Hendrix-Facebook-Aggregator-Air-AS3

Facebook Aggregator library for Adobe AiR (AS3)
ActionScript
2
star
18

HendrixString

1
star