I have one url, for e.g., "https://www.[REDACTED].com/article/toDownload.pdf"
After pasting url in browser, PDF gets downloaded.
What I want is to download PDF and convert it into
base64
.
Issue:
But after converting the code into
base64
, it does not show proper pdf format. It gets converted into base 64 but, after decoding it
base64
to PDF online, it does not show valid format.
Can anyone help me with this??
string downloadPdf = "https://www.[REDACTED].com/article/toDownload.pdf";
using (WebClient webClient = new WebClient())
{
webClient.Headers["Cache-Control"]= "public";
webClient.Headers["Content-Description"] = "File Transfer";
webClient.Headers["Content-Disposition"] = "attachment;
filename=$sample\".\".pdf";
webClient.Headers["Content-Type"] = "application/pdf";
webClient.Headers["Content-Transfer"] = "binary";
byte[] imageBytes = webClient.DownloadData(downloadPdf);
var base64 = Convert.ToBase64String(imageBytes);
}
Online tool shows this error after decoding base64 to PDF:
"The MIME of file was detected as "application/octet-stream", but the decoder displays it as "application/pdf". To view it as is , Your browser cannot display the file as "application/pdf"."
What I have tried:
I tried different code that I got from Google, but am facing the same issue. I also used
httpWebRequest
in C#.