Re: [racket-users] question re downloading a PDF file
Hello, call-with-output-file and copy-port makes this task easier. Took me a while before I found out about copy-port, too. Maybe there are a few places in the documentation that should have explicit mentions of it. #lang racket (require net/url) (define/contract (download-file uri save-as-path) (-> string? path-string? any/c) (call-with-output-file save-as-path (λ (out) (define in (get-pure-port (string->url uri))) (copy-port in out)) #:exists 'replace)) (module+ main (download-file "https://racket-lang.org/img/racket-logo.svg; "racket-logo.svg")) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/9ea93faa-c38a-45e6-94cf-e5504d77cc30%40googlegroups.com.
Re: [racket-users] question re downloading a PDF file
Thanks, Dominik, that appears to do the trick! (pdfgrep is immediately happy...). Much appreciated, Tim -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/b117ca57-d32f-44ba-a1fb-1185a23e3442%40googlegroups.com.
Re: [racket-users] question re downloading a PDF file
Hi, On 24. 11. 19 13:01, Tim Hanson wrote: > hi, > > I need to fetch a number of PDF documents and wrote a bit of racket to make > it easier. The part that "downloads" is this: > > (let ([content >((compose port->string get-pure-port string->url) (url-for-doc > year doc-name))]) > (let ([out (open-output-file full-path-of-file-to-write #:mode 'text)]) > (write-string content out) > (close-output-port out) as far as I can tell the PDF is not a string - rather it is bytes. I would try port->bytes and write-bytes in your case. Cheers, Dominik -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/cb06a85a-1840-f8c0-111f-9b5af21910f7%40trustica.cz.
[racket-users] question re downloading a PDF file
hi, I need to fetch a number of PDF documents and wrote a bit of racket to make it easier. The part that "downloads" is this: (let ([content ((compose port->string get-pure-port string->url) (url-for-doc year doc-name))]) (let ([out (open-output-file full-path-of-file-to-write #:mode 'text)]) (write-string content out) (close-output-port out) According to the file utility the resulting file is a PDF document, version 1.7 But I can't open it with preview on a mac ("it may be damaged or use a format that preview doesn't recognize"); pdfgrep ("cannot open") and pdf2ps ( Error: An error occurred while reading an XREF table. The file has been damaged. This may have been caused by a problem while converting or transfering the file. ) also complain. Using mac file system info (command i) I notice differences when I examine a file downloaded this way versus one I got using save-as with a browser. The file I download with racket shows nothing in the "More info" section. The version downloaded with a browser shows about 10 fields. Is there something outside the file I need to worry about? (Once upon a time mac files had data and resource forks -- maybe they still do?) Should I be using some other method of downloading? (Incidentally I also tried #:mode 'binary.) Might I have more luck under gnu linux? -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/3d5eb9a0-c0b8-4eea-9af9-05cdd920ed54%40googlegroups.com.