0

I am getting/ downloading the encoded base64 string through api, Now I have to decoding it to base 64, and then after decoding the base64 string, I need to convert it as pdf file.so that when I click the downloading button it will give me the converted decoding base64 as PDF.

Code:

Context context;
List<BillReceiptReport> list;
UtilityBillManager manager;
String encodedBase64 = "";
public BillReportDetailsAdapter(Context context, List<BillReceiptReport> list) {
this.context = context;
this.list = list;
}

@Override
public BillReportDetailsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new BillReportDetailsViewHolder(LayoutInflater.from(context).inflate(R.layout.transaction_reports_details_item_layout, parent, false));
}
@Override
public void onBindViewHolder(@NonNull BillReportDetailsViewHolder holder, int position) {
BillReceiptReport billReceiptReport = list.get(position);

holder.downloadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
manager = new UtilityBillManager(context, AppBaseController.get().getUserSettings());
manager.UserTransactionReceiptReport(listener,billReceiptReport); //UserTransactionReceiptReport is the api where i get the base64 string from server.
}
});
}
private final TransactionReportListener listener = new TransactionReportListener() {

@Override
public void didFetch(String response, String message) {
encodedBase64 = response;
//Log.e("tag",encodedBase64);
byte [] decodeBase64 = android.util.Base64.decode(encodedBase64, Base64.DEFAULT);

// Now i have the decoded base64 string, Now i need to showing it as pdfview.

}

@Override
public void didError(String message) {

}
};

I think now my question is understanding to you

ayaz khan
  • 29
  • 7
  • can you look my code now as I am updating it, where I am wrong? @KJ – ayaz khan Jul 02 '22 at 03:15
  • One thing that is wrong is that `didError` is doing nothing with the error message. Try (at least) logging it ... so you can see when an error occurs and what the message says. – Stephen C Jul 02 '22 at 03:19
  • You should also provide (at least) the code that declares and initializes all of the variables used in the above. And provide a clear explanation of what happens when you run the code, including all relevant error messages and exception stacktraces (from logcat) – Stephen C Jul 02 '22 at 03:23
  • @StephenC, i am storing my encoded base64 string to encodedbase64 string, which comes from the api. then i decode it. now the problem is i don't know how the process is downloading it as pdf. I updated my code. after decoding the base64 then what will be my approaches to download it as pdf. – ayaz khan Jul 02 '22 at 03:38
  • @StephenC, after decode the base64 string, what will i do download it as pdf from app. can you help? – ayaz khan Jul 02 '22 at 03:51
  • You need to respond properly to our comments. Show us the code, error messages, stacktraces ... as requested. Otherwise we can't diagnose your problem or help you to fix your code. – Stephen C Jul 02 '22 at 04:00
  • I should also point out that it is hard to understand shat you are doing here. In the title you are asking about downloading the PDF from the server >>to<< the app. In your comments you seem to be talking about downloading the PDF >>from<< the app. Confusing. (And conversely, if you have gotten the base64 encoded PDF from the server, you have **already** downloaded it, so you don't need to download it again. Explain what you are actually trying to do with the downloaded PDF.) – Stephen C Jul 02 '22 at 04:05
  • Instead of writing a stream of confusing comments, you would do better if you EDITed the question to explain clearly what you are trying to do, and ... address all of the other issues. But if what you are really trying to do here is to get someone to write the code for you for free (i.e. "show you" the code) ... that's not how StackOverflow works. – Stephen C Jul 02 '22 at 04:09
  • @StephenC, now I updated my code as what I want. I need some idea that after decoding the base64 string how will be my approaches. i just need some clear advice to solve the problem as my own. – ayaz khan Jul 02 '22 at 04:29
  • OK ... so I would just like to point out that what you are asking NOW is very different to what you were asking before, both in the original question (and original code) and your earlier comments. Looking at the code now. (It is not easy ... given the horrible way it is formatted ...) – Stephen C Jul 02 '22 at 04:32
  • sorry for being my confusing comments or approaching for the guidance i want. Now can you help ? – ayaz khan Jul 02 '22 at 04:39
  • 1
    OK. I think I understand now. Given that what you are now really asking is how to display the PDF on the Android device, you need to tell us which PDF viewer you intend to use. Note that Android doesn't have PDF viewing as part of the standard platform. So you either need a 3rd party library or a 3rd-party app to do this. Which one have you chosen? If you haven't chosen one yet, **my guidance** is: 1) do some research on PDF viewers / viewing for Android, 2) select one, 3) read the documentation provided on how to integrate it with an Android app. – Stephen C Jul 02 '22 at 04:39
  • 1
    You could start by reading https://stackoverflow.com/questions/9666030 and https://stackoverflow.com/questions/25170975 ... or Googling for "display pdf android" – Stephen C Jul 02 '22 at 04:47
  • @StephenC, One question need to ask, after decode base64, can I convert the decoded base64 to as .pdf file? will you give some idea on these too. – ayaz khan Jul 02 '22 at 04:58
  • Sure. Just write it to the file system with a filename "something.pdf". Or wrap it in a `ByteArrayInputStream`. It is already a PDF file. – Stephen C Jul 02 '22 at 05:27
  • @StephenC, I am successfully achieved what i was looking for, after decoding the base64 string, I get the .pdf formate file. but i face one problem can i share my code? – ayaz khan Jul 02 '22 at 07:51
  • Ask a new question. (This question is basically unanswerable ... and should be deleted.) – Stephen C Jul 02 '22 at 08:00
  • @StephenC I posted this can you look it , https://stackoverflow.com/questions/72837085/how-to-dynamically-changes-the-pdf-file-name – ayaz khan Jul 02 '22 at 08:17
  • @StephenC, I raised with a new question. can you look. it will be helpful for me. – ayaz khan Jul 02 '22 at 08:37

0 Answers0