All Projects → Gkemon → Android-XML-to-PDF-Generator

Gkemon / Android-XML-to-PDF-Generator

Licence: Apache-2.0 license
This library is for convert XML to PDF very easily using Step Builders Pattern

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Android-XML-to-PDF-Generator

pdftron-android-samples
PDFTron Android Samples
Stars: ✭ 30 (-78.57%)
Mutual labels:  pdf-converter, pdf-document, pdf-generation
Pdfgen
Simple C PDF Writer/Generation library
Stars: ✭ 200 (+42.86%)
Mutual labels:  pdf-document, pdf-generation
Labelmake
Declarative style JavaScript PDF generator library. Works on Node and the browser 🖨︎
Stars: ✭ 112 (-20%)
Mutual labels:  pdf-document, pdf-generation
Pdfsave
Convert websites into readable PDFs
Stars: ✭ 46 (-67.14%)
Mutual labels:  pdf-converter, pdf-generation
laravel-print-api
Laravel package to access our print-api
Stars: ✭ 16 (-88.57%)
Mutual labels:  pdf-document, pdf-generation
Printable Mockups
Create printable UI mockups & wireframes templates
Stars: ✭ 479 (+242.14%)
Mutual labels:  pdf-document, pdf-generation
pdf-creator-node
This package is used to generate HTML to PDF in Nodejs
Stars: ✭ 122 (-12.86%)
Mutual labels:  pdf-converter, pdf-generation
chromic pdf
Convenient HTML to PDF/A rendering library for Elixir based on Chrome & Ghostscript
Stars: ✭ 196 (+40%)
Mutual labels:  pdf-converter, pdf-generation
Ptext Release
pText is a library for reading, creating and manipulating PDF files in python.
Stars: ✭ 124 (-11.43%)
Mutual labels:  pdf-converter, pdf-generation
Docnet
DocNET is as fast PDF editing and reading library for modern .NET applications
Stars: ✭ 128 (-8.57%)
Mutual labels:  pdf-converter, pdf-document
Doctron
Docker-powered html convert to pdf(html2pdf), html to image(html2image like jpeg,png),which using chrome(golang) kernel, add watermarks to pdf, convert pdf to images etc.
Stars: ✭ 141 (+0.71%)
Mutual labels:  pdf-converter, pdf-generation
pdfio
PDFio is a simple C library for reading and writing PDF files.
Stars: ✭ 55 (-60.71%)
Mutual labels:  pdf-document, pdf-generation
scryber.core
Scryber.Core is a dotnet 5 html to pdf engine written entirely in C# for creating beautiful flowing documents from html templates including css styles, object data binding and svg drawing.
Stars: ✭ 74 (-47.14%)
Mutual labels:  pdf-document, pdf-generation
Go Wkhtmltopdf
Golang commandline wrapper for wkhtmltopdf
Stars: ✭ 564 (+302.86%)
Mutual labels:  pdf-document, pdf-generation
Laravel Pdf
A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.
Stars: ✭ 79 (-43.57%)
Mutual labels:  pdf-converter, pdf-generation
Aws Lambda Libreoffice
85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli
Stars: ✭ 145 (+3.57%)
Mutual labels:  pdf-converter, pdf-generation
Expense Tracker with Pdf report
An expense Tracker 🔥🔥 which lets you add transactions 🖊🖊 and generate a pdf report of all of your transactions📋📋
Stars: ✭ 16 (-88.57%)
Mutual labels:  pdf-document, pdf-generation
PaymentCardView
Custom Credit/Debit card view
Stars: ✭ 62 (-55.71%)
Mutual labels:  android-development
circular-reveal-fragment
Push/pop fragment in style
Stars: ✭ 34 (-75.71%)
Mutual labels:  android-development
PdfToImage
Convert PDF To jpg in c# (using PdfiumViewer)
Stars: ✭ 23 (-83.57%)
Mutual labels:  pdf-converter

Logo

XML to PDF Generator For Android

Maintained Maintained

Maintained

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

Run the sample app and see the gif below for getting more clearance.

Demo

  • 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

-----------------------------------------------------

➤ Table of Contents

-----------------------------------------------------

➤ Installation

Step 1. Add the JitPack repository to your root build.gradle at the end of repositories

android {
 .
 .
  
   /*Need Java version 1.8 as Rx java is used for file write underneath for preventing UI freezing*/
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
 .
 .
}
 .
 .
allprojects {
    repositories {
        // ...
        maven { url 'https://jitpack.io' }
    }
}
.
.

Step 2. Add the dependency

dependencies {
        implementation 'com.github.Gkemon:Android-XML-to-PDF-Generator:2.6.2
}

-----------------------------------------------------

➤ Getting Started

You 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) because sometimes we need to change the content of the XML and then dealing this java view object is only way to do this.

➤ Important Note

#f03c15 #f03c15 #f03c15 For better output and make the PDF more responsive,please try to set android:layout_width of the top most view of XML a fixed value in pixel or px (Recommandation is not use dp as it depends on device screen) instead of wrap_content and match_parent otherwise sizing could be malformed in PDF for different device screen.Suppose if you want to print an A4 sized pdf so you can see my example from where. You just need to make your XML's width:hight aspected ratio 1:1.14142. Referece is here. #f03c15 #f03c15 #f03c15

