0

Can anyone please tell me that how to write object to file in Android? I have a table layout in which all the contents like row, footer, header information is added. I want to add this object as a file on sdcard, as I want to convert this report of TableLayout in pdf form. Can anyone please tell me how to write PDF in Android with the help of object?

ehehhh
  • 1,066
  • 3
  • 16
  • 27
Aditya
  • 115
  • 3
  • 14
  • 2
    You should change this question to "How to create a PDF file on Android?", because that is really what you're asking for isn't it? If you simply want to write data to a file there are many many solutions, but if you specifically want it as a PDF your options are a lot more limited. – britzl May 30 '13 at 06:07
  • 1
    Creating a PDF: http://stackoverflow.com/questions/2499960/how-to-create-pdfs-in-android-sdk – britzl May 30 '13 at 06:08
  • hey actually i have a report already cretaed with tables and all.I want to convert that report into pdf.For that i am using itext.But when i tried to add that object in document object,there is no method for that? – Aditya May 30 '13 at 06:11
  • If you already have some code written you should post it. It's easier to help you then. – britzl May 30 '13 at 06:22
  • Document document=new Document(); PdfWriter.getInstance(document, new FileOutputStream(Environment.getExternalStorageDirectory()+File.separator+filename)); document.open(); document.addSubject(puneet); //document.a; document.close(); – Aditya May 30 '13 at 06:29
  • in this i want to add file in document object after document.open? – Aditya May 30 '13 at 06:29
  • update your question with the code instead of adding it as a comment. It's hard to read this way. – britzl May 30 '13 at 08:15

1 Answers1

0

Generate PDF on server instead of device. PDF generation involves numerous operations and external libraries. it will be very slow on device, will need you to write comparatively more lines of codes and will not give as elegant output as by a web server.

i guess you must be getting data from a server itself(as its traditional app model), so just create a web service which can provide you a PDF file with desired table .

one way of doing this can be :

Download the iText core binary from the webpage http://sourceforge.net/projects/itext/ and use it in your java project. a good tutorial here

in case you do not have a server, but creating one is not a problem for you, just do it . will surely help you in future.

in case you want to provide offline pdf generation feature, which means user don't need internet connectivity for this, try snippet by @pratik in above answer.

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
  • hmm okie okie can u plz give tell me how to create pfd from server? – Aditya May 30 '13 at 06:27
  • hey thanks but i have already using this itext jar in my project.Actually my problem is that i am unable to add object into document object by which i can convert that object into pdf form.I know the methods how to take pdf.My pdf is also generated but when i open that pdf it shows my empty data.Actually value of object is not added to pdf.What can i do this for getting the value of object? – Aditya May 30 '13 at 06:40
  • i did not used it ever. your android specific question has been resolved . ask a separate question about your prob. with that library. – Shailendra Singh Rajawat May 30 '13 at 06:47