tags:

views:

447

answers:

2

Hi

I am want to take advantage of the web optimization for pdfs by allowing users to download them a page at a time.

The pdfs are configured for fast web view. I am serving the pdfs from sql server 2008. The c# .net 3.5 web app untilises linq to SQL to load the files into a binary array from the database. The file is opended in PDF reader plugin on the client in IE.

Any help or a shove in the right direction would be greatly appreciated.

Thanks

A: 

If you simply want to send a PDF to the client, create an aspx file with this code:

protected void Page_Load(object sender, EventArgs e)
{
  byte[] pdfdata = GetMyPdfDataSomehow();

  Response.Clear();
  Response.ContentType = "application/pdf";
  Response.BinaryWrite(pdfdata);

  if (NoCaching)
  {
    Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
  }
  else
  {
    Response.Cache.SetExpires(DateTime.Now.AddDays(7));
    Response.Cache.SetCacheability(HttpCacheability.Public);
    Response.Cache.SetValidUntilExpires(true);
  }
  Response.End();
}

However, if you want to know how to split the PDF file up page by page, you'll need some PDF library for that.

Chris
Thanks Chris this is similar to what I am currently doing I am really looking for some help with byte serving perhaps using a httpHandler.
Mick
A: 

Returning an entire PDF is simply a case of returning the binary on the http response, as per Chris's reply.

For the page-at-a-time handling, I would suggest using something like Fiddler2 or Wireshark to look at the http traffic. There may be some custom http headers on the requests, a bit like the "resume download" support via the byte range headers.

You would need to observe a working page-by-page example, and look at what both client and server send.

Marc Gravell
Thanks Marc I will give this a go.
Mick