Download pdf from my servlet

Hi,
I'm want to downlaod a servlet located on the server from my servlet.
please help me.
thanks

That simply gets the File as a byte[]. I use the following method
public static byte[] getBytesFromFile(File file) throws IOException {
          InputStream is = new FileInputStream(file);
          long length = file.length();
          // You cannot create an array using a long type.
          // It needs to be an int type.
          // Before converting to an int type, check
          // to ensure that file is not larger than Integer.MAX_VALUE.
          if (length > Integer.MAX_VALUE) {
               // File is too large
          // Create the byte array to hold the data
          byte[] bytes = new byte[(int) length];
          // Read in the bytes
          int offset = 0;
          int numRead = 0;
          while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
               offset += numRead;
          // Ensure all the bytes have been read in
          if (offset < bytes.length) {
               throw new IOException("Could not completely read file " + file.getName());
          // Close the input stream and return bytes
          is.close();
          return bytes;
     }

Similar Messages

  • How to download pdf from application server

    hi all,
    anybody has code to download pdf from application server to presentation server.
    right now i get the pdf file on to the desktop but i get error on opening.
    gui_download gives error if i use xstring.
    pl advice.
    thanks.
    sap fan.

    Hi,
    use the below code to download file from app server to presentation server
    PARAMETERS: S_file TYPE SAPB-SAPPFAD
    default '\folder1\abc,pdf'.
    PARAMETERS: t_lfile TYPE SAPB-SAPPFAD
    default 'c:\temp\xyx.pdf'.
    START-OF-SELECTION.
      CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT'
        EXPORTING
          path             = source_file
         TARGETPATH        = target_lfile
    EXCEPTIONS
       ERROR_FILE       = 1
       OTHERS           = 2
      IF sy-subrc eq  0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

  • I have Adobe Acrobat version 11.0.0 installed with Adobe CC.  I cannot download PDFs from the internet (in this case from PubMed National Library of Medicine).  If I try to do this  I get a popup message saying that "ADOBE ACROBAT NPAPI PLUG-IN, VERSION 1

    I have Adobe Acrobat version 11.0.0 installed with Adobe CC.  I cannot download PDFs from the internet (in this case from PubMed National Library of Medicine).  If I try to do this  I get a popup message saying that "ADOBE ACROBAT NPAPI PLUG-IN, VERSION 11.0.0 NEEDS YOUR PERMISSION TO RUN.  I DON'T KNOW HOW TO GIVE THIS PERMISSION OR WHAT TO DO.  CAN YOU PLEASE HELP?

    What buttons do you get to click on with this message? What browser are you using (e.g. Safari, Chrome, Internet Explorer...)

  • %pdf error in downloading pdf from Function module

    Hi,
    I am trying to download pdf from a LinkToaction UI element.
    I recieve %pdf" error when trying to download using below code. from backend perspective ABAPer said they are able to download PDF from ABAP program. Lokks like I am doing some mistake somewhere in below code.
    From the backend, pdf is coming in  a table in the form of SOLI-Text Line (TLine - SO_TEXT255)
    In webdynpro I am tried to take each line from that table and attched to a IWDResource as below.
    Please correct me if anything wrong here to get out of %pdf" error.
    IModel_Pdf_FileNode Model = wdContext.nodeModel_Pdf_File();
    IPDFElement pdf = wdContext.nodePDF().currentPDFElement();
    if (Model != null && Model.size() > 0)
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    try {
       for (int i = 0; i < Model.size(); i++){
          IModel_Pdf_FileElement Element =
                                                 Model.getModel_Pdf_FileElementAt(i);
         baos.write(Element.getLine().getBytes());
        IWDResource resource =WDResourceFactory.createCachedResource(
              baos.toByteArray(),
              "Test",
              WDWebResourceType.PDF);
        pdf.setBinaryResource(resource);
    Thanks
    Praveen

    Thanks for the sample. I use version NWDS7.0 and I don't find IContent type in my NWDS after re-organizing import statements.
    currently I use below code to get the PDF on click of LinkToaction UI element (After I set the pdf from backend above part of the code).
    {code
    IWDResource pdfResource = wdContext.nodePDF().currentPDFElement().getBinaryResource();
                   String pdfURL = pdfResource.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal());
              IWDWindow window =
              wdComponentAPI.getWindowManager()
              .createNonModalExternalWindow(pdfURL , "Test");
              window.show();
    {code}
    Currently above code giving %pdf" error when clicking LTU UI elemnt.
    Please suggest How I need to adjust your sample in my case.
    Thanks
    Praveen

  • I am unable to download pdfs from the web into my downloads folder

    Since i did the new update on firefox (8-14?) I am unable to download pdfs from a website into my downloads folder. When I choose to view a pdf in a window, I get a blank window with the urlxxxx. pdf in the top...but a blank window. This is a change in the functioning of my browser since the update... i have changed nothing on preferences or anything
    I am able to download pdf's into my downloads folder from safari, but really don't want to change all my bookmarks etc from firefox to start using safari. Am on a Mac OS 10.7.4
    thanks

    Hi Matt_G
    nope...didn't help. When I typed in pdf into the search bar, nothing came into the content window.
    thanks for any further assistance you can provide...really hate to have to use safari instead of firefox
    trish.painter

  • How do I keep downloaded pdfs from automatically opening in Acrobat on a MAC?

    I am downloading pdfs from FETCH on a MAC and they are automatically opening in Acrobat. How do I download and not have them open? There are literally hundreds of them.
    Thanks,

    Hi Brian,
    The Safari web browser contains a feature, enabled by default, which causes all files considered "safe" to be automatically opened once they have finished downloading. Safari considers the following file types to be safe:
    - Pictures
    - Movies
    - Sounds
    - PDF files
    -Text documents
    - Disc images (.dmg files)
    - Other archive types
    Although it can be convenient while enabled, this can be a very dangerous feature when it comes to your security. It can be disabled in a few easy steps.
    > Open your Safari web browser by clicking on the Safari icon in the dock.
    > Click on Safari in your Safari menu, located at the top of your screen. When the drop-down menu appears, choose Preferences.
    > Select the General tab from the Preferences window, which is now overlaying your browser window.
    You will now see a check box labeled "Open 'safe' files after downloading", located near the middle of the Preferences window. If this box is checked, click on the check mark and verify that it is no longer active.
    Click on the red circle/x located in the top left hand corner of the Preferences window to complete the process. You will now be returned to your main browser window.
    Hope this helps.
    Regards,
    Rave

  • I cannot download pdfs from FireFox on a Mac

    Up until just a few days ago I could download pdfs from websites through Firefox. As far as I know I did not upgrade or change anything. I followed all of the tutorials, the Troubleshooting Information tips, deleted profile.ind files, added the PDF viewer 0.6.39 and that does not work.
    I am on a Mac, OS 10.6.8
    Firefox 17

    You can disable the Adobe Reader plugin in Firefox (Tools > Add-ons > Plugins) and use the external Adobe Reader application or Preview application instead.
    *Firefox > Preferences > Applications > Adobe PDF document : Use Adobe Reader
    PDF files may also be found under another entry like Portable document.
    *https://support.mozilla.org/kb/change-firefox-behavior-when-open-file

  • On new MBP, wont download pdfs from secure sites, like banks. "unknown error" reported. Using Acrobat.

    Recently started using a Macbook Pro, formerly ran Firefox on a PC. Installed Acrobat and it works fine, and will download pdfs from internet fine, UNLESS it is from certain sites, that as near as I can tell have in common that I needed a password to get in (eg, Bank, insurance company). At this sites I can't download a pdf file, and am told that an "unknown error" occurred and I should try saving directly link to the disk. But this doesn't work either, it just wants to save a .cgi file, not the pdf. Any suggestions greatly appreciated.

    Did you try to save that cgi file and give it a .pdf file extension?

  • How do I download pdfs from link without opening first in Safari?

    I am running OS 10.7.2 and browse with Safari 5.1.2.  I download PDF files routinely for my work.  In previous versions of Safari (with OS 10.5.x), clicking a link to download a PDF led to the PDF immediately downloading and then opening in Adobe Acrobat Pro.  Since upgrading to current system and Safari, I can no longer do that.  Clicking on PDF links opens in Safari, and then I have to find and click Safari's download button, and then I have to go to the downloads folder and click to open the document.  Does anyone know how to bypass this opening feature and get Safari to just download and then get the pdf to instantly open like it used to?  I am finding myself moving to Firefox, which I don't like as well and don't know as well, because it doesn't interfere with PDF docs. 
    Any solutions out there?

    Thanks for the suggestion, but those are the settings I'm already using.  Unfortunately, the various websites I visit don't respond uniformly to control-click, and choosing to download a file from that menu often just downloads an HTML of the page rather than the pdf doc itself.  I find shift-option-click works more often than other key combos, but I still have to then go to the downloads folder and manually open the file. 
    You may be right about Firefox being my only option.  Thanks for the suggestions.

  • Can't download .pdfs from web - Standard

    Have standard 7.0 and it worked fine for years but recently it will not download pdf files from the web.  Locks up IE and Mozilla when I try.  Opens pdf's fine from local drive just a problem with the web downloads.  Removed and reloaded Acrobat 7.0.  No change.  Downloaded ActiveX control - no change.  Any ideas out there????

    What version of Acrobat 7. Hopefully not 7.0.0 since there were many bug fixes. What version of Windows? What service packs? What version of MSIE? What version of Mozilla? Were there any recent Windows updates that you installed prior to things going wonky? Also, if running Windows XP, what firewall software and what virus protection?

  • Downloading PDF from internet

    I would like to download a PDF file from the Internet
    "sometimes"
    I get a message in Adobe Reader as follows
    Adobe Reader could not open ____because it is either not a
    supported file type or because the file has been damaged (for example it was
    sent as an email attachment and wasn't correctly decoded)
    I have downloaded it to my Desktop and tried opening it from the website
    I have Adobe Reader 9.3
    this last time someone from the website sent the same PDF file to me in an e-mail and it opened peoperly

    This is the site
    http://www.hanp.net/volumes/current
    there is a highlighted area that indicates
    download PDF
    I had contacted someone associated with the website above and he indicated he had no trouble opening the PDF file on the site.  He sent it to me in an email attachment, and I was able to open it in Adobe without a problem
    Thank you for looking into it for me
    Lynn

  • Firefox won't download pdfs from some sites, e.g. Wells, but others too. Bank said use IE - that works. Help

    Only seems to happen on financial sites. I use xp sp3 on lenovo thinkpad t61.
    E.g., to download a pdf statment from Wells, I open the statment and then try to save it, but no option to save it. Called bank, they say to use Internet Explorer - that works. With IE I can right click on the file and then use "Save as" or I can open the file and "Save a copy". Can't do eaither of these w Firefox 19.0.2. I don't think that this used to be a problem. This is not a problem with all pdf files from all sites.

    Sorry you are having problems with Firefox.
    ===CARE this is a public forum ===
    Do not post sensitive or confidential information.
    Firefox has a new built in pdf viewer, and whilst this has been released it is still undergoing development, with bug fixes due and further features likely to be added.
    I do not notice any named pdf reading plugin in your system details, but you may need to consider using a third party pdf reader for now:
    *When you open the pdf s do you see any Firefox warning information bar at the top edge of the document, or any warning with in the pdf itself about incompatibility and using another viewer ? <br/> see also
    **[[Use the Adobe Reader plugin to view or download PDF files]]
    **[[How to disable the built-in PDF viewer and use another viewer]]
    There is a possibility sites or pdfs may be faulty, and that advice given may not be the best. Please give links to any faqs etc publicly posted by banks relating to pdf use, and the web address of the banks are having problems with.
    One of the problems with the Firefox viewer is fixed in the firefox Beta channel and possibly in an add-on you could consider trying those.
    * http://www.mozilla.org/en-US/firefox/channel/#beta/beta-desktop <br/>if you do upgrade note there is no need to uninstall Firefox, and you should not use any option that removes personal information, or you will destroy bookmarks and passwords.
    * https://addons.mozilla.org/en-US/firefox/addon/pdfjs/

  • Unable to download pdf from iphone to pc

    I have synced my iPhone 6 Plus (iOS 8.2) to iTunes. But for some reason the PDF's that I have in iBooks on my phone are grayed out in iTunes when I look under Books in the "On My Device" section.  I am running the current version of iTunes (version 12.1.1.4) on a Windows 8 machine.  I am also having issues with getting the PDF's that are in iBooks on my phone to sync over to iBooks on my new iPad Air 2 (iOS 8.2).
    I have stepped through everything that I can seem to find to make sure that I am doing this correctly, but they nothing seems to be working.
    Any assistance is greatly appreciated.

    Hi ThreeOs
    I am still not able to download the music from my registered PC. Please note that when I connect my phone to a non-registered PC I am able to download music. 
    I am sure that my issue will not be resolved Nokia support say that there is no issue from there side and as per nokia support instructions I have re-registered my PC and still the same issue.  I have sent the attachment to the mail you mentioned. 
    Even if the issue is resolved now its too late as my subcription is ending on 25-Sep-2011 and I am 100% sure that my subscription will not be extended. I have been not able to download music from my registered PC from May onwards that means I should be compensated for 4 months. Can you please help me in this regard. 

  • Cant download PDFs from Web pages  Adobe 9 reader,

    Hi there , i have Adobe Reader 9 installed, which reads PDF files Ok from my hard drive and when saved from
    Emails. but when i try and save a PDF from a web page it try's to open Acrobat and asks me to login. I have removed  Acrobat, but still cant download a PDF, Has anybody experienced this and have a resolution. Cheers 

    If you removed Acrobat, you must re-install Reader.

  • Downloading pdf from emails

    Hi just got the z3 compact last week. And I am find it hard to download pdf attachments from email. I can download them up until 2 weeks ago. Any further back on the email feed and it comes up with a message saying can't download attachment. Doesnt give me anyone info on why. Also having trouble downloading them when I'm using google read emails to. Not sure if it's related.
    Any ideas or advice would be great
    Thanks

    Do you have an antivirus app? which email app are you using?
    "I'd rather be hated for who I am, than loved for who I am not." Kurt Cobain (1967-1994)

Maybe you are looking for