0

I am creating an application that will generate a PDF on Android (with itextg library) without storing it, just to show the info as a PDF.

I have the following code to generate the PDF:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("Hello world"));   
document.close();

byte[] pdfByteArray = baos.toByteArray();

and it works fine but I could not find a working example that work for me (using a ByteArrayOutputStream). These are the questions that I have looked:

but with any of their responses I have been able to show the PDF on Android.

How can I visualize the PDF that I have generated in my Android application?

Thanks in advance!

Community
  • 1
  • 1
Francisco Romero
  • 12,787
  • 22
  • 92
  • 167
  • you have to start activity that renders PDF format: `intent.setDataAndType(uri, "application/pdf");` and create your own `ContentProvider` that serves your generated PDF – pskink Aug 08 '16 at 11:53
  • Didn't you ask that question already? http://stackoverflow.com/questions/38788794/is-there-some-way-to-visualize-data-as-pdf-without-storing-it-on-android – Amedee Van Gasse Aug 08 '16 at 11:59
  • @AmedeeVanGasse I do not think so because as BrunoLowagie points out, it was off-topic because I was looking for a general purpose. Now it is more specific, with code and some related questions (in the other question I did not know what should I search). Should I delete the other question and maintain this one as it is better asked? – Francisco Romero Aug 08 '16 at 12:06
  • @pskink Now I am looking about it because I never have used it. I will put an answer if I get it or edit the question with more code when I complete it if I am not able to get it. – Francisco Romero Aug 08 '16 at 12:28
  • and? does custom `ContentProvider` work? – pskink Aug 09 '16 at 12:37
  • @pskink I tried doing with `ContentProvider` but I was not able to get it. I am looking more examples to have a reference. – Francisco Romero Aug 09 '16 at 14:37
  • examples will not help here, you need to find out the solution by yourself – pskink Aug 09 '16 at 20:24
  • @pskink Yes, that's true. I am reading documentation about it but I think that an example always help to visualize how it works better (just a simple example, not to copy-paste an internet example) P.S: I am not asking about to get it here. – Francisco Romero Aug 10 '16 at 06:05
  • see `ContentProvider#openFile(Uri uri, String mode)` – pskink Aug 10 '16 at 08:13

0 Answers0