Home > Net >  Base64-encoded binary string, txt to PDF in R
Base64-encoded binary string, txt to PDF in R

Time:09-08

I am trying to download PDF's via an API where I recieve the data as Base64-encoded binary in JSON format. Is there a way to convert that to a pdf using R?

My approach is the following but that generated "PDF" can't be read properly by a PDF reader. By looking at it in Notepad it also looks like it is missing something like additional metadata?, as it should create the following PDF

file <- fromJSON("data.txt")
decoded <- base64_dec(file$data)
save(decoded, "file.pdf")

File: data.txt

CodePudding user response:

You should use writeBin to write out the binary raw data to a file

data <- jsonlite::fromJSON("data.txt")
raw <- openssl::base64_decode(data$data)
writeBin(raw, "output.pdf")
  • Related