如何解码编码的base64字符串并将其下载为Android中的PDF?

发布于 2025-02-12 11:12:57 字数 1673 浏览 1 评论 0原文

我正在通过API获取/下载编码的base64字符串,现在我必须将其解码为64,然后在解码base64字符串后,我需要将其转换为PDF文件。因此,当我单击下载按钮时它会给我转换后的解码base64作为pdf。

代码:

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);

//现在我有了解码的base64字符串,现在我需要将其显示为pdfview。

}

@Override
public void didError(String message) {

}
};

我认为现在我的问题是对您的理解

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文