maria.bonet
maria.bonet

Reputation: 427

problems downloading signed pdf files c#

I have a signed pdf with Adobe signature well done. My problem starts when I want to download this document.

Via webmethod I get the bytes of the signed file. Until here there is no problems.

If I try to save the file in my server, when I open the file everything is correct. But if I try to download it when I open it the signature is wrong.

This is the error in adobe reader:

"The scope of the signed data is defined by a range of unexpected bytes. Details: The range of bytes of the signature is invalid"

This is the way I download the file:

HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename= Factura.pdf");
HttpContext.Current.Response.AddHeader("Content-Length", newStream.Length.ToString());
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.OutputStream.Write(newStream.GetBuffer(), 0, newStream.GetBuffer().Length);
HttpContext.Current.Response.OutputStream.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();

Can anyone help me with this problem?

Upvotes: 0

Views: 551

Answers (1)

Paulo Soares
Paulo Soares

Reputation: 1916

You are sending more bytes than thos advertised in the header. Do newStream.ToArray() and only use the byte array. Other thing to check is if you really have all the bytes in newStream, save it to a file to check (from the ToArray().

Upvotes: 2

Related Questions