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

后端 未结 16 1732
难免孤独
难免孤独 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:47

    If you use asp.net, you can control pdf filename through page (url) file name. As other users wrote, Acrobat is a bit s... when it choose the pdf file name when you press "save" button: it takes the page name, removes the extension and add ".pdf". So /foo/bar/GetMyPdf.aspx gives GetMyPdf.pdf.

    The only solution I found is to manage "dynamic" page names through an asp.net handler:

    • create a class that implements IHttpHandler
    • map an handler in web.config bounded to the class

    Mapping1: all pages have a common radix (MyDocument_):

      
    
    

    Mapping2: completely free file name (need a folder in path):

    
    

    Some tips here (the pdf is dynamically created using iTextSharp):
    http://fhtino.blogspot.com/2006/11/how-to-show-or-download-pdf-file-from.html

提交回复
热议问题