-1

EDIT: modified Title to be more specific

I've created a generic handler in VS2012 using their basic template as a starting point and modified it to grab a pdf from our sqlserver. The primary code block is this:

buffer = DirectCast(rsp.ScalarValue, Byte())
context.Response.ContentType = "application/pdf"
context.Response.OutputStream.Write(buffer, 0, buffer.Length)
context.Response.Flush()

And this works fine to display the BLOB as a pdf using whichever pdf plugin is installed on any given browser.

My Question: How can I modify the handler to write Adobe PDF specific parameters to the output? Specifically I'm trying to set width='fit' such that the output PDF stream will autofit the document to the width of the popup window.

NB: Writing the BLOB to a pdf file and serving the PDF is not an option.

Thanks in advance for any advice or links

fnostro
  • 4,531
  • 1
  • 15
  • 23

1 Answers1

0

I don't think there's anything that you can do in your handler. According to that document PDF viewers can examine the URL that was used to open the PDF but there are no HTTP headers that you can set. So you'll need to modify the thing that links to your handler to have those parameters in place. Alternatively, you could build a pre-handler that HTTP redirects to your new handler with those parameters in place.

Also, that document was written in 2007 and was intended for Adobe Acrobat and Adobe Reader. Most modern browsers ship with their own internal PDF viewer these days so unless you are only targeting Adobe your efforts might be wasted.

Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • I have tried passing the parameters via the URL for the handler such that the ref looks like this `~/PdfHandler.ashx?id=xxx&width=fit` and various incarnations with and without quotes, but the handler isn't receiving a document but accessing a database and subsequently writing a byte array. So there doesn't seem to be an location to place parameters. However the handler generates an `` object for the pdf that I'm wondering if I can override. – fnostro Jan 17 '14 at 21:44
  • According to that document, the URL parameters should start with a hash (#), not a question mark for starters. And just to confirm, you're testing with Adobe Acrobat or Adobe Reader, right? I just tested Chrome's PDF viewer and it appears to be working with at least page numbers, too. You say that the handler generates both an embed tag as well as the PDF bytes, that's confusing to me. Do you mean that you are embedding the PDF bytes directly within the embed tag? – Chris Haas Jan 17 '14 at 21:55
  • The code in my OP is it. the only other code block retrieves the byte array. I'm not writing any specific html so on the one hand the handler is writing it, but not because I wrote any code. If I had to guess, it's automatically injected by IIS based on the content type when it renders the page. – fnostro Jan 17 '14 at 22:05