问题描述
我在R中有一个功能(例如下面)。我需要将其公开为API。该函数当前期望将指向PDF文件的路径传递给它。然后,它会刮除该PDF文件,并进一步处理生成的字符串。问题是,这在实时环境中是必需的,在实时环境中系统将下载PDF文件,而不必将其存储在任何地方。因此,函数/ API需要传递一个PDF对象而不是路径。我不知道如何编写函数以使其接受PDF对象?我已经读过BLOB是表示二进制数据的对象,并认为这可能是要走的路(让系统将PDF文件转换为Blob并将Blob传递给函数),但是我不确定。任何想法或链接将不胜感激。
# path to the document
path = '//path/folder/file.pdf'
# function
function_absa_bank_statement_details <- function(path = "null"){
if(path == "null"){
result <- "No document"
} else{
raw_text <- pdf_text(path)
list_lines <- strsplit(as.character(raw_text[1]),"\r\n")
product_type <- str_trim(list_lines[[1]][17])
account_number <- gsub("-","",str_trim(function_get_substring(list_lines[[1]][9],': ','end_line')))
account_holder <- str_trim(list_lines[[1]][13])
date_range <- gsub("/","-",substr(str_trim(function_get_substring(list_lines[[1]][19],'VIR TYDPERK: ','end_line')),1,23))
start_date <- function_alter_string_date_format(substr(date_range,10))
end_date <- function_alter_string_date_format(str_trim(function_get_substring(date_range,' - ','end_line')))
}
return(list(
"product_type" = product_type,"account_number" = account_number,"account_holder" = account_holder,"start_date" = start_date,"end_date" = end_date
))
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)