百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

Android-XML-to-PDF-Generator

> 设计协作
开源

此库使用步骤构建器模式非常轻松地将 XML 转换为 PDF

197 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

此库使用步骤构建器模式非常轻松地将 XML 转换为 PDF

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) ids or directly views objects

Run the sample app and see it's or youtube video below for getting more clearance.

  • 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
  • ➤ Getting Started
  • ➤ License

➤ 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.8'
}
```	
## ➤ 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

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](https://github.com/Gkemon/Android-XML-to-PDF-Generator/blob/master/sample/src/main/res/layout/demo_a4_sized_page.xml). You just need to make your XML's  width:hight aspected ratio 1:1.14142. Referece is [here](https://www.papersizes.org/sp/a/a4#:~:text=The%20aspect%20ratio%20(width%3Aheight,(1%3A%E2%88%9A2) ).

### 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](https://github.com/Gkemon/Android-XML-to-PDF-Generator/edit/master/README.md#from-views) ) 

…


### From view IDs :

…


### 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](https://github.com/Gkemon/Android-XML-to-PDF-Generator/issues/4#issuecomment-712690701) )

…

	

### 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](https://github.com/Gkemon/Android-XML-to-PDF-Generator/blob/master/sample/src/main/java/com/emon/exampleXMLtoPDF/demoInvoice/DemoInvoiceFragment.java) 

### 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](https://developer.android.com/reference/androidx/core/content/FileProvider) is used to open file here. To get a good insight about it please see the [tutorial](https://vladsonkin.com/how-to-share-files-with-android-fileprovider/). 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](https://github.com/Gkemon/Android-XML-to-PDF-Generator/issues/16) is fixed by rearranging XML like [this](https://github.com/Gkemon/Android-XML-to-PDF-Generator/blob/master/sample/src/main/res/layout/layout_test_invoice.xml)

So if you find any trouble,then you are also welcomed again to knock me.Thank you so much. 
LinkedIn
   &nbsp; 
  
    Inbox
  

#### Logo credit: [kirillmazin](https://www.behance.net/kirillmazin)

## ➤ License

The source code is licensed under the [Apache License 2.0](https://github.com/Gkemon/XML-to-PDF-generator/blob/master/LICENSE). 
## ➤ App using it 
* [Codeddit Programmer Community](
https://play.google.com/store/apps/details?id=com.codedditapp.codeddit)
* [হাজিরা খাতা - Attendance sheet - HaziraKhata](
https://play.google.com/store/apps/details?id=com.Teachers.HaziraKhataByGk)
* [Trust Axiata Pay](
https://play.google.com/store/apps/details?id=com.tad.bdkepler&hl=en&gl=US)
* [Prideboard](https://play.google.com/store/apps/details?id=com.pridesys.prideboard)

* [Treatbook - Your Health Coach and Medical Tracker](
https://play.google.com/store/apps/details?id=com.newlit.treatbook&hl=en&gl=US)

* [Mobflow](
https://play.google.com/store/apps/details?id=com.brazzo.mobflow)

* [Front Benchers](https://play.google.com/store/apps/details?id=com.mr_17.front_benchers)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidandroid-arsenalandroid-developmentdesign-pattern

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类设计协作
定价开源

> 相关工具

F
Figma
协作式界面设计工具
S
sketch-wakatime
Sketch plugin for automatic time tracking and metrics generated from your Sketch usage.
Q
QuickColor
Quickly apply fills from the global or document color palettes to selected elements - 🎨