Content-Type="Application/pdf" & Byte[]


S

Stan SR

Hi,
I call a web service method that returns an array of bytes.
This array is a PDF document and I would like to display this array as pdf
document within the browser.

So I wrote this code, but I don't get my pdf

byte[] myPDF = myWebService.GetDocument(pdfID);
Response.Clear();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition",
"inline;filename=mydoc.pdf");
Response.BinaryWrite(myPDF);
Response.End();

Any help ?

Stan
 
Ad

Advertisements

G

George Ter-Saakov

Nothing obvious wrong with your code.
Make sure that the service.GetDocument returns a pdf. Simply save it into
file on hard drive and try to open.
Most likely it's not valid pdf

George.
 
S

Stan SR

Hi George,

I ve saved the byte array to file and it's a real pdf.

here's the code I use
FileStream newFile = new FileStream(myPath, FileMode.Create);
newFile.Write(myPDF, 0, myPDF.Length);
newFile.Close();

I think I miss something in my previous script.

So if you have another Idea, it's welcome.

Stan

"George Ter-Saakov"
Nothing obvious wrong with your code.
Make sure that the service.GetDocument returns a pdf. Simply save it into
file on hard drive and try to open.
Most likely it's not valid pdf

George.

Stan SR said:
Hi,
I call a web service method that returns an array of bytes.
This array is a PDF document and I would like to display this array as
pdf document within the browser.

So I wrote this code, but I don't get my pdf

byte[] myPDF = myWebService.GetDocument(pdfID);
Response.Clear();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition",
"inline;filename=mydoc.pdf");
Response.BinaryWrite(myPDF);
Response.End();

Any help ?

Stan
 
S

Stan SR

In fact, it works using FireFox but fails using IE7.
I change some lines
Response.ClearContent();
Response.AppendHeader("content-length", myPDF.Length.ToString());
Response.ContentType = "Application/pdf";
Response.BinaryWrite(myPDF);
Response.Flush();
Response.Close();

Is it because I use the Visual Studio Webserver ?
I m not sure because it works with FireFox.

Any help ?
"George Ter-Saakov"
Nothing obvious wrong with your code.
Make sure that the service.GetDocument returns a pdf. Simply save it into
file on hard drive and try to open.
Most likely it's not valid pdf

George.

Stan SR said:
Hi,
I call a web service method that returns an array of bytes.
This array is a PDF document and I would like to display this array as
pdf document within the browser.

So I wrote this code, but I don't get my pdf

byte[] myPDF = myWebService.GetDocument(pdfID);
Response.Clear();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition",
"inline;filename=mydoc.pdf");
Response.BinaryWrite(myPDF);
Response.End();

Any help ?

Stan
 
D

David R. Longnecker

Try placing Response.End() in a finally block. Using ActiveReports, I had
to make sure to use the Finally or it was "ending" before Internet Explorer
was finished picking up everything...

try
{
byte[] myPDF = myWebService.GetDocument(pdfID);
Response.Clear();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition",
"inline;filename=mydoc.pdf");
Response.BinaryWrite(myPDF);
Response.End();

}
catch (NullReferenceException ex)
{
throw ex;
}
finally
{
Response.End();
}
 
Ad

Advertisements

G

George Ter-Saakov

Try to add Content-Length: to the header
Response.AddHeader("Content-Length", myPDF.Length.ToString());

I recall I had a problem with binary files without that header info.


George


Stan SR said:
Hi George,

I ve saved the byte array to file and it's a real pdf.

here's the code I use
FileStream newFile = new FileStream(myPath, FileMode.Create);
newFile.Write(myPDF, 0, myPDF.Length);
newFile.Close();

I think I miss something in my previous script.

So if you have another Idea, it's welcome.

Stan

"George Ter-Saakov"
Nothing obvious wrong with your code.
Make sure that the service.GetDocument returns a pdf. Simply save it into
file on hard drive and try to open.
Most likely it's not valid pdf

George.

Stan SR said:
Hi,
I call a web service method that returns an array of bytes.
This array is a PDF document and I would like to display this array as
pdf document within the browser.

So I wrote this code, but I don't get my pdf

byte[] myPDF = myWebService.GetDocument(pdfID);
Response.Clear();
Response.ContentType = "Application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition",
"inline;filename=mydoc.pdf");
Response.BinaryWrite(myPDF);
Response.End();

Any help ?

Stan
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top