I am loading a PDF into the PDFViewer from a stream but would like to set the filename of the file when downloaded by the user from the browser. By default it seems to be “document.pdf”. I’ve tried a couple of things unsuccessfully:
PDF.js v2.0.493 (build: c5c06bf5)
Message: PDFDocument: stream must have data
2. So I decided to change to using a Postback url. I removed the PDF stream and set the PDFSource = this.GetCallbackURL(); This also causes the same error as above in the PDFViewer control and never calls my ProcessRequest method. Is this because the control is calling its original handler rather than mine?
Any suggestion as to how I can set the filename?
TIA
Nic
So setting filename in the handler didn’t work, but I’ve since discovered that there is a method on pdf.js that can set the filename:
PDFViewerApplication.setTitleUsingUrl() which takes a URL and then figures out the filename from it.
My problem now is that I cannot figure out how to access the PDFViewerApplication object. I’ve tried to do this from OnWebRender and from other event using Eval(string.Format(“PDFViewerApplication.setTitleUsingUrl(‘{0}’);”, Application.Url + fileName)); but I always get “PDFViewerApplication is undefined”
Unfortunately I’m not a js programmer so my understanding is very limited. Can anyone point me in the right direction?
TIA
Nic
Thanks both,
But still slightly confused. To use Application.Download I need to get the PDFViewer to call my handler. I’ve set:
pdfViewer1.PdfSource = this.GetPostBackURL();
but when the viewer is rendered it displays the same error as in my original post:
PDF.js v2.0.493 (build: c5c06bf5)
Message: PDFDocument: stream must have data
and my ProcessRequest(HttpContext context) handler is never called.
I’ve built and attached a simple example. You will see that the NotImplimentedException in the handler is never reached.
Hi Nic,
the Mozilla PDF viewer and probably most other PDF viewser don´t seem to care about the attachment name header.
They use the PDF title in the PDF when it´s set. I´m afraid we can´t change that.
Best regards
Frank
Hi Nic,
To set the file name use
Snippet
Application.Download("Wisej-Datasheet-V2.2.pdf", "MyFileName.PDF"); Using a Stream, use Snippet
Application.Download(stream, "MyFileName.PDF");
Please login first to submit.