“name” web pdf for better default save filename in Acrobat?

后端 未结 16 1722
难免孤独
难免孤独 2020-12-14 00:09

My app generates PDFs for user consumption. The \"Content-Disposition\" http header is set as mentioned here. This is set to \"inline; filename=foo.pdf\", which should be

相关标签:
16条回答
  • 2020-12-14 00:55

    You could always have two links. One that opens the document inside the browser, and another to download it (using an incorrect content type). This is what Gmail does.

    0 讨论(0)
  • 2020-12-14 00:57

    I believe this has already been mentioned in one flavor or another but I'll try and state it in my own words.

    Rather than this:

    /bar/sessions/958d8a22-0/views/1493881172/export?format=application/pdf&no-attachment=true
    

    I use this:

    /bar/sessions/958d8a22-0/views/1493881172/NameThatIWantPDFToBe.pdf?GeneratePDF=1
    

    Rather than having "export" process the request, when a request comes in, I look in the URL for GeneratePDF=1. If found, I run whatever code was running in "export" rather than allowing my system to attempt to search and serve a PDF in the location /bar/sessions/958d8a22-0/views/1493881172/NameThatIWantPDFToBe.pdf. If GeneratePDF is not found in the URL, I simply transmit the file requested. (note that I can't simply redirect to the file requested - or else I'd end up in an endless loop)

    0 讨论(0)
  • 2020-12-14 00:59

    Try this, if your executable is "get.cgi"

    http://server,org/get.cgi/filename.pdf?file=filename.pdf

    Yes, it's completely insane. There is no file called "filename.pdf" on the server, there is directory at all under the executable get.cgi.

    But it seems to work. The server ignores the filename.pdf and the pdf reader ignores the "get.cgi"

    Dan

    0 讨论(0)
  • 2020-12-14 01:01

    Try placing the file name at the end of the URL, before any other parameters. This worked for me. http://www.setasign.de/support/tips-and-tricks/filename-in-browser-plugin/

    0 讨论(0)
  • 2020-12-14 01:02

    Instead of attachment you can try inline:

    Response.AddHeader("content-disposition", "inline;filename=MyFile.pdf");
    

    I used inline in a previous web application that generated Crystal Reports output into PDF and sent that in browser to the user.

    0 讨论(0)
  • 2020-12-14 01:03

    File download dialog (PDF) with save and open option

    Points To Remember:

    1. Return Stream with correct array size from service
    2. Read the byte arrary from stream with correct byte length on the basis of stream length.
    3. set correct contenttype

    Here is the code for read stream and open the File download dialog for PDF file

    private void DownloadSharePointDocument()
    {
        Uri uriAddress = new Uri("http://hyddlf5187:900/SharePointDownloadService/FulfillmentDownload.svc/GetDocumentByID/1/drmfree/");
        HttpWebRequest req = WebRequest.Create(uriAddress) as HttpWebRequest;
        // Get response   
        using (HttpWebResponse httpWebResponse = req.GetResponse() as HttpWebResponse)
        {
            Stream stream = httpWebResponse.GetResponseStream();
            int byteCount = Convert.ToInt32(httpWebResponse.ContentLength);
            byte[] Buffer1 = new byte[byteCount];
            using (BinaryReader reader = new BinaryReader(stream))
            {
                Buffer1 = reader.ReadBytes(byteCount);
            }
            Response.Clear();
            Response.ClearHeaders();
            // set the content type to PDF 
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment;filename=Filename.pdf");
            Response.Buffer = true;
            Response.BinaryWrite(Buffer1);
            Response.Flush();
           // Response.End();
        }
    }
    
    0 讨论(0)
提交回复
热议问题