1

I'm trying to download and save a pdf file using R.

This file displays perfectly in Chrome and Edge: http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?&ftpFileName=20170317105445289.pdf&content=efmisweb&xsg=:8083/

The following R code works without error:

download.file('http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?&ftpFileName=20170317105445289.pdf&content=efmisweb&xsg=:8083/', '20170317105445289.pdf', mode="wb")

R displays

trying URL 'http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?&ftpFileName=20170317105445289.pdf&content=efmisweb&xsg=:8083/'
Content type 'text/html; charset=UTF-8' length 2707 bytes
downloaded 2707 bytes

The only hint is that the file size is much smaller than what I would expect.

Indeed, when I open it using Adobe Acrobat, it gives me an error, saying it is either not a supported file type, or the file is damaged. What causes the error?

I noticed answers to other questions say you should include mode=wb, so I did that already.

wwl
  • 2,025
  • 2
  • 30
  • 51
  • If you look at the source code for that web page, you will see that none of the data is there. What is there is some javascript that Chrome proceeds to execute giving you the content. `download.file` does not execute the javascript. – G5W Sep 19 '17 at 01:19
  • Check this: https://stackoverflow.com/a/74493075/2444948 – Dorian Grv Nov 18 '22 at 17:51

1 Answers1

1

With your link I had a 2707 bytes file. And with this link the file is 115 kilobytes.

download.file('http://www.cpppc.org:8082/efmisweb/ppp/projManage/xsg_perview.do?tokenid=undefined&fileName=20170317105445289.pdf',destfile = "Download", mode="wb")
wwl
  • 2,025
  • 2
  • 30
  • 51
MadMed
  • 36
  • 8