وصفات PostgreSQL: التحويل من HTML وعناوين URL إلى PDF و PS

لإعداد التحويل من HTML و URL إلى PDF و PS ، نحتاج إلى postgres نفسها ومولد htmldoc وامتداد pg_htmldoc . (لقد قدمت روابط إلى شوكة بلدي ، لأنني أجريت بعض التغييرات التي لم يتم حشرها بعد في المستودع الأصلي. يمكنك أيضًا استخدام الصورة الجاهزة .)

أولاً ، قم بتثبيت الامتدادات باستخدام الأمر
CREATE EXTENSION pg_htmldoc 

للتحويل من HTML و URL إلى PDF و PS ، استخدم الأوامر
 SELECT file2pdf('file.html', 'file.pdf'); --  FILE  PDF      SELECT file2ps('file.html', 'file.pdf'); --  FILE  PS      SELECT file2pdf(ARRAY['file1.html', 'file2.html'], 'file.pdf'); --   FILE  PDF      SELECT file2ps(ARRAY['file1.html', 'file2.html'], 'file.pdf'); --   FILE  PS      SELECT html2pdf(', !', 'file.pdf'); --  HTML  PDF      SELECT html2ps(', !', 'file.pdf'); --  HTML  PS      SELECT html2pdf(ARRAY[', !', ' , !'], 'file.pdf'); --   HTML  PDF      SELECT html2ps(ARRAY[', !', ' , !'], 'file.pdf'); --   HTML  PS      SELECT url2pdf('https://google.com', 'file.pdf'); --  URL  PDF      SELECT url2ps('https://google.com', 'file.pdf'); --  URL  PS      SELECT url2pdf(ARRAY['https://google.com', 'https://google.ru'], 'file.pdf'); --   URL  PDF      SELECT url2ps(ARRAY['https://google.com', 'https://google.ru'], 'file.pdf'); --   URL  PS      

أيضًا ، يمكن إرسال نتيجة التوليد إلى البريد باستخدام pg_curl
 CREATE OR REPLACE FUNCTION send(url TEXT, username TEXT, password TEXT, subject TEXT, "from" TEXT, "to" TEXT[], data TEXT, type TEXT) RETURNS TEXT LANGUAGE SQL AS $BODY$ WITH s AS (SELECT pg_curl_easy_reset(), --  (  ) pg_curl_easy_setopt('CURLOPT_URL', url), --    pg_curl_easy_setopt('CURLOPT_USERNAME', username), --   pg_curl_easy_setopt('CURLOPT_PASSWORD', password), --   pg_curl_recipient_append("to"), --   pg_curl_header_append('Subject', subject), --   pg_curl_header_append('From', "from"), --   pg_curl_header_append('To', "to"), --   pg_curl_mime_data(data, type:=type), --   pg_curl_mime_data(file2pdf('file.html'), file:='=?utf-8?B?'||encode(' FILE  PDF.pdf', 'base64')||'?=', type:='application/pdf', code:='base64'), --    FILE  PDF pg_curl_mime_data(file2ps('file.html'), file:='=?utf-8?B?'||encode(' FILE  PS.ps', 'base64')||'?=', type:='application/ps', code:='base64'), --    FILE  PS pg_curl_mime_data(file2pdf(ARRAY['file1.html', 'file2.html']), file:='=?utf-8?B?'||encode('  FILE  PDF.pdf', 'base64')||'?=', type:='application/pdf', code:='base64'), --     FILE  PDF pg_curl_mime_data(file2ps(ARRAY['file1.html', 'file2.html']), file:='=?utf-8?B?'||encode('  FILE  PS.ps', 'base64')||'?=', type:='application/ps', code:='base64'), --     FILE  PS pg_curl_mime_data(html2pdf(', !'), file:='=?utf-8?B?'||encode(' HTML  PDF.pdf', 'base64')||'?=', type:='application/pdf', code:='base64'), --    HTML  PDF pg_curl_mime_data(html2ps(', !'), file:='=?utf-8?B?'||encode(' HTML  PS.ps', 'base64')||'?=', type:='application/ps', code:='base64'), --    HTML  PS pg_curl_mime_data(html2pdf(ARRAY[', !', ' , !']), file:='=?utf-8?B?'||encode('  HTML  PDF.pdf', 'base64')||'?=', type:='application/pdf', code:='base64'), --     HTML  PDF pg_curl_mime_data(html2ps(ARRAY[', !', ' , !']), file:='=?utf-8?B?'||encode('  HTML  PS.ps', 'base64')||'?=', type:='application/ps', code:='base64'), --     HTML  PS pg_curl_mime_data(url2pdf('https://google.com'), file:='=?utf-8?B?'||encode(' URL  PDF.pdf', 'base64')||'?=', type:='application/pdf', code:='base64'), --    URL  PDF pg_curl_mime_data(url2ps('https://google.com'), file:='=?utf-8?B?'||encode(' URL  PS.ps', 'base64')||'?=', type:='application/ps', code:='base64'), --    URL  PS pg_curl_mime_data(url2pdf(ARRAY['https://google.com', 'https://google.ru']), file:='=?utf-8?B?'||encode('  URL  PDF.pdf', 'base64')||'?=', type:='application/pdf', code:='base64'), --     URL  PDF pg_curl_mime_data(url2ps(ARRAY['https://google.com', 'https://google.ru']), file:='=?utf-8?B?'||encode('  URL  PS.ps', 'base64')||'?=', type:='application/ps', code:='base64'), --     URL  PS pg_curl_header_append('Connection', 'close'), --    pg_curl_easy_perform(), --  pg_curl_easy_getinfo_char('CURLINFO_HEADERS') --   ) SELECT pg_curl_easy_getinfo_char FROM s; --   $BODY$; 

وكل هذا يمكن القيام به بشكل غير متزامن في الخلفية باستخدام برنامج الجدولة .

Source: https://habr.com/ru/post/ar458986/


All Articles