Advertisement
hecrus

Form SaveItem Внешнее действие для генерации PDF

Oct 24th, 2020
2,441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 8.56 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[fm_tst-pdf_saveItem]
  2.    @username nvarchar(256),
  3.    @itemID int,
  4.    @parameters ExtendedDictionaryParameter READONLY
  5.    -- либо перечислить все поля в форме (@fieldcode и т.д.) 
  6. AS
  7. BEGIN
  8.     -- сохраняем форму (добавление/обновление некой сущности)
  9.    
  10.    
  11.     declare @pname nvarchar(max)
  12.     select @pname = Value2 from @parameters where [key]='name'
  13.  
  14.  
  15.     declare @url nvarchar(128) = '/uploads/pdf/'+convert(nvarchar(50), newid())+'.pdf'
  16.  
  17.  
  18.     -- SELECT 1 (Result, Msg, SuccessUrl, HideFormAfterSubmit, RefreshContainer)
  19.     select 1 Result, 'OK  <a href="'+@url+'">Download PDF</a>' Msg, '' SuccessUrl, 1 HideFormAfterSubmit, '' RefreshContainer
  20.  
  21.    
  22.     --select 1 Result, 'Сохранено'
  23.     declare @options  nvarchar(max) = N'
  24.    {
  25.    "options": {
  26.        "title": "Test Document"
  27.    },
  28.    "pages": [
  29.        {
  30.            "elements": [
  31.                {
  32.                    "type": "text",
  33.                    "value": "'+isnull(@pname, 'No name')+N'",
  34.                    "alignment": "center",
  35.                    "marginTop": "6cm",
  36.                    "marginBottom": "0",
  37.                    "marginLeft": "0",
  38.                    "marginRight": "0",
  39.                    "paddingTop": "0cm",
  40.                    "paddingBottom": "0",
  41.                    "paddingLeft": "0",
  42.                    "paddingRight": "0",
  43.                    "firstLineIndent": "0cm", //красная строка для абзацев
  44.                    "color": "#000000",
  45.                    "backgroundColor": "#FFFFFF",
  46.                    "font": {
  47.                        "size": 30,
  48.                        "bold": false,
  49.                        "italic": false
  50.                    }
  51.                },
  52.                {
  53.                    "type": "text",
  54.                    "value": "PDF Generator test",
  55.                    "alignment": "center",
  56.                    "font": {
  57.                        "size": 16,
  58.                        "italic": true
  59.                    }
  60.                }
  61.            ]
  62.        },
  63.        {
  64.            "elements": [
  65.                {
  66.                    "type": "image",
  67.                    "path": "/uploads/land/finance.jpg",
  68.                    "width": "10cm", //соотношение сторон сохраняется, можно указывать либо ширину, либо высоту
  69.                    "height": "10cm",
  70.                    "alignment": "left",
  71.                    //"wrapStyle": "through" //при значении through картинка становится фоном для последующих элементов. По идее здесь же настраиваниется обтекание текста вокруг картинки, пока это не работает
  72.                },
  73.                {
  74.                    "type": "text",
  75.                    "value": "Text below the image",
  76.                    "alignment": "left",
  77.                    "font": {
  78.                        "size": 14,
  79.                        "italic": true
  80.                    }
  81.                },
  82.                {
  83.                    "type": "line",
  84.                    "color": "#333399",
  85.                    "thickness": "0.1cm"
  86.                },
  87.                {
  88.                    "type": "text",
  89.                    "value": "This is a line test",
  90.                    "alignment": "right",
  91.                    "font": {
  92.                        "size": 12,
  93.                        "bold": true
  94.                    }
  95.                }
  96.            ]
  97.        },
  98.        {
  99.            "elements": [
  100.                {
  101.                    "type": "table",
  102.                    "border": {
  103.                        "width": "0.02cm",
  104.                        "color": "#000000"
  105.                    },
  106.                    "columnWidths": ["4cm", "4cm", "2cm"],
  107.                    "headers": ["Column ", "Column 2", "Column 3"],
  108.                    "values": [
  109.                        ["value 1_1", "value 1_2", "value 1_3"],
  110.                        ["value 2_1", "value 2_2", "value 2_3"],
  111.                        ["value 3_1", "value 3_2", "value 3_3"],
  112.                        ["result", "", ""]
  113.                    ],
  114.                    "styleOptions": [
  115.                        {
  116.                            "position": [4, 0], //координаты ячейки, которую правим. [X, Y] - где X - строка, Y - столбец, начиная с нуля, строка 0 - шапка
  117.                            "alignment": "right",
  118.                            "font": { "bold": true, "italic": false, "family": "Arial", "size": 12 },
  119.                            "mergeRight": 2, //объединить n ячеек справа с этой
  120.                            "mergeDown": 0 //объединить n ячеек ниже с этой
  121.                        }
  122.                    ]
  123.                },
  124.                {
  125.                    "type": "text",
  126.                    "value": "This is a table",
  127.                    "color": "#ff3333",
  128.                    "backgroundColor": "#ddddff",
  129.                    "paddingBottom": "0.2cm",
  130.                    "marginTop": "0.1cm"
  131.                },
  132.                {
  133.                    "type": "text",
  134.                    "value": "Some lists:",
  135.                    "marginTop": "1cm"
  136.                },
  137.                {
  138.                    "type": "list",
  139.                    "listStyle": "ul",
  140.                    "items": [
  141.                        "item1",
  142.                        "item2",
  143.                        "item3"
  144.                    ]
  145.                },
  146.                {
  147.                    "type": "list",
  148.                    "listStyle": "ol",
  149.                    "items": [
  150.                        "item1",
  151.                        "item2",
  152.                        "item3"
  153.                    ]
  154.                },
  155.                {
  156.                    "type": "list",
  157.                    "listStyle": "ol2",
  158.                    "items": [
  159.                        "item1",
  160.                        "item2",
  161.                        "item3"
  162.                    ]
  163.                },
  164.                {
  165.                    "type": "list",
  166.                    "listStyle": "ol3",
  167.                    "items": [
  168.                        "item1",
  169.                        "item2",
  170.                        "item3"
  171.                    ]
  172.                },
  173.                {
  174.                    "type": "text",
  175.                    "value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
  176.                    "marginBottom": "0.5cm",
  177.                    "firstLineIndent": "1.5cm"
  178.                },
  179.                {
  180.                    "type": "text",
  181.                    "value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
  182.                    "marginBottom": "0.5cm",
  183.                    "firstLineIndent": "1.5cm"
  184.                },
  185.                {
  186.                    "type": "text",
  187.                    "value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
  188.                    "marginBottom": "0.5cm",
  189.                    "firstLineIndent": "1.5cm"
  190.                }
  191.            ]
  192.        }
  193.    ]
  194. }
  195. '
  196.    
  197.     select 'generatepdf' type,
  198.         @url url,
  199.         @options options
  200.    
  201.    
  202.  
  203.  
  204.  
  205. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement