Josh
Josh

Reputation: 33

Convert HTML to PDF with httr

I have an HTML file saved locally that I would like to convert to PDF using httr and pdfcrowd.com API. I am using the following code:

library(httr)

r <- POST(url="http://pdfcrowd.com/api/pdf/convert/html/", config=list(authenticate(user=myusername, password=myAPItoken)), 
              encode="multipart", body=upload_file(path=< my local path >))

content(r)

When I run this I get the following output saying that I am missing the src field. My understanding is the src field is the path to the file. Any help is appreciated:

"No data to convert. Missing src field."

Upvotes: 1

Views: 900

Answers (1)

hadley
hadley

Reputation: 103948

Based on the documentation and error message, I suspect you want:

library(httr)

r <- POST(
  "http://pdfcrowd.com/api/pdf/convert/html/", 
  authenticate(myusername, myAPItoken), 
  body = list(src = upload_file("my local path"))
)

content(r)

Upvotes: 1

Related Questions