1

I am developing an Android app for flight reservation and i am using firebase Database for storing and retriving data. I need to generate a PDF of Ticket and contents should be changed as per passenger details and stored in local directory. I have a template of Ticket. What should i do?

Thank you in advance.

  • 1
    You should tag appropriately. [tag:ticket-system], if you check its page, has nothing to do with your question. Meanwhile, we don't even know what programming language you are using, whether you are looking for a clientside or a serverside solution, and especially we don't know what you have tried so far. – Amadan Apr 06 '20 at 17:50
  • I am working with Android in Android Studio and i want to generate a ticket of a flight with corresponding changes as per passenger details in users phone. – Abhijeet Rathore Apr 06 '20 at 19:10

1 Answers1

0

Since Android 5 you can use PdfDocument and its friend classes to generate a PDF document on Android device. The official documentation is here. There is no library to use a template with PdfDocument. You have to use some drawing primitive to accomplish your task.

Here is a sample to generate a PDF with a single page A4:

// create a new document
 PdfDocument document = new PdfDocument();

 // crate a page description
 PageInfo pageInfo = new PageInfo.Builder(595, 842, 1).create();

 // start a page
 Page page = document.startPage(pageInfo);

 Canvas canvas=page.getCanvas());
 // draw something on the page
 Paint paint = new Paint();
 paint.setColor(Color.RED);

 canvas.drawCircle(50, 50, 30, paint);

 // finish the page
 document.finishPage(page);

 // write the document content
 document.writeTo(getOutputStream());

 // close the document
 document.close();

The page content is defined with Canvas object. Just another example. I hope this helps you.

xcesco
  • 4,690
  • 4
  • 34
  • 65