Postgresql functions as backend (p.4: html to pdf …)

create type type_text2pdf as
(
url text,
file bytea
);
create function sm_text2pdf
(txt text, filename text, folder text
) returns type_text2pdf
language
plpython3u
as
$$
import pdfkit
import os
t,f = args[0],args[1]
fn='/files/'+folder+'/'+f
r=pdfkit.from_string(t,fn)
in_file=open(fn,"rb")
data=in_file.read()
return fn, data
$$;
/*
select * from sm_text2pdf($$<html>yay!</html>$$,'a.pdf','docs');
*/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store