Download PDF using httpURLConnection

Can anyone help me on downloading PDF (or any file other than HTML) using httpURLConnection class. Reading the input stream line by line from the site using Strings causes a corrupt file download.
Please help !!! Thanks.

you cannot read it line by line. try reading it byte by byte
     URL url = new URL("http://yourserver.com/yourfile.pdf");
     HttpURLConnection conn = (HttpURLConnection)url.openConnection();
     InputStream in = conn.getInputStream();
     ByteArrayOutputStream bos = new ByteArrayOutputStream();
     int i;
     while((i = in.read())!= -1)
          bos.write(i);
     byte [] b = bos.toByteArray();
     FileOutputStream fos = new FileOutputStream("c:\\temp\\test.pdf");
     fos.write(b);
     fos.close();
     conn.disconnect();

Similar Messages

  • Why can't I download a pdf file using internet explorer as my browser.I can download pdfs using fire

    Why can't I download a pdf file using internet explorer as my browser. I can download pdfs using firefox.

    Gilad D,
    Thanks for the support.
    I would guess the plugin is enabled since when I use Foxfire as my browser, all pdfs download and are readable. (just doesn’t happen when I use IE as my browser, I get a blank screen with a small “x” in the upper left corner)
    I will try your proposed solution.
    Charlie

  • Can't open many downloaded PDF using Preview (or Acrobat).

    Hello,
    my problem has been going on for a while, and haven't found any post on the web regarding this. I am downloading a lot of pdf files, especially from science journals. When i try to open them, i have a message that says somthing like: "this pdf is an application downloaded from internet... do you still want to open it?".
    If i click yes, then an error message pops.
    It seems like those PDF are interpreted as Application files, which is strange.
    Please let me know if you have heard about this before.
    Thanks

    From Cnet:
    Adobe's popular PDF file format--known to anyone who's ever called up a tax form on the IRS Web site--has generally been considered immune to viruses. But a new virus carried by programs embedded in PDF files raises concerns that the format itself could become susceptible.
    On Tuesday morning, Network Associates' McAfee antivirus division became aware of the first virus--known as "Peachy"--that uses PDF to spread, said Vincent Gullotto, senior director of McAfee's Avert group.
    Fortunately, those who are simply viewing a PDF, or Portable Document Format, file aren't vulnerable. The virus spreads only by way of Adobe's Acrobat software--the program used to create PDF documents--not through Acrobat Reader, the free program that is used to view the files
    Here's the page: http://news.cnet.com/New-virus-travels-in-PDF-files/2100-1001_3-271267.html

  • Downloading PDFs using Adobe 10 x

    Hi!
    I am viewing journals online for my dissertation, and trying to save them onto my hard-disk for reading at a later time / printing.
    I click on the save button, but it doesn't seem to be doing anything? I try the shortcut ctrl+shift+s and that pops up a message saying something along the lines of 'this file does not let you save any changes, it will save the original file'. So I click okay, continue. And it wont do anything.
    This makes me sad .

    Same problem here, do you have a solution already?.
    This is the error screen
    Im USing Windows Xp and sp3
    And IE8

  • Get PDF using FileDownload UI

    Hi,
    Any pointers to documentation which shows step by step creation of a WD application, for downloading PDF using the FileDownload UI.
    I have a WD application which calls a BAPI. This BAPI returns one parameter (BIN_FILE) which is of type XSTRING. This paramter contains the PDF content. I need to use this to be downloaded to a pdf.
    Can anyone guide me how to do it. I used the recent posts for this but seems to loose track somewhere.
    Regards
    Puneet

    Hi
    create a context element of type binary for example FileDownload.
    In doInit() metod:
       IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("FileDownload");    
       IWDModifiableBinaryType binaryType;
       binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
       binaryType.setFileName("test.pdf");
       binaryType.setMimeType(WDWebResourceType.pdf);
    you xstring is for example "file"
    try
         int length =(int)file.length();
         byte b[] = new byte[length];
         b = file.getBytes();
         wdContext.currentContextElement().setFileDownload(b);
         catch(Exception ex)
    Andrea

  • Cannot download pdf mountain lion

    How do you download PDFS using Acrobat Reader and Mountain Lion?

    Hi Ray,
    Just asking, are you trying to view it in a browser, oractuall download it to your Mac?
    Do you have a link to the one you're having trouble with?

  • Opening downloaded pdf files using Adobe instead of in Safari

    I prefer to use full-feature Adobe software to view downloaded pdf files instead of Safari. How do I keep Safari from opening them in the browser and instead automatically open Adobe Reader when the search engine finds a pdf file?

    I have just installed Adobe Reader 9. I am getting frequent system hangs (cannot do anything without cold re-boot) when using the product, in particular when using forms documents provided by Companies House, a UK government agency.

  • I can only print the current page of downloaded pdf's.  Not able to print "all".  I'm using a Macbook air.

    I can only print the current page of downloaded pdf's.  Not able to print "all".  I'm using a Macbook air.

    it says "the document could not be printed".  "There were no ages selected to print".
    I selected "all".  I always tried selecting pages "1-3".
    The only choice that works is current page.  Very strange.

  • How do I download PDF files using Safari.  All I get is a black screen.

    How do I download PDF files using Safari.  All I get is a black screen.

    Back up all data.
    Quit Safari. In the Finder, select Go ▹ Go to Folder... from the menu bar, or press the key combination shift-command-G. Copy the line of text below into the box that opens, and press return:
    /Library/Internet Plug-ins
    From the folder that opens, remove any items that have the letters “PDF” in the name. You may be prompted for your login password. Then launch Safari and test.
    If you still have the issue, repeat with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari again.

  • Firefox won't download pdf's using iMacros "TAG" command

    For work, I automated the downloading of documents (doc, docx, pdf files etc.) using a simple macro in iMacros. I had to use a macro because the nature of the site is - go to the main screen, click a client name link, scroll down and click a link to download the document - then go back to the main screen and repeat. The macro automated this tedious process and WAS working with about 95% success (seems that I can't tell firefox to automatically save a txt file for some reason - but that's another story). Now, all of a sudden, the macro won't download any pdf's. The macro still works fine when the document is a doc or docx or rtf file but when it hits a pdf file, it does nothing - just moves on to the next client. Since the macro works properly with the other file types (again, not txt - but everything else) it's probably not an iMacros issue. The frustrating part is - I can go into the page manually where the pdf file lives - and click on the file - and it works properly - file downloads automatically as it should.
    the macro code line is very simple:
    TAG POS=1 TYPE=A ATTR=TARGET:_blank
    I had to set all my document file types to automatically download (including adobe files) when a link is clicked - which is fine - and like I said - the macro used to work - just stopped downloading pdf's all of a sudden.
    Also I disable the adobe plugin - but that didn't work - since I have adobe files set to download automatically it shouldn't make a difference if the plugin is active or not anyway.
    Any help appreciated,
    Thanks

    Hi,
    As a safe test you can try installing [https://addons.mozilla.org/en-US/firefox/addon/imacros-for-firefox/ iMacros] in a [https://support.mozilla.org/en-US/kb/Managing-profiles new profile] and check. The [http://forum.iopus.com/viewforum.php?f=11 iMacros support] would also be helpful.
    [http://wiki.imacros.net/Main_Page KB]

  • I can't download PDF's from website that uses Adobe Reader on my Windows 8 phone?

    For work I need to be able to download PDF's from a particular website.  It utilizes the Adobe Reader but when I try to download a PDF, it doesn't do anything.  I tried to download the "Adobe Reader" from the website but it says that I do not hav the system requirements to do so.  This problem started after they did the Adobe update.  I haven't been able to download these PDS's since then.  I need to be able to do this for work....  Any suggestions?  or when will this issue be fixed?  Thank you!!!

    I have the same problem.  Or similar.  A few weeks ago, i installed Adobe reader (because i had a pdf attachment that was unreadable in Preview, so i wanted to try Adobe to see if that would work; it didn't work).  Since then, i can't open PDF files on the web. I get a black screen or sometimes a white one. and i can sometimes open them indirectly, if there is the option on the link. I thought this problem started after i deleted Adobe however. I'm not sure because i wasn't expecting this problem and am not exactly sure the sequence of when things happened, but i wanted to delete Adobe reader because i had no use for it. Unfortunately, they didn't provide an uninstaller. I put the application in the trash and whatever else was in the folder, and emptied the trash, but got a lot of messages about various files not being able to be deleted because they were in use.  I think it was since then that i can't open PDF files.  Never had a problem before getting involved with Adobe Reader. Anyway,  as far as your answer goes, i have already deleted as much of it as i can. 
    Any other suggestions?  i downloaded the Adobe installer to reinstall it if that's what it takes. i need to be able to open PDF files.
    Thanks

  • Cannot download .pdf files and word docs from KM using Web Dynpro

    Dear Portal Gurus,
    Using KM API, I am trying to download, documents from KM in my Web Dynpro Application. But .pdf files and word docs with screenshots are not getting retrieved from KM. Word docs opens with no content and Adobe opens with an error saying "Either it is a damaged file or It is not a supported file".
    I am using the following KM service to download the content.
    public byte[] retrieveResourceInBytes(String strRid){                    
    /////  after a few lines  ////
         if (this.loggedOnUser.isAuthenticated()) {
    // create a resource context with the authenticated user
         rContext = new ResourceContext(this.loggedOnUser);
    // create a RID to handle a resource
          aRid = RID.getRID(strRid);
              try {
              // get an instance of a resource factory
                     final IResourceFactory aResourceFactory = ResourceFactory.getInstance();
    // retrieve a folder/file  with context
                                                 aResource =  aResourceFactory.getResource(aRid, rContext);
         if(aResource.isCollection()) {
                                                                      aResource = (ICollection) aResource;
                                                      IPropertyMap objIPropertyMap = aResource.getProperties();               
                                                 IMutablePropertyMap objIMutablePropertyMap =objIPropertyMap.getMutable();
                                                 objHashMap = new HashMap();
         if (aResource != null) {
                                                                         IContent oldContent = aResource.getContent();
                            InputStream objInputStream=oldContent.getInputStream();
                 byte[] theBytes = new byte[objInputStream.available()];
                 objInputStream.read(theBytes);
                        return theBytes;
         } //  catches all the exceptions here///
    Could you please advise if I am doing something wrong else could you please advise me for any corrections which would help?
    Thanks a lot in advance,
    Zeena
    Edited by: Zeena Ali on Mar 25, 2009 8:13 AM

    On Apr 10, 2013, at 4:10 PM, AdityaKalania wrote: Replies in RED below:
    Re: Cannot download pdf files from web sites
    created by AdityaKalania in Adobe Reader - View the full discussion
    Hi,
    Which web browser are you using to view the PDF? Safari 5.1.8
    When you open the PDF in Adobe Reader add-in you will either see a floating toolbar
    http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-5224223-317859/430-90/floating +toolbar.JPG
    or a normal toolbar
    http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-5224223-317860/450-11/normalto olbar.JPG
    both the toolbars have save button, use the button to save the file locally. I do not see these toolbars. I do, however see this
    and it works! Thanks
    Hope this will help you.
    Thanks
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5224223#5224223
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5224223#5224223
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5224223#5224223. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Adobe Reader by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • I have installed Adobe Reader 11.0.07 for Mac OS 10.9.3. Have asked this question numerous time without results. The problems I am having are: I cannot scroll using the side slider on downloaded PDF files, nor can I fill in fillable files. Also, and this

    I have installed Adobe Reader 11.0.07 for Mac OS 10.9.3. Have asked this question numerous time without results. The problems I am having are: I cannot scroll using the side slider on downloaded PDF files, nor can I fill in fillable files. Also, and this is extremely irritating, I cannot re-initialize the same file or initialize and another PDF file after I have initialized the first file. If you cannot help please let me know if should use an earlier  version of Reader or find anther company that has the appropriate software.

    Perhaps you missed that you started a discussion at I have OS 10.9.2 and have downloaded latest version of Reader 11. I can no longer fill in form or scroll using the side bar. and you did not respond to the last post there.

  • Safari 5.1 using QT to download pdf document files

    I selected a link in my imac mail that took me to the internet site to view a PDF , but safari 5.1 is using QT to download pdf document files. I can't adjust the size or see pass page one. I don't know what happen to the reader. Can anyone help?

    I just figure out I'm in the wrong forum. Will post to safari forum.

  • 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/

Maybe you are looking for

  • Help needed in executing SQL query...

    Hi, I am very new to JDeveloper. Curently i am tryin to execute an SQL query from the BPEL process, the output of the query is to be mapped to a variable field from a target xsd file. the query is fairly simple, like SELECT emp FROM emp_table WHERE e

  • DataIntegrator XI R2 couldn't get connection to SAP R/3

    Specification: -  Data Integrator XI R2, SAP R/3 4.6C Problem      : - I'm trying to connect data integrator R2 with SAP R/3 4.6c , and it doesn't work well unfortunately.   When I tried to connect DI with R3(QAS), it works well. but, when I tried to

  • Bank chains

    Hi All, I have doubt about functionality of bank chains in sap. In the vendor master we will be maintain vendor bank accounts(created FI01) in payment transactions. To activate bank chains functionality we have activated scenario 0002. In T.code FIBP

  • Cant edit pdf on ipad anymore - can still edit on pc???

    I created an editable pdf which I was using on my iPad. At some point I stopped being able to edit it on my iPad but I can still edit it on my PC. Any help would be greatly appreciated.

  • My macbook crashed and I see a folder with a question mark blinking-

    I was getting a file from my friend on AIM and my mac froze. So I tried to restart it but all I see is a white screen with a question mark in the folder blinking, instead of an apple sign. Does this mean that my harddrive crashed and I need a new har