How to save dynamically generated PDF files with proper file name?

Hi,
I need to save the pdf file with default name which generated by
dinamically.
this is the code i am trying to save by default
protected void processRequest (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
OutputStream bos = response.getOutputStream ();
// this returns pdf byte array
byte  ios[]  = callReport ( reportId_param , fullyQualifiedReportClassName , paramHashMap ) ;
response.setContentType ("application/pdf");
// reportId_param and reportName_param supplied from some where
String docName =  reportId_param + "_" + reportName_param ;
if( fromDate_req != null && toDate_req != null )
                String dateStr = fromDate_req + "_to_" + toDate_req ;
                dateStr = dateStr.replaceAll ( "/" , "_" ) ;
                docName = docName + "_" + dateStr ;
// here docName would be like "RP_COM_COLL_01_Message_Details_03_09_2008_to_03_09_2008"
response.setHeader ("Content-Disposition","inline; filename=" + docName ) ;
bos.write (ios);
bos.flush ();
}the above code produces pdf in browser when calling this URL
http://localhost:8080/DAD01TN0801027/RWReportServlet
In browser we can save this PDF by using two ways
1. File -> Save As
2. By using Save Icon within the PDF toolBar
both the actions uses the file name "RWReportServlet" as default instead of using docName
Can any one help me please
Regards
Sakthivel.

That said, your code is not very efficient. You're storing the complete PDF file in memory. What if the PDF file is fairly large? And what if multiple users download multiple large PDF files simultaneously? Your server would run out of memory. Rather use InputStream instead of a raw byte[]. And preferably buffer it.
You should also be setting the content-length header by the way.