From layout resources :

( Only static content in XML will be printed by this approach. If you want to change the content of the XML ,suppose there is a text view in the XML and you want to populate it with a data then try the approach )

 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. */
                        .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. */
                        .actionAfterPDFGeneration(PdfGenerator.ActionAfterPDFGeneration.SHARE)
			/* It true then the generated pdf will be shown after generated. */
                        .build(new PdfGeneratorListener() {
                            @Override
                            public void onFailure(FailureResponse failureResponse) {
                                super.onFailure(failureResponse);
				/* If pdf is not generated by an error then you will findout the reason behind it
				 * from this FailureResponse. */
                            }
			      @Override
                            public void onStartPDFGeneration() {
                                /*When PDF generation begins to start*/
                            }

                            @Override
                            public void onFinishPDFGeneration() {
                                /*When PDF generation is finished*/
                            }

                            @Override
                            public void showLog(String log) {
                                super.showLog(log);
				/*It shows logs of events inside the pdf generation process*/ 
                            }

                            @Override
                            public void onSuccess(SuccessResponse response) {
                                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)*/
				
                            }
                        });

From view IDs :

    PdfGenerator.getBuilder()
                        .setContext(context)
                        .fromViewIDSource()
                        .fromViewID(R.layout.hostLayout,activity,R.id.tv_print_area,R.id.tv_print_area)
			/* "fromViewID()" takes array of view ids and the host layout xml where the view ids are belonging.
			 * You can also invoke "fromViewIDList()" method here which takes list of view ids instead of array.*/
                        .setFileName("Test-PDF")
                        .setFolderName("Test-PDF-folder")
                        .actionAfterPDFGeneration(PdfGenerator.ActionAfterPDFGeneration.OPEN)
                        .build(new PdfGeneratorListener() {
                            @Override
                            public void onFailure(FailureResponse failureResponse) {
                                super.onFailure(failureResponse);
                            }
			    
			       @Override
                            public void onStartPDFGeneration() {
                                /*When PDF generation begins to start*/
                            }

                            @Override
                            public void onFinishPDFGeneration() {
                                /*When PDF generation is finished*/
                            }

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

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

From views:

( This approach is perfect when you need to change the XML content. You can change the content getting them by findViewById and change them and finally print them. Other example is here )

TextView tvText = view.findViewByID(R.id.tv_text_1);
tvText.setText("My changed content");
//By the following statements, we are changing the text view inside of our target "view" which is going to be changed.
//So if we now print the "view" then you will see the changed text in the pdf.

PdfGenerator.getBuilder()
                        .setContext(MainActivity.this)
                        .fromViewSource()
                        .fromView(view)
                        .setFileName("Test-PDF")
                        .setFolderName("Test-PDF-folder")
                        .actionAfterPDFGeneration(PdfGenerator.ActionAfterPDFGeneration.OPEN)
                        .build(new PdfGeneratorListener() {
                            @Override
                            public void onFailure(FailureResponse failureResponse) {
                                super.onFailure(failureResponse);
                            }

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

                            @Override
                            public void onStartPDFGeneration() {
                                /*When PDF generation begins to start*/
                            }

                            @Override
                            public void onFinishPDFGeneration() {
                                /*When PDF generation is finished*/ 
                            }
			    
                            @Override
                            public void onSuccess(SuccessResponse response) {
                                super.onSuccess(response);
                            }
                        });

Multi-paged PDF creation:

Users of the library, sometimes have doubts that how to create multi-paged PDF. Though I mentioned it above but I need to show it again for more clearance. You can insert multiple xml or views object even view id in the parameter of the following methods to create multi-paged pdf:

If you want create multi-paged pdf from xmls-

.fromLayoutXML(R.layout.layout_1,R.layout.layout_2)

If you want create multi-paged pdf from view ids -

.fromViewID(activity,R.id.viewId1,R.id.viewId2)

If you want create multi-paged pdf from views-

.fromViewID(view1,view1)

How to print an Invoice Or Report ?

Sometimes people gets stuck to print invoice or report via this library.So I wrote an example invoice/report printing fragment to visualise how to print an Invoice or Report. Here is the link also with an important documentation

How to deal with generated PDF?

With a method calling named openPDFafterGeneration(true), the generated file will be automatically opened automatically.So you DON'T NEED TO BE BOTHER FOR IT. FileProvider is used to open file here. To get a good insight about it please see the tutorial. The android:authorities name in the app is ${applicationId}.xmlToPdf.provider which might be needed if you want to deal with generated file CUSTOMLY,not letting the app open the generated file. you will get the generated file path in onSuccess(SuccessResponse response) response.

Troubleshoot

  • Try to avoid to provide match_parent and wrap_content height/width in XML. So it specifically.
  • If any of your footer view is not placed the footer position then you need adjust it using marginTop and keep it in a ScrollView.For example this issue is fixed by rearranging XML like this

So if you find any trouble,then you are also welcomed again to knock me.Thank you so much.

-----------------------------------------------------

linkedin LinkedIn   inbox Inbox

Logo credit: kirillmazin

➤ License

The source code is licensed under the Apache License 2.0.

-----------------------------------------------------

➤ App using it

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].