Android-XML-to-PDF-Generator

Additional

Language
Java
Version
1.0 (Aug 31, 2020)
Created
Sep 29, 2019
Updated
Sep 11, 2020
Owner
Gk Mohammad Emon (Gkemon)
Contributor
Gk Mohammad Emon (Gkemon)
1
Activity
Badge
Generate
Download
Source code
APK file

Promotion

XML to PDF Generator For Android

Automatically generate PDF file from XML file or Java's View object in Android

Make PDF from Android layout resources (e.g - R.layout.myLayout,R.id.viewID), Java's view ids or directly views objects

  • ➤ Table of Contents➤ Installation➤ Getting Started➤ License➤ InstallationStep 1. Add the JitPack repository to your root build.gradle at the end of repositoriesallprojects { repositories { // ... maven { url 'https://jitpack.io' } } } Step 2. Add the dependencydependencies { implementation 'com.github.Gkemon:XML-to-PDF-generator:1.0' } ➤ Getting StartedYou can generate PDF from many sources.Layout resources (i.e: R.layout.myLayout)View ids (i.e: R.id.viewID)Java view objects (i.e View,TextView,LinearLayout)From layout resources :PdfGenerator.getBuilder() .setContext(context) .fromLayoutXMLSource() .fromLayoutXML(R.layout.layout_print,R.layout.layout_print) /* "fromLayoutXML()" takes array of layout resources. * You can also invoke "fromLayoutXMLList()" method here which takes list of layout resources instead of array. */ .setDefaultPageSize(PdfGenerator.PageSize.A4) /* It takes default page size like A4,A5. You can also set custom page size in pixel * by calling ".setCustomPageSize(int widthInPX, int heightInPX)" here. */ .setFileName("Test-PDF") /* It is file name */ .setFolderName("FolderA/FolderB/FolderC") /* It is folder name. If you set the folder name like this pattern (FolderA/FolderB/FolderC), then * FolderA creates first.Then FolderB inside FolderB and also FolderC inside the FolderB and finally * the pdf file named "Test-PDF.pdf" will be store inside the FolderB. */ .openPDFafterGeneration(true) /* It true then the generated pdf will be shown after generated. */ .build(newPdfGeneratorListener() { @OverridepublicvoidonFailure(FailureResponsefailureResponse) { super.onFailure(failureResponse); /* If pdf is not generated by an error then you will findout the reason behind it * from this FailureResponse. */ } @OverridepublicvoidshowLog(Stringlog) { super.showLog(log); /*It shows logs of events inside the pdf generation process*/ } @OverridepublicvoidonSuccess(SuccessResponseresponse) { super.onSuccess(response); /* If PDF is generated successfully then you will find SuccessResponse * which holds the PdfDocument,File and path (where generated pdf is stored)*/ } });
  • Simple: Extremely simple to use. For using Step Builder Design Patten undernath,here IDE greatly helps developers to complete the steps for creating a PDF from XMLs.Powerful: Customize almost everything.Transparent: It shows logs,success-responses, failure-responses , that's why developer will nofity any event inside the process.???? Table of Contents



From view IDs :

    PdfGenerator.getBuilder()
                        .setContext(context)
                        .fromViewIDSource()
                        .fromViewID(activity,R.id.tv_print_area,R.id.tv_print_area)
   /* "fromViewID()" takes array of view ids those MUST BE and MUST BE contained in the inserted "activity" .
    * You can also invoke "fromViewIDList()" method here which takes list of view ids instead of array. */
                        .setCustomPageSize(3000,3000)
   /* Here I used ".setCustomPageSize(3000,3000)" to set custom page size.*/
                        .setFileName("Test-PDF")
                        .setFolderName("Test-PDF-folder")
                        .openPDFafterGeneration(true)
                        .build(new PdfGeneratorListener() {
                            @Override
                            public void onFailure(FailureResponse failureResponse) {
                                super.onFailure(failureResponse);
                            }

                            @Override
                            public void showLog(String log) {
                                super.showLog(log);
                            }

                            @Override
                            public void onSuccess(SuccessResponse response) {
                                super.onSuccess(response);
                            }
                        });

From views:

PdfGenerator.getBuilder()
                        .setContext(MainActivity.this)
                        .fromViewSource()
                        .fromView(view) 
   /* "fromView()" takes array of view. You can also invoke "fromViewList()" method here
    * which takes list of view instead of array. */
                        .setCustomPageSize(3000,3000)
                        .setFileName("Test-PDF")
                        .setFolderName("Test-PDF-folder")
                        .openPDFafterGeneration(true)
                        .build(new PdfGeneratorListener() {
                            @Override
                            public void onFailure(FailureResponse failureResponse) {
                                super.onFailure(failureResponse);
                            }

                            @Override
                            public void showLog(String log) {
                                super.showLog(log);
                            }

                            @Override
                            public void onSuccess(SuccessResponse response) {
                                super.onSuccess(response);
                            }
                        });

LinkedIn   Inbox

Logo credit: kirillmazin

➤ License

The source code is licensed under the Apache License 2.0.