Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am getting pdf from httpwebresponse, I have copied response stream to memory stream and converting stream data to base64 string using bytes array.

and saving the base64 string data in database, if pdf contains plain text it is working fine.

if pdf contains images or highlighted contents correct base64 string is not coming and pdf is not opening.

Please give me solution to get pdf data.

Response Headers

content-type: application/pdf
content-disposition: attachment; filename="test.pdf"


Thanks,
Ajay

What I have tried:

using (HttpWebResponse responsePdf = (HttpWebResponse)request.GetResponse())
{
    Stream stream = responsePdf.GetResponseStream();
    MemoryStream memoryStream = new MemoryStream();
    stream.CopyTo(memoryStream);

    byte[] bytes = memoryStream.ToArray();
    base64PdfData = Convert.ToBase64String(bytes);

    stream.Close();
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900