• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    Kotlin
  • Created almost 6 years ago
  • Updated 5 months ago

Reviews

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

Repository Details

PDF Generator library, easy way to create PDF from String Content or Any HTML Content.

PDF-Generator

Download Download Download Download

PDF Generator library, easy way to create PDF from String Content or Any HTML Content.

Attention!

// Not getting much time to maintain this code, there might be some issues with latest Android SDK.
// If you're facing any please take pull and resolve offline for your case or raise the PR for others.
// Thanks.

Get Started

dependencies {
     implementation 'com.uttampanchasara.pdfgenerator:pdfgenerator:1.3'
}

Quick Start

In order to start using PdfGenerator, Just copy below code to your project and just pass the required values and that's all you done!

Kotlin Code:

 CreatePdf(this)
            .setPdfName("FirstPdf")
            .openPrintDialog(false)
            .setContentBaseUrl(null)
            .setPageSize(PrintAttributes.MediaSize.ISO_A4)
            .setContent("Your Content")
            .setFilePath(Environment.getExternalStorageDirectory().absolutePath + "/MyPdf")
            .setCallbackListener(object : CreatePdf.PdfCallbackListener {
                override fun onFailure(errorMsg: String) {
                    Toast.makeText(this@MainActivity, errorMsg, Toast.LENGTH_SHORT).show()
                }

                override fun onSuccess(filePath: String) {
                    Toast.makeText(this@MainActivity, "Pdf Saved at: $filePath", Toast.LENGTH_SHORT).show()
                }
            })
            .create()

Java Code:

new CreatePdf(this)
            .setPdfName("FirstPdf")
            .openPrintDialog(false)
            .setContentBaseUrl(null)
            .setPageSize(PrintAttributes.MediaSize.ISO_A4)
            .setContent("Your Content")
            .setFilePath(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyPdf")
            .setCallbackListener(new CreatePdf.PdfCallbackListener() {
                @Override
                public void onFailure(@NotNull String s) {
                    // handle error
                }

                @Override
                public void onSuccess(@NotNull String s) {
                    // do your stuff here
                }
            })
            .create();

NOTE: ( Provide STORAGE Permission if you are providing filePath to library )

In library, I'm not handling any storage permission related exception, If you are providing your custom filePath then your application must have STORAGE READ-WRITE Permission in order to store Pdf in provided path.

Usage

  • setPdfName : String

Provide Your Pdf name, Library will use to save pdf with this name.

  • openPrintDialog : Boolean

Default is false, If you set true it will send your pdf for print and open the android default pdf print view.

  • setContentBaseUrl : String

If you are loading content from assets folder in that case you can pass your base url here, same as we passed in webview.

  • setPageSize : PrintAttributes.MediaSize

To set custom page size for your pdf, you will have to pass the mediaSize as argument.

Example - For A4 size: PrintAttributes.MediaSize.ISO_A4 | ISO_A0 | ISO_A1

  • setContent : String

Provide your String content, which you want to generate Pdf.

  • setFilePath : String

Provide custom file path to save pdf in your own directory, default will be the cache directory of Application

  • setCallbackListener : Listener Interface

Set this callback listener to get callback on pdf generated.

Benefits

  • Easily Generate Pdf
  • No Extra codes
  • Time saving
  • Lightweight

More?

If you have any suggestions or you can make this library better write me, create issue, or you can also write code and send pull request.

Questions?

Ping-Me on : Twitter Facebook

profile for Uttam Panchasara at Stack Overflow, Q&A for professional and enthusiast programmers

Donate

If you found this library helpful, consider buying me a cup of ☕

Stargazers over time

Stargazers over time

License

   Copyright 2019 Uttam Panchasara

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

More Repositories

1

Shared-Element-Transition-Kotlin

Android Shared element transition example from Fragment to Activity on viewpager with recyclerview.
Kotlin
42
star
2

Flutter-Floating-Menu

A new Flutter package which helps developers in creating Floating Menu.
Dart
38
star
3

TodoNotes

A Todo Notes Application developed with flutter, with basic functionalities to write quick Notes.
Dart
26
star
4

FlutterExpandableMenu

A new Flutter package which helps developers in creating Expandable Menu.
Dart
18
star
5

MultiTheme

Sample Project to demonstrate that how to use multi theme in Android application without using any Libraries.
Kotlin
18
star
6

FlutterLoginUI

Flutter Login-Registration UI with Sliding Animation.
Dart
15
star
7

FloatingMenu

This is a example to use Floating Menu Package in your Application.
Dart
9
star
8

FlutterDBExample

A Flutter application, To show the use of sqflite database in flutter with easy and clean structure.
Dart
8
star
9

iCollect

Hobby Project: Fully Offline Android Application to Collect data with basic information of User, In which I have used barcode scanner to scan any code and other basic information of user and store that as record also show the history for same.
Kotlin
8
star
10

FirstFlutter

Flutter Project: To Learn Firebase Authentication + Cloud Firestore implementation in Flutter.
Dart
6
star
11

ImgurGallery

Flutter Project : Imgur API Integration in Flutter
Dart
5
star
12

FlutterToast

Flutter Example, To show toast message in flutter.
Dart
5
star
13

Kotlin-BaseProject

This repository contains a sample project with basic screens that implements MVP architecture using Dagger2, Room, RxJava2, and Retrofit
Kotlin
5
star
14

NodePractice

Practice : Basic of JavaScript + Node, In which learning how to write APIs on Node.
JavaScript
4
star
15

FlutterExamples

Dart
4
star
16

LoginUI

Java
4
star
17

multitheme-flutter

It's a demo application for multiple theme support dynamically with custom color attributes.
Dart
3
star
18

RuntimePermission

This is sample Utils class to ask runtime permission.
Java
2
star
19

DefaultProjectTemplate

Java
2
star
20

Firestore-Demo

2
star
21

Firebase-Cloud-Firestore-Demo

This is to Learn the basic usage of Firebase and Cloud Firestore Database, To Achieve simple SignIn, SignUp and User listing work flow using Cloud Firestore.
Kotlin
2
star
22

ConsraintLayout-Animations

This is a sample project for animations which is created using constraint layout.
Kotlin
2
star
23

base-flutter

Dart
2
star
24

flutter_base_project

Dart
2
star
25

customtablewidget

Dart
1
star
26

NewsHeadlines

This is Simple Application to show News Feeds with best UI using Android's Material design.
Kotlin
1
star