Similar Messages

  • How to "save as" a pdf form with another name? So not over the same document, is it possible?

    I have made a form in acrobat pro and i want use this form on the Ipad. But on the Ipad with acrobat reader save the document automatically and i want save all the versions and not finally one document..Can somebody tell me this is possible or not?!

    It sounds like you want to duplicate a PDF document. View the document list, and click Edit. Select the document to be duplicated. Select the Duplicate/Move icon (on an iPhone the icon shows two documents). Select Duplicate.

  • How to save book in pdf tiff 300 dpi? with these steps file -print book- PDF- save PDF to folder as TIFF 300 dpi does not work

    how to save book in pdf tiff 300 dpi?
    with these steps file -print book- PDF- save PDF to folder as TIFF 300 dpi does not work

    Hi pissedadobeuser,
    Does this issue occur with any particular web page?
    Are you able to print the webpage to 'Adobe PDF' to convert it to pdf.
    Which Browser version, OS version and Acrobat version are you using?
    Regards,
    Rave

  • How do i convert a pdf into a word file, i have tried doing save as?

    how do i convert a pdf into a word file, i have tried doing save as?

    Hi Jack,
    What version of Acrobat are you using?
    You might need to go to File> Save As Other> Microsoft Word or choose 'Adobe PDF printer' from the File menu.
    Is save as option not functioning correctly? Do you get any specific error?
    Please let me know.
    Regards,
    Anubha

  • Issue with emailing dynamically generated PDF (InteractiveForm UI element)

    Hi Experts ,
    I have a requirement according to which i need to generate PDF dynamically using webdynpro java and email the dynamically generated PDF.
    I am facing issue while emailing the dynamically genarated pdf.
    It gives me an exception :
    nested exception is: javax.mail.MessagingException: IOException while sending message;  nested exception is: java.io.IOException: no data
    This is because its unable to get the binary data (byte array) of the dynamically generated PDF which is required to send mail.
    Could some one suggest me how to fetch the binary data of the dynamically generated PDF.
    For dynamic PDF generation i am using dynamic generation of UI element   InteractiveForm UI Element 
    In case of static PDF (i.e. the PDF genarated by inserting the InteractiveFrom Ui element on the view using the insert child option) we do set the pdf source property of Interactive Form UI element to a context variable attribute of type binary but  my problem is ,how to set the PDF source of a dynamically generated Interactive form UI element to a context variable attribute of type binary ..
    Any help would be highly appreciated.
    Regards ,
    Navya

    Hi Frank ,
    the code to generate PDF dynamically is written in the WdDoModifyView section of the view as the PDF need to be generated dynamically., i.e. by adding InteractiveForm UI elements at  runtime.
    I tried the code suggested by you  but i gave mean exception.
    errorjava.io.FileNotFoundException:
    (The system cannot find the path specified)
    Kindly let me know where i am going wrong .
    Below is the code that i  had written in a separate method m_mail().
    This would take as input the name of the dynamically generated data node and is called from the wdDoModifyView section of the view
    public void m_mail( java.lang.String p_dynamicnodeName )
                   ByteArrayOutputStream templateSourceOutputStream = new ByteArrayOutputStream();
              //        This would need to have the Templatefile in the Mimes-Directory of the Webdynpro-Component
                   String templateUrl = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), "AdobeView1_InteractiveForm.xdp");
                   InputStream templateSourceInputStream = new FileInputStream(templateUrl);
                   IOUtil.write(templateSourceInputStream, templateSourceOutputStream);
                   IWDPDFDocumentCreationContext pdfContext = WDPDFDocumentFactory.getDocumentHandler().getDocumentCreationContext();
                   pdfContext.setData(WDInteractiveFormHelper.getContextDataAsStream(wdContext
                   .nodeCtx_vn_dynmcnd()
                   .getChildNode(p_dynamicnodeName, IWDNode.NO_SELECTION)));
                   pdfContext.setTemplate(templateSourceOutputStream);
                   pdfContext.setInteractive(false);
                   IWDPDFDocument pdf = pdfContext.execute();
                   if (pdf != null) {
                    pdfArray = pdf.getPDF();
    Kindly let me know where am i going wrong.
    Regards ,
    Navya

  • How to save movieclip to pdf in AS3.0?

    Flash actionscript3.0
    How to save  movieclip to pdf ?
    Thanks in Advance.

    Thanks in Advance.
    one more question
    how to convert to flash file to avi file, with highquality.

  • How do I make Applescript to compress 2 filez with the same name?

    Hello guys and thank you for reading this!
    I don't know a lot about programming, but i believe applescript can save my life. What I need is.
    Detecting 2 files with the same name, but differnt extension. (song 1.jpg, song 1.mp3)
    Compressing those 2 files into a single .zip (In the end I would have song 1.jpg, song 1.mp3 and song 1.zip
    And that's it! I know its pretty simple, and I've seen the "Create Archive" in automator, but I don't really know how to tell him which files to Compress.
    Thanks again!

    Hi,
    Try this script :
    set sourceFolder to choose folder
    tell application "System Events"
          {name, name extension} of (files of sourceFolder whose name extension is not "zip")
          my compress2FilesSameName(the result, sourceFolder as string)
          repeat with i in (get folders of sourceFolder) --check in subfolders
                {name, name extension} of (files of i whose name extension is not "zip")
                my compress2FilesSameName(the result, path of i)
          end repeat
    end tell
    on compress2FilesSameName(tList, tFolder)
          set tnames to item 1 of tList
          set tExtensions to item 2 of tList
          set tc to count tnames
          set j to 1
          repeat while j < tc
                tell (item j of tExtensions) to if it is not missing value or it is not "" then
                      set n1 to (count) + 2
                else
                      set n1 to 1
                end if
                tell (item (j + 1) of tExtensions) to if it is not missing value or it is not "" then
                      set n2 to (count) + 2
                else
                      set n2 to 1
                end if
                set name1 to item j of tnames
                set name2 to item (j + 1) of tnames
                if (text 1 thru -n1 of name1) = (text 1 thru -n2 of name2) then -- same name
                      set tFile1 to quoted form of POSIX path of (tFolder & name1)
                      set tFile2 to quoted form of POSIX path of (tFolder & name2)
                      set zipFile to quoted form of POSIX path of (tFolder & (text 1 thru -n1 of name1) & ".zip")
                      do shell script "/usr/bin/zip -j  " & zipFile & " " & tFile1 & " " & tFile2
                      set j to j + 2
                else
                      set j to j + 1
                end if
          end repeat
    end compress2FilesSameName
    if an archive already exists with the same name (in the parent folder of the files to compress) , the ZIP command overwrite this ".zip" file.
    Example  with "song 1.jpg", "song 1.mp3" and "song 1.zip" :
    If "song 1.zip" doesn't exist, the ZIP command create the "song 1.zip" file.
    If "song 1.zip" exist, the ZIP command overwrite the "song 1.zip" file (it will not create a new archive).

  • Upload new pdf file with the same name

    We are trying to upload a pdf file with a specific name (i.e
    file.pdf) that has links to it on many pages of a website. We need
    the pdf file to keep the same name but when we try to upload it,
    Contribute is being 'smart' and changing the name so as to not
    overwrite the file on the server. But we WANT to overwrite the file
    on the server. Any ideas on how we can achieve this in Contribute?
    Thanks so much (in advance) for your help!

    Actually, we have the same problem and I believe the answer
    lies in the abilities that your role has assigned to it. The
    solution that ThinkInk gave works *if you are allowed to delete
    files*. If your role doesn't have that permission, then it will
    just upload another copy of the file and rename it.
    It's rather irritating that there isn't more control over
    this...our server is littered with *thousands and thousands* of
    duplicate files that originate from this situation.
    If your administrator wants you to be able to delete files as
    well, then you could get him/her to give you that permission, and I
    believe this will allow you to overwrite the file by using the
    "Publish file from my computer" option described above.

  • Sample JAVA program: generate PDF from xsf:fo File

    Hi everybody,
    we already have an xsl that converts an xml into an xsl:fo file.
    I am now looking for a very simple sample that converts this xsl:fo into a PDF.
    It would be profitable if the java-sample would read the xsl:fo file as an input-stream.
    Thanks
    Regards
    Mario

    Hi,
    as I am not a JAVA expert.
    Do you know how to reuse the generated PDF in the java sample not as a fileOutputStream.
    I need to attach the generated PDF to a mail-xml-document.
    (I know haw to generate a mail structure in java-mappping)
    What kind of object is the generated PDF within the java?
    Any ideas
    Regards Mario

  • How to save or export pdf project?

    Can someone show me how to save or export PDF file to other files?  My Acrobat greyed out everything besides "save as".  I cannot save to other format or export to other format. Please help

    It might be that this is a protected PDF, or a type of PDF that cannot be converted (e.g. certain forms). Look under File > Properties -- Security.

  • How to delete the file with space in name

    Hi
    I want to delete the file "test ex.txt" file.
    i run the following command in command prompt.i can delete the file successfully.
    /bin/rm -f /mnt/"test ex.txt"
    I want to run the command from java.So i am using the following code
    String cmd = "/bin/rm -f /mnt/\"test ex.txt\"";
         Runtime rt = Runtime.getRuntime();
    process = rt.exec(cmd);
    The file was not deleted.
    How to delete the file with space in name?
    Help me

    Use the form of exec that takes an array of command + args.
    arr[0] = "/bin/rm"
    arr[1] = "-f"
    arr[2] = "/home/me/some directory with spaces";Or use ProcessBuilder, which is the preferred replacement for Runtime.exec, and which Runtime.exec calls.

  • FTP how to pass dynamic filename/directory location - reading a file in 11g

    Hi All,
    We r using FTP adapter(SOA 11g) for getting files in remote server, May i know how to pass dynamic filename and directory where the file exists for reading in server.
    Thanks,
    Rak

    Hey according to my understanding, the Dynamic partner links are set only for the Outbound invocations only. Is my understanding right? if so, how do we create the dynamic partnerlinks for the ftp get kind of stuff...??
    Thanks in advance

  • How do i convert a .pdf to a WORD file?

    How do I convert a .pdf to a WORD file?

    Hi pdfyes,
    Welcome!
    Try going here:
    ExportPDF getting started guide: http://forums.adobe.com/docs/DOC-2412
    Kindest regards,
    Stacy

  • How to save an image as a PICT resource file?

    Can someone tell me how to save an image as a PICT resource file? I'd like to make ikons in Photoshop and save them in this format, but I 'm not finding any leads. Thanks!

    If you have Resorcerer from "ancient times" it of course can handle resource forks since that's was it's goal in life.
    There are lots of icon creation apps these days.  Do a search for "icon" on macupdate.com to see what's available.  For example that search finds:
    iconXprit
    Icon Builder X

  • How to open a file with the same name?

    Hi, now I practicing making web pages where I put sample codes in one directory and I copy them to edit.
    The probrem is, I couldn't open one file while I'm opening another file with the same name.
    Is it possible to open  a file with the same name in Dreamweaver?

    That could be a very error prone practice.
    May I suggest you take advantage of DW "Snippets" feature instead.
    Simply save any blocks of code you will reuse regularly as snippets,
    and give each one a descriptive name you like.
    Then you can simply place your cursor in code view where you wish the code,
    and click insert on the selected item from the snippet panel.

Maybe you are looking